final int nRows = getRowDimension(); final int nCols = getColumnDimension(); if (m.getColumnDimension() != nCols || m.getRowDimension() != nRows) { return false; final BigDecimal[] dataRow = data[row]; for (int col = 0; col < nCols; col++) { if (!dataRow[col].equals(m.getEntry(row, col))) { return false;
/** * Returns the result premultiplying this by <code>m</code>. * @param m matrix to premultiply by * @return m * this * @throws IllegalArgumentException * if rowDimension(this) != columnDimension(m) */ public BigMatrix preMultiply(BigMatrix m) throws IllegalArgumentException { return m.multiply(this); }
final int nCols = m.getColumnDimension(); final int nSum = this.getColumnDimension(); final BigDecimal[][] outData = new BigDecimal[nRows][nCols]; BigDecimal sum = ZERO; for (int i = 0; i < nSum; i++) { sum = sum.add(dataRow[i].multiply(m.getEntry(i, col)));
/** * Compute the sum of this and <code>m</code>. * * @param m matrix to be added * @return this + m * @throws IllegalArgumentException if m is not the same size as this */ public BigMatrix add(BigMatrix m) throws IllegalArgumentException { try { return add((BigMatrixImpl) m); } catch (ClassCastException cce) { // safety check MatrixUtils.checkAdditionCompatible(this, m); final int rowCount = getRowDimension(); final int columnCount = getColumnDimension(); final BigDecimal[][] outData = new BigDecimal[rowCount][columnCount]; for (int row = 0; row < rowCount; row++) { final BigDecimal[] dataRow = data[row]; final BigDecimal[] outDataRow = outData[row]; for (int col = 0; col < columnCount; col++) { outDataRow[col] = dataRow[col].add(m.getEntry(row, col)); } } return new BigMatrixImpl(outData, false); } }
final int nCols = m.getColumnDimension(); final int nSum = this.getColumnDimension(); final BigDecimal[][] outData = new BigDecimal[nRows][nCols]; BigDecimal sum = ZERO; for (int i = 0; i < nSum; i++) { sum = sum.add(dataRow[i].multiply(m.getEntry(i, col)));
/** * Compute the sum of this and <code>m</code>. * * @param m matrix to be added * @return this + m * @throws IllegalArgumentException if m is not the same size as this */ public BigMatrix add(BigMatrix m) throws IllegalArgumentException { try { return add((BigMatrixImpl) m); } catch (ClassCastException cce) { // safety check MatrixUtils.checkAdditionCompatible(this, m); final int rowCount = getRowDimension(); final int columnCount = getColumnDimension(); final BigDecimal[][] outData = new BigDecimal[rowCount][columnCount]; for (int row = 0; row < rowCount; row++) { final BigDecimal[] dataRow = data[row]; final BigDecimal[] outDataRow = outData[row]; for (int col = 0; col < columnCount; col++) { outDataRow[col] = dataRow[col].add(m.getEntry(row, col)); } } return new BigMatrixImpl(outData, false); } }
int nRows = getRowDimension(); int nCols = getColumnDimension(); if (m.getColumnDimension() != nCols || m.getRowDimension() != nRows) { return false; if (!data[row][col].equals(m.getEntry(row, col))) { return false;
/** * Returns the result premultiplying this by <code>m</code>. * @param m matrix to premultiply by * @return m * this * @throws IllegalArgumentException * if rowDimension(this) != columnDimension(m) */ public BigMatrix preMultiply(BigMatrix m) throws IllegalArgumentException { return m.multiply(this); }
final int nRows = getRowDimension(); final int nCols = getColumnDimension(); if (m.getColumnDimension() != nCols || m.getRowDimension() != nRows) { return false; final BigDecimal[] dataRow = data[row]; for (int col = 0; col < nCols; col++) { if (!dataRow[col].equals(m.getEntry(row, col))) { return false;
/** * Returns the result premultiplying this by <code>m</code>. * @param m matrix to premultiply by * @return m * this * @throws IllegalArgumentException * if rowDimension(this) != columnDimension(m) */ public BigMatrix preMultiply(BigMatrix m) throws IllegalArgumentException { return m.multiply(this); }
/** * Returns the result of postmultiplying this by <code>m</code>. * @param m matrix to postmultiply by * @return this*m * @throws IllegalArgumentException * if columnDimension(this) != rowDimension(m) */ public BigMatrix multiply(BigMatrix m) throws IllegalArgumentException { if (this.getColumnDimension() != m.getRowDimension()) { throw new IllegalArgumentException("Matrices are not multiplication compatible."); } int nRows = this.getRowDimension(); int nCols = m.getColumnDimension(); int nSum = this.getColumnDimension(); BigDecimal[][] outData = new BigDecimal[nRows][nCols]; BigDecimal sum = ZERO; for (int row = 0; row < nRows; row++) { for (int col = 0; col < nCols; col++) { sum = ZERO; for (int i = 0; i < nSum; i++) { sum = sum.add(data[row][i].multiply(m.getEntry(i, col))); } outData[row][col] = sum; } } return new BigMatrixImpl(outData); }
/** * Compute the sum of this and <code>m</code>. * * @param m matrix to be added * @return this + m * @exception IllegalArgumentException if m is not the same size as this */ public BigMatrix add(BigMatrix m) throws IllegalArgumentException { if (this.getColumnDimension() != m.getColumnDimension() || this.getRowDimension() != m.getRowDimension()) { throw new IllegalArgumentException("matrix dimension mismatch"); } int rowCount = this.getRowDimension(); int columnCount = this.getColumnDimension(); BigDecimal[][] outData = new BigDecimal[rowCount][columnCount]; for (int row = 0; row < rowCount; row++) { for (int col = 0; col < columnCount; col++) { outData[row][col] = data[row][col].add(m.getEntry(row, col)); } } return new BigMatrixImpl(outData); }
/** * Compute this minus <code>m</code>. * * @param m matrix to be subtracted * @return this + m * @exception IllegalArgumentException if m is not the same size as *this */ public BigMatrix subtract(BigMatrix m) throws IllegalArgumentException { if (this.getColumnDimension() != m.getColumnDimension() || this.getRowDimension() != m.getRowDimension()) { throw new IllegalArgumentException("matrix dimension mismatch"); } int rowCount = this.getRowDimension(); int columnCount = this.getColumnDimension(); BigDecimal[][] outData = new BigDecimal[rowCount][columnCount]; for (int row = 0; row < rowCount; row++) { for (int col = 0; col < columnCount; col++) { outData[row][col] = data[row][col].subtract(m.getEntry(row, col)); } } return new BigMatrixImpl(outData); }
if (b.getRowDimension() != this.getRowDimension()) { throw new IllegalArgumentException("Incorrect row dimension"); int nColB = b.getColumnDimension(); int nRowB = b.getRowDimension(); for (int row = 0; row < nRowB; row++) { for (int col = 0; col < nColB; col++) { bp[row][col] = b.getEntry(permutation[row], col);
if (b.getRowDimension() != getRowDimension()) { throw MathRuntimeException.createIllegalArgumentException( LocalizedFormats.DIMENSIONS_MISMATCH_2x2, b.getRowDimension(), b.getColumnDimension(), getRowDimension(), "n"); final int nColB = b.getColumnDimension(); final int nRowB = b.getRowDimension(); final BigDecimal[] bpRow = bp[row]; for (int col = 0; col < nColB; col++) { bpRow[col] = b.getEntry(permutation[row], col);
if (b.getRowDimension() != getRowDimension()) { throw MathRuntimeException.createIllegalArgumentException( "dimensions mismatch: got {0}x{1} but expected {2}x{3}", b.getRowDimension(), b.getColumnDimension(), getRowDimension(), "n"); final int nColB = b.getColumnDimension(); final int nRowB = b.getRowDimension(); final BigDecimal[] bpRow = bp[row]; for (int col = 0; col < nColB; col++) { bpRow[col] = b.getEntry(permutation[row], col);