List of usage examples for org.apache.commons.math.linear MatrixUtils checkSubtractionCompatible
public static void checkSubtractionCompatible(final AnyMatrix left, final AnyMatrix right) throws IllegalArgumentException
From source file:org.mitre.math.linear.BufferRealMatrix.java
/** {@inheritDoc} */ public BufferRealMatrix subtract(final BufferRealMatrix b) throws IllegalArgumentException { // if (b == this) { // return this.subtractSelf(); // }/*from w w w . j a v a 2 s . c o m*/ // safety check MatrixUtils.checkSubtractionCompatible(this, b); try { final BufferRealMatrix c = new BufferRealMatrix(rows, columns, null); // perform addition block-wise, to ensure good cache behavior for (int blockIndex = 0; blockIndex < this.blockRows * this.blockColumns; ++blockIndex) { // all the same size, so should all be the same blockOffsets and layout final long blockOffset = this.getBlockOffset(blockIndex); DoubleBuffer adb = this.dataFileChannel .map(FileChannel.MapMode.READ_WRITE, blockOffset, BLOCK_BYTE_SIZE).asDoubleBuffer(); adb.clear(); DoubleBuffer bdb = b.dataFileChannel .map(FileChannel.MapMode.READ_WRITE, blockOffset, BLOCK_BYTE_SIZE).asDoubleBuffer(); bdb.clear(); DoubleBuffer cdb = c.dataFileChannel .map(FileChannel.MapMode.READ_WRITE, blockOffset, BLOCK_BYTE_SIZE).asDoubleBuffer(); cdb.clear(); for (int k = 0; k < BLOCK_BYTE_SIZE / DOUBLE_BYTE_SIZE; k++) { try { cdb.put(adb.get() - bdb.get()); } catch (BufferUnderflowException e) { LOG.fatal(String.format("BufferUnderflowException while adding elements at %d in block %d", k, blockIndex)); throw e; } } } return c; } catch (IOException ioe) { throw new RuntimeException(ioe); } }