@Override public void assertDimensionalityEquals( final int otherDimensionality) { if (this.getDimensionality() != otherDimensionality) { throw new DimensionalityMismatchException( this.getDimensionality(), otherDimensionality); } }
@Override public void assertDimensionalityEquals( final int otherDimensionality) { if (this.getDimensionality() != otherDimensionality) { throw new DimensionalityMismatchException( this.getDimensionality(), otherDimensionality); } }
@Override public void assertDimensionalityEquals( final int otherDimensionality) { if (this.getDimensionality() != otherDimensionality) { throw new DimensionalityMismatchException( this.getDimensionality(), otherDimensionality); } }
@Override public void assertSameDimensions( Matrix other ) { if (!this.checkSameDimensions(other)) { throw new DimensionalityMismatchException( "Matrices must have same dimensions: " + "(" + this.getNumRows() + "x" + this.getNumColumns() + ") !=" + "(" + other.getNumRows() + "x" + other.getNumColumns() + ")" ); } }
@Override public void assertSameDimensions( Matrix other ) { if (!this.checkSameDimensions(other)) { throw new DimensionalityMismatchException( "Matrices must have same dimensions: " + "(" + this.getNumRows() + "x" + this.getNumColumns() + ") !=" + "(" + other.getNumRows() + "x" + other.getNumColumns() + ")" ); } }
@Override public void assertSameDimensions( Matrix other ) { if (!this.checkSameDimensions(other)) { throw new DimensionalityMismatchException( "Matrices must have same dimensions: " + "(" + this.getNumRows() + "x" + this.getNumColumns() + ") !=" + "(" + other.getNumRows() + "x" + other.getNumColumns() + ")" ); } }
@Override public double trace() { if (this.isSquare() == false) { throw new DimensionalityMismatchException( "Matrix must be square for trace()" ); } // find the min dimension... should be same, but this is more robust int M = this.getNumRows(); int N = this.getNumColumns(); int D = (M < N) ? M : N; double diagonal_sum = 0.0; for (int i = 0; i < D; i++) { diagonal_sum += this.getElement( i, i ); } return diagonal_sum; }
@Override public double trace() { if (this.isSquare() == false) { throw new DimensionalityMismatchException( "Matrix must be square for trace()" ); } // find the min dimension... should be same, but this is more robust int M = this.getNumRows(); int N = this.getNumColumns(); int D = (M < N) ? M : N; double diagonal_sum = 0.0; for (int i = 0; i < D; i++) { diagonal_sum += this.getElement( i, i ); } return diagonal_sum; }
@Override public double trace() { if (this.isSquare() == false) { throw new DimensionalityMismatchException( "Matrix must be square for trace()" ); } // find the min dimension... should be same, but this is more robust int M = this.getNumRows(); int N = this.getNumColumns(); int D = (M < N) ? M : N; double diagonal_sum = 0.0; for (int i = 0; i < D; i++) { diagonal_sum += this.getElement( i, i ); } return diagonal_sum; }
@Override public void assertMultiplicationDimensions( final Matrix postMultiplicationMatrix) { if (!this.checkMultiplicationDimensions(postMultiplicationMatrix)) { throw new DimensionalityMismatchException( "Matrices must have same internal dimensions: " + + this.getNumRows() + "x" + this.getNumColumns() + " != " + + postMultiplicationMatrix.getNumRows() + "x" + postMultiplicationMatrix.getNumColumns()); } }
@Override public void assertMultiplicationDimensions( final Matrix postMultiplicationMatrix) { if (!this.checkMultiplicationDimensions(postMultiplicationMatrix)) { throw new DimensionalityMismatchException( "Matrices must have same internal dimensions: " + + this.getNumRows() + "x" + this.getNumColumns() + " != " + + postMultiplicationMatrix.getNumRows() + "x" + postMultiplicationMatrix.getNumColumns()); } }
@Override public void assertMultiplicationDimensions( final Matrix postMultiplicationMatrix) { if (!this.checkMultiplicationDimensions(postMultiplicationMatrix)) { throw new DimensionalityMismatchException( "Matrices must have same internal dimensions: " + + this.getNumRows() + "x" + this.getNumColumns() + " != " + + postMultiplicationMatrix.getNumRows() + "x" + postMultiplicationMatrix.getNumColumns()); } }
@Override public void setRow( int rowIndex, Vector rowVector ) { int N = this.getNumColumns(); if (N != rowVector.getDimensionality()) { throw new DimensionalityMismatchException( N, rowVector.getDimensionality() ); } for (int j = 0; j < N; j++) { this.setElement( rowIndex, j, rowVector.getElement( j ) ); } }
@Override public void setColumn( int columnIndex, Vector columnVector ) { int M = this.getNumRows(); if (M != columnVector.getDimensionality()) { throw new DimensionalityMismatchException( M, columnVector.getDimensionality() ); } for (int i = 0; i < M; i++) { this.setElement( i, columnIndex, columnVector.getElement( i ) ); } }
@Override public void setColumn( int columnIndex, Vector columnVector ) { int M = this.getNumRows(); if (M != columnVector.getDimensionality()) { throw new DimensionalityMismatchException( M, columnVector.getDimensionality() ); } for (int i = 0; i < M; i++) { this.setElement( i, columnIndex, columnVector.getElement( i ) ); } }
@Override public void setColumn( int columnIndex, Vector columnVector ) { int M = this.getNumRows(); if (M != columnVector.getDimensionality()) { throw new DimensionalityMismatchException( M, columnVector.getDimensionality() ); } for (int i = 0; i < M; i++) { this.setElement( i, columnIndex, columnVector.getElement( i ) ); } }
@Override public void setRow( int rowIndex, Vector rowVector ) { int N = this.getNumColumns(); if (N != rowVector.getDimensionality()) { throw new DimensionalityMismatchException( N, rowVector.getDimensionality() ); } for (int j = 0; j < N; j++) { this.setElement( rowIndex, j, rowVector.getElement( j ) ); } }
@Override public void setRow( int rowIndex, Vector rowVector ) { int N = this.getNumColumns(); if (N != rowVector.getDimensionality()) { throw new DimensionalityMismatchException( N, rowVector.getDimensionality() ); } for (int j = 0; j < N; j++) { this.setElement( rowIndex, j, rowVector.getElement( j ) ); } }
/** * @param A * @param B * @return A - B */ public static Matrix fastsparseminusEquals(SparseColumnMatrix A, SparseColumnMatrix B) { if (A.getNumColumns() != B.getNumColumns() || A.getNumRows() != B.getNumRows()) { throw new DimensionalityMismatchException(); } final SparseColumnMatrix ret = A; final FlexCompColMatrix retint = ret.getInternalMatrix(); final FlexCompColMatrix Bint = B.getInternalMatrix(); for (int i = 0; i < A.getNumColumns(); i++) { final no.uib.cipr.matrix.sparse.SparseVector aCol = retint.getColumn(i); final no.uib.cipr.matrix.sparse.SparseVector bCol = Bint.getColumn(i); aCol.add(-1, bCol); } return ret; }
/** * @param A * @param B * @return A - B */ public static Matrix fastsparseminusEquals(SparseRowMatrix A, SparseRowMatrix B) { if (A.getNumColumns() != B.getNumColumns() || A.getNumRows() != B.getNumRows()) { throw new DimensionalityMismatchException(); } final SparseRowMatrix ret = A; final FlexCompRowMatrix retInt = ret.getInternalMatrix(); final FlexCompRowMatrix bint = B.getInternalMatrix(); for (int i = 0; i < A.getNumRows(); i++) { final no.uib.cipr.matrix.sparse.SparseVector aCol = retInt.getRow(i); final no.uib.cipr.matrix.sparse.SparseVector bCol = bint.getRow(i); aCol.add(-1, bCol); } return ret; }