@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 ) ); } }
/** * Internal function that writes the row onto the destinationVector. * Gets the specified row from the zero-based index and returns a vector * that corresponds to that column * * @param rowIndex zero-based index into the matrix * @param destinationVector * Vector with elements equal to the number of columns in this */ protected void getRowInto( int rowIndex, Vector destinationVector ) { int N = this.getNumColumns(); if (N != destinationVector.getDimensionality()) { throw new DimensionalityMismatchException( N, destinationVector.getDimensionality() ); } for (int j = 0; j < N; j++) { destinationVector.setElement( j, this.getElement( rowIndex, j ) ); } }
/** * Internal function that writes the row onto the destinationVector. * Gets the specified row from the zero-based index and returns a vector * that corresponds to that column * * @param rowIndex zero-based index into the matrix * @param destinationVector * Vector with elements equal to the number of columns in this */ protected void getRowInto( int rowIndex, Vector destinationVector ) { int N = this.getNumColumns(); if (N != destinationVector.getDimensionality()) { throw new DimensionalityMismatchException( N, destinationVector.getDimensionality() ); } for (int j = 0; j < N; j++) { destinationVector.setElement( j, this.getElement( rowIndex, j ) ); } }