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

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

Introduction

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

Prototype

void start(int rows, int columns, int startRow, int endRow, int startColumn, int endColumn);

Source Link

Document

Start visiting a matrix.

Usage

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

/** {@inheritDoc} */
@Override/*  w  w  w  .  jav a  2 s  .  c o m*/
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();
}