Example usage for org.apache.commons.math.linear RealMatrixPreservingVisitor end

List of usage examples for org.apache.commons.math.linear RealMatrixPreservingVisitor end

Introduction

In this page you can find the example usage for org.apache.commons.math.linear RealMatrixPreservingVisitor end.

Prototype

double end();

Source Link

Document

End visiting a matrix.

Usage

From source file:org.mitre.math.linear.BufferRealMatrix.java

/** {@inheritDoc} */
@Override/*from ww  w. j a  v a  2s . com*/
public double walkInOptimizedOrder(final RealMatrixPreservingVisitor visitor) throws MatrixVisitorException {
    visitor.start(rows, columns, 0, rows - 1, 0, columns - 1);
    for (int iBlock = 0, blockIndex = 0; iBlock < blockRows; ++iBlock) {
        final int pStart = iBlock * BLOCK_SIZE;
        final int pEnd = Math.min(pStart + BLOCK_SIZE, rows);

        for (int jBlock = 0; jBlock < blockColumns; ++jBlock, ++blockIndex) {
            try {
                final int qStart = jBlock * BLOCK_SIZE;
                final int qEnd = Math.min(qStart + BLOCK_SIZE, columns);

                final long blockOffset = this.getBlockOffset(blockIndex);
                final DoubleBuffer block = this.dataFileChannel
                        .map(FileChannel.MapMode.READ_WRITE, blockOffset, BLOCK_BYTE_SIZE).asDoubleBuffer();
                block.clear();

                LOG.debug(String.format("BlockIndex=%d pStart=%d pEnd=%d qStart=%d qEnd=%d", blockIndex, pStart,
                        pEnd, qStart, qEnd));
                for (int p = pStart, k = 0; p < pEnd; ++p) {
                    // jump to end of row incase we are not there
                    k = (p - pStart) * BLOCK_SIZE;
                    for (int q = qStart; q < qEnd; ++q, ++k) {
                        visitor.visit(p, q, block.get(k));
                    }
                }

                this.dataFileChannel.force(false);
            } catch (IOException ioe) {
                throw new MathRuntimeException(
                        "IO Exception while visiting blockIndex {0} (iBlock={1}, jBlock={2})", blockIndex,
                        iBlock, jBlock);
            }
        }
    }
    return visitor.end();
}