/** * Subtract {@code m} from this matrix. * * @param m Matrix to be subtracted. * @return {@code this} - m. * @throws MatrixDimensionMismatchException if {@code m} is not the * same size as this matrix. */ public BlockRealMatrix subtract(final BlockRealMatrix m) throws MatrixDimensionMismatchException { // safety check MatrixUtils.checkSubtractionCompatible(this, m); final BlockRealMatrix out = new BlockRealMatrix(rows, columns); // perform subtraction block-wise, to ensure good cache behavior for (int blockIndex = 0; blockIndex < out.blocks.length; ++blockIndex) { final double[] outBlock = out.blocks[blockIndex]; final double[] tBlock = blocks[blockIndex]; final double[] mBlock = m.blocks[blockIndex]; for (int k = 0; k < outBlock.length; ++k) { outBlock[k] = tBlock[k] - mBlock[k]; } } return out; }
/** * Returns {@code this} minus {@code m}. * * @param m Matrix to be subtracted. * @return {@code this - m} * @throws MatrixDimensionMismatchException if {@code m} is not the same * size as {@code this}. */ public DiagonalMatrix subtract(final DiagonalMatrix m) throws MatrixDimensionMismatchException { MatrixUtils.checkSubtractionCompatible(this, m); final int dim = getRowDimension(); final double[] outData = new double[dim]; for (int i = 0; i < dim; i++) { outData[i] = data[i] - m.data[i]; } return new DiagonalMatrix(outData, false); }
/** * Returns {@code this} minus {@code m}. * * @param m Matrix to be subtracted. * @return {@code this - m} * @throws MatrixDimensionMismatchException if {@code m} is not the same * size as {@code this}. */ public Array2DRowRealMatrix subtract(final Array2DRowRealMatrix m) throws MatrixDimensionMismatchException { MatrixUtils.checkSubtractionCompatible(this, m); final int rowCount = getRowDimension(); final int columnCount = getColumnDimension(); final double[][] outData = new double[rowCount][columnCount]; for (int row = 0; row < rowCount; row++) { final double[] dataRow = data[row]; final double[] mRow = m.data[row]; final double[] outDataRow = outData[row]; for (int col = 0; col < columnCount; col++) { outDataRow[col] = dataRow[col] - mRow[col]; } } return new Array2DRowRealMatrix(outData, false); }
/** {@inheritDoc} */ public RealMatrix subtract(final RealMatrix m) throws MatrixDimensionMismatchException { MatrixUtils.checkSubtractionCompatible(this, m); final int rowCount = getRowDimension(); final int columnCount = getColumnDimension(); final RealMatrix out = createMatrix(rowCount, columnCount); for (int row = 0; row < rowCount; ++row) { for (int col = 0; col < columnCount; ++col) { out.setEntry(row, col, getEntry(row, col) - m.getEntry(row, col)); } } return out; }
} catch (ClassCastException cce) { MatrixUtils.checkSubtractionCompatible(this, m);
/** * Subtract {@code m} from this matrix. * * @param m Matrix to be subtracted. * @return {@code this} - m. * @throws MatrixDimensionMismatchException if {@code m} is not the * same size as this matrix. */ public BlockRealMatrix subtract(final BlockRealMatrix m) throws MatrixDimensionMismatchException { // safety check MatrixUtils.checkSubtractionCompatible(this, m); final BlockRealMatrix out = new BlockRealMatrix(rows, columns); // perform subtraction block-wise, to ensure good cache behavior for (int blockIndex = 0; blockIndex < out.blocks.length; ++blockIndex) { final double[] outBlock = out.blocks[blockIndex]; final double[] tBlock = blocks[blockIndex]; final double[] mBlock = m.blocks[blockIndex]; for (int k = 0; k < outBlock.length; ++k) { outBlock[k] = tBlock[k] - mBlock[k]; } } return out; }
/** * Subtract {@code m} from this matrix. * * @param m Matrix to be subtracted. * @return {@code this} - m. * @throws MatrixDimensionMismatchException if {@code m} is not the * same size as this matrix. */ public BlockRealMatrix subtract(final BlockRealMatrix m) throws MatrixDimensionMismatchException { // safety check MatrixUtils.checkSubtractionCompatible(this, m); final BlockRealMatrix out = new BlockRealMatrix(rows, columns); // perform subtraction block-wise, to ensure good cache behavior for (int blockIndex = 0; blockIndex < out.blocks.length; ++blockIndex) { final double[] outBlock = out.blocks[blockIndex]; final double[] tBlock = blocks[blockIndex]; final double[] mBlock = m.blocks[blockIndex]; for (int k = 0; k < outBlock.length; ++k) { outBlock[k] = tBlock[k] - mBlock[k]; } } return out; }
/** * Returns {@code this} minus {@code m}. * * @param m Matrix to be subtracted. * @return {@code this - m} * @throws MatrixDimensionMismatchException if {@code m} is not the same * size as {@code this}. */ public DiagonalMatrix subtract(final DiagonalMatrix m) throws MatrixDimensionMismatchException { MatrixUtils.checkSubtractionCompatible(this, m); final int dim = getRowDimension(); final double[] outData = new double[dim]; for (int i = 0; i < dim; i++) { outData[i] = data[i] - m.data[i]; } return new DiagonalMatrix(outData, false); }
/** * Returns {@code this} minus {@code m}. * * @param m Matrix to be subtracted. * @return {@code this - m} * @throws MatrixDimensionMismatchException if {@code m} is not the same * size as {@code this}. */ public DiagonalMatrix subtract(final DiagonalMatrix m) throws MatrixDimensionMismatchException { MatrixUtils.checkSubtractionCompatible(this, m); final int dim = getRowDimension(); final double[] outData = new double[dim]; for (int i = 0; i < dim; i++) { outData[i] = data[i] - m.data[i]; } return new DiagonalMatrix(outData, false); }
} else { MatrixUtils.checkSubtractionCompatible(this, m);
/** * Returns {@code this} minus {@code m}. * * @param m Matrix to be subtracted. * @return {@code this - m} * @throws MatrixDimensionMismatchException if {@code m} is not the same * size as {@code this}. */ public Array2DRowRealMatrix subtract(final Array2DRowRealMatrix m) throws MatrixDimensionMismatchException { MatrixUtils.checkSubtractionCompatible(this, m); final int rowCount = getRowDimension(); final int columnCount = getColumnDimension(); final double[][] outData = new double[rowCount][columnCount]; for (int row = 0; row < rowCount; row++) { final double[] dataRow = data[row]; final double[] mRow = m.data[row]; final double[] outDataRow = outData[row]; for (int col = 0; col < columnCount; col++) { outDataRow[col] = dataRow[col] - mRow[col]; } } return new Array2DRowRealMatrix(outData, false); }
/** * Returns {@code this} minus {@code m}. * * @param m Matrix to be subtracted. * @return {@code this - m} * @throws MatrixDimensionMismatchException if {@code m} is not the same * size as {@code this}. */ public Array2DRowRealMatrix subtract(final Array2DRowRealMatrix m) throws MatrixDimensionMismatchException { MatrixUtils.checkSubtractionCompatible(this, m); final int rowCount = getRowDimension(); final int columnCount = getColumnDimension(); final double[][] outData = new double[rowCount][columnCount]; for (int row = 0; row < rowCount; row++) { final double[] dataRow = data[row]; final double[] mRow = m.data[row]; final double[] outDataRow = outData[row]; for (int col = 0; col < columnCount; col++) { outDataRow[col] = dataRow[col] - mRow[col]; } } return new Array2DRowRealMatrix(outData, false); }
/** {@inheritDoc} */ public RealMatrix subtract(final RealMatrix m) throws MatrixDimensionMismatchException { MatrixUtils.checkSubtractionCompatible(this, m); final int rowCount = getRowDimension(); final int columnCount = getColumnDimension(); final RealMatrix out = createMatrix(rowCount, columnCount); for (int row = 0; row < rowCount; ++row) { for (int col = 0; col < columnCount; ++col) { out.setEntry(row, col, getEntry(row, col) - m.getEntry(row, col)); } } return out; }
/** {@inheritDoc} */ public RealMatrix subtract(final RealMatrix m) throws MatrixDimensionMismatchException { MatrixUtils.checkSubtractionCompatible(this, m); final int rowCount = getRowDimension(); final int columnCount = getColumnDimension(); final RealMatrix out = createMatrix(rowCount, columnCount); for (int row = 0; row < rowCount; ++row) { for (int col = 0; col < columnCount; ++col) { out.setEntry(row, col, getEntry(row, col) - m.getEntry(row, col)); } } return out; }
} catch (ClassCastException cce) { MatrixUtils.checkSubtractionCompatible(this, m);