mirror of
https://github.com/apache/commons-math.git
synced 2025-02-06 01:59:13 +00:00
added column walking order
renamed walkInInternalOrder into walkInOptimizedOrder git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@730787 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
75f8b0afb1
commit
89c80e938e
@ -32,7 +32,7 @@ import org.apache.commons.math.util.MathUtils;
|
||||
*/
|
||||
public abstract class AbstractRealMatrix implements RealMatrix, Serializable {
|
||||
|
||||
/** Serializable version identifier */
|
||||
/** Serializable version identifier. */
|
||||
private static final long serialVersionUID = -3665653040524315561L;
|
||||
|
||||
/** Cached LU solver.
|
||||
@ -195,31 +195,74 @@ public abstract class AbstractRealMatrix implements RealMatrix, Serializable {
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public double getNorm() {
|
||||
final int rowCount = getRowDimension();
|
||||
final int columnCount = getColumnDimension();
|
||||
double maxColSum = 0;
|
||||
for (int col = 0; col < columnCount; ++col) {
|
||||
double sum = 0;
|
||||
for (int row = 0; row < rowCount; ++row) {
|
||||
sum += Math.abs(getEntry(row, col));
|
||||
return walkInColumnOrder(new RealMatrixPreservingVisitor() {
|
||||
|
||||
/** Serializable version identifier */
|
||||
private static final long serialVersionUID = -2452270856202894168L;
|
||||
|
||||
/** Last row index. */
|
||||
private double endRow;
|
||||
|
||||
/** Sum of absolute values on one column. */
|
||||
private double columnSum;
|
||||
|
||||
/** Maximal sum across all columns. */
|
||||
private double maxColSum;
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void start(final int rows, final int columns,
|
||||
final int startRow, final int endRow,
|
||||
final int startColumn, final int endColumn) {
|
||||
this.endRow = endRow;
|
||||
columnSum = 0;
|
||||
maxColSum = 0;
|
||||
}
|
||||
maxColSum = Math.max(maxColSum, sum);
|
||||
}
|
||||
return maxColSum;
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void visit(final int row, final int column, final double value) {
|
||||
columnSum += Math.abs(value);
|
||||
if (row == endRow) {
|
||||
maxColSum = Math.max(maxColSum, columnSum);
|
||||
columnSum = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public double end() {
|
||||
return maxColSum;
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public double getFrobeniusNorm() {
|
||||
final int rowCount = getRowDimension();
|
||||
final int columnCount = getColumnDimension();
|
||||
double sum2 = 0;
|
||||
for (int col = 0; col < columnCount; ++col) {
|
||||
for (int row = 0; row < rowCount; ++row) {
|
||||
final double mij = getEntry(row, col);
|
||||
sum2 += mij * mij;
|
||||
return walkInOptimizedOrder(new RealMatrixPreservingVisitor() {
|
||||
|
||||
/** Serializable version identifier */
|
||||
private static final long serialVersionUID = -6065411033772300640L;
|
||||
|
||||
/** Sum of squared entries. */
|
||||
private double sum;
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void start(final int rows, final int columns,
|
||||
final int startRow, final int endRow,
|
||||
final int startColumn, final int endColumn) {
|
||||
sum = 0;
|
||||
}
|
||||
}
|
||||
return Math.sqrt(sum2);
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void visit(final int row, final int column, final double value) {
|
||||
sum += value * value;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public double end() {
|
||||
return Math.sqrt(sum);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@ -511,11 +554,28 @@ public abstract class AbstractRealMatrix implements RealMatrix, Serializable {
|
||||
final int nRows = getRowDimension();
|
||||
final int nCols = getColumnDimension();
|
||||
final RealMatrix out = createMatrix(nCols, nRows);
|
||||
for (int row = 0; row < nRows; ++row) {
|
||||
for (int col = 0; col < nCols; ++col) {
|
||||
out.setEntry(col, row, getEntry(row, col));
|
||||
walkInOptimizedOrder(new RealMatrixPreservingVisitor() {
|
||||
|
||||
/** Serializable version identifier */
|
||||
private static final long serialVersionUID = 3807296710038754174L;
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void start(final int rows, final int columns,
|
||||
final int startRow, final int endRow,
|
||||
final int startColumn, final int endColumn) {
|
||||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void visit(final int row, final int column, final double value) {
|
||||
out.setEntry(column, row, value);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public double end() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
return out;
|
||||
|
||||
@ -691,10 +751,11 @@ public abstract class AbstractRealMatrix implements RealMatrix, Serializable {
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void walkInRowOrder(final RealMatrixChangingVisitor visitor)
|
||||
public double walkInRowOrder(final RealMatrixChangingVisitor visitor)
|
||||
throws MatrixVisitorException {
|
||||
final int rows = getRowDimension();
|
||||
final int columns = getColumnDimension();
|
||||
visitor.start(rows, columns, 0, rows - 1, 0, columns - 1);
|
||||
for (int row = 0; row < rows; ++row) {
|
||||
for (int column = 0; column < columns; ++column) {
|
||||
final double oldValue = getEntry(row, column);
|
||||
@ -703,26 +764,31 @@ public abstract class AbstractRealMatrix implements RealMatrix, Serializable {
|
||||
}
|
||||
}
|
||||
lu = null;
|
||||
return visitor.end();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void walkInRowOrder(final RealMatrixPreservingVisitor visitor)
|
||||
public double walkInRowOrder(final RealMatrixPreservingVisitor visitor)
|
||||
throws MatrixVisitorException {
|
||||
final int rows = getRowDimension();
|
||||
final int columns = getColumnDimension();
|
||||
visitor.start(rows, columns, 0, rows - 1, 0, columns - 1);
|
||||
for (int row = 0; row < rows; ++row) {
|
||||
for (int column = 0; column < columns; ++column) {
|
||||
visitor.visit(row, column, getEntry(row, column));
|
||||
}
|
||||
}
|
||||
return visitor.end();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void walkInRowOrder(final RealMatrixChangingVisitor visitor,
|
||||
final int startRow, final int endRow,
|
||||
final int startColumn, final int endColumn)
|
||||
public double walkInRowOrder(final RealMatrixChangingVisitor visitor,
|
||||
final int startRow, final int endRow,
|
||||
final int startColumn, final int endColumn)
|
||||
throws MatrixIndexException, MatrixVisitorException {
|
||||
checkSubMatrixIndex(startRow, endRow, startColumn, endColumn);
|
||||
visitor.start(getRowDimension(), getColumnDimension(),
|
||||
startRow, endRow, startColumn, endColumn);
|
||||
for (int row = startRow; row <= endRow; ++row) {
|
||||
for (int column = startColumn; column <= endColumn; ++column) {
|
||||
final double oldValue = getEntry(row, column);
|
||||
@ -731,47 +797,116 @@ public abstract class AbstractRealMatrix implements RealMatrix, Serializable {
|
||||
}
|
||||
}
|
||||
lu = null;
|
||||
return visitor.end();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void walkInRowOrder(final RealMatrixPreservingVisitor visitor,
|
||||
final int startRow, final int endRow,
|
||||
final int startColumn, final int endColumn)
|
||||
public double walkInRowOrder(final RealMatrixPreservingVisitor visitor,
|
||||
final int startRow, final int endRow,
|
||||
final int startColumn, final int endColumn)
|
||||
throws MatrixIndexException, MatrixVisitorException {
|
||||
checkSubMatrixIndex(startRow, endRow, startColumn, endColumn);
|
||||
visitor.start(getRowDimension(), getColumnDimension(),
|
||||
startRow, endRow, startColumn, endColumn);
|
||||
for (int row = startRow; row <= endRow; ++row) {
|
||||
for (int column = startColumn; column <= endColumn; ++column) {
|
||||
visitor.visit(row, column, getEntry(row, column));
|
||||
}
|
||||
}
|
||||
return visitor.end();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void walkInInternalOrder(final RealMatrixChangingVisitor visitor)
|
||||
public double walkInColumnOrder(final RealMatrixChangingVisitor visitor)
|
||||
throws MatrixVisitorException {
|
||||
walkInRowOrder(visitor);
|
||||
final int rows = getRowDimension();
|
||||
final int columns = getColumnDimension();
|
||||
visitor.start(rows, columns, 0, rows - 1, 0, columns - 1);
|
||||
for (int column = 0; column < columns; ++column) {
|
||||
for (int row = 0; row < rows; ++row) {
|
||||
final double oldValue = getEntry(row, column);
|
||||
final double newValue = visitor.visit(row, column, oldValue);
|
||||
setEntry(row, column, newValue);
|
||||
}
|
||||
}
|
||||
lu = null;
|
||||
return visitor.end();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void walkInInternalOrder(final RealMatrixPreservingVisitor visitor)
|
||||
public double walkInColumnOrder(final RealMatrixPreservingVisitor visitor)
|
||||
throws MatrixVisitorException {
|
||||
walkInRowOrder(visitor);
|
||||
final int rows = getRowDimension();
|
||||
final int columns = getColumnDimension();
|
||||
visitor.start(rows, columns, 0, rows - 1, 0, columns - 1);
|
||||
for (int column = 0; column < columns; ++column) {
|
||||
for (int row = 0; row < rows; ++row) {
|
||||
visitor.visit(row, column, getEntry(row, column));
|
||||
}
|
||||
}
|
||||
return visitor.end();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void walkInInternalOrder(final RealMatrixChangingVisitor visitor,
|
||||
public double walkInColumnOrder(final RealMatrixChangingVisitor visitor,
|
||||
final int startRow, final int endRow,
|
||||
final int startColumn, final int endColumn)
|
||||
throws MatrixIndexException, MatrixVisitorException {
|
||||
walkInRowOrder(visitor, startRow, endRow, startColumn, endColumn);
|
||||
throws MatrixIndexException, MatrixVisitorException {
|
||||
checkSubMatrixIndex(startRow, endRow, startColumn, endColumn);
|
||||
visitor.start(getRowDimension(), getColumnDimension(),
|
||||
startRow, endRow, startColumn, endColumn);
|
||||
for (int column = startColumn; column <= endColumn; ++column) {
|
||||
for (int row = startRow; row <= endRow; ++row) {
|
||||
final double oldValue = getEntry(row, column);
|
||||
final double newValue = visitor.visit(row, column, oldValue);
|
||||
setEntry(row, column, newValue);
|
||||
}
|
||||
}
|
||||
lu = null;
|
||||
return visitor.end();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void walkInInternalOrder(final RealMatrixPreservingVisitor visitor,
|
||||
public double walkInColumnOrder(final RealMatrixPreservingVisitor visitor,
|
||||
final int startRow, final int endRow,
|
||||
final int startColumn, final int endColumn)
|
||||
throws MatrixIndexException, MatrixVisitorException {
|
||||
checkSubMatrixIndex(startRow, endRow, startColumn, endColumn);
|
||||
visitor.start(getRowDimension(), getColumnDimension(),
|
||||
startRow, endRow, startColumn, endColumn);
|
||||
for (int column = startColumn; column <= endColumn; ++column) {
|
||||
for (int row = startRow; row <= endRow; ++row) {
|
||||
visitor.visit(row, column, getEntry(row, column));
|
||||
}
|
||||
}
|
||||
return visitor.end();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public double walkInOptimizedOrder(final RealMatrixChangingVisitor visitor)
|
||||
throws MatrixVisitorException {
|
||||
return walkInRowOrder(visitor);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public double walkInOptimizedOrder(final RealMatrixPreservingVisitor visitor)
|
||||
throws MatrixVisitorException {
|
||||
return walkInRowOrder(visitor);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public double walkInOptimizedOrder(final RealMatrixChangingVisitor visitor,
|
||||
final int startRow, final int endRow,
|
||||
final int startColumn, final int endColumn)
|
||||
throws MatrixIndexException, MatrixVisitorException {
|
||||
walkInRowOrder(visitor, startRow, endRow, startColumn, endColumn);
|
||||
return walkInRowOrder(visitor, startRow, endRow, startColumn, endColumn);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public double walkInOptimizedOrder(final RealMatrixPreservingVisitor visitor,
|
||||
final int startRow, final int endRow,
|
||||
final int startColumn, final int endColumn)
|
||||
throws MatrixIndexException, MatrixVisitorException {
|
||||
return walkInRowOrder(visitor, startRow, endRow, startColumn, endColumn);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
|
@ -1284,8 +1284,9 @@ public class DenseRealMatrix extends AbstractRealMatrix implements Serializable
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void walkInRowOrder(final RealMatrixChangingVisitor visitor)
|
||||
public double walkInRowOrder(final RealMatrixChangingVisitor visitor)
|
||||
throws MatrixVisitorException {
|
||||
visitor.start(rows, columns, 0, rows - 1, 0, columns - 1);
|
||||
for (int iBlock = 0; iBlock < blockRows; ++iBlock) {
|
||||
final int pStart = iBlock * BLOCK_SIZE;
|
||||
final int pEnd = Math.min(pStart + BLOCK_SIZE, rows);
|
||||
@ -1301,11 +1302,13 @@ public class DenseRealMatrix extends AbstractRealMatrix implements Serializable
|
||||
}
|
||||
}
|
||||
}
|
||||
return visitor.end();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void walkInRowOrder(final RealMatrixPreservingVisitor visitor)
|
||||
public double walkInRowOrder(final RealMatrixPreservingVisitor visitor)
|
||||
throws MatrixVisitorException {
|
||||
visitor.start(rows, columns, 0, rows - 1, 0, columns - 1);
|
||||
for (int iBlock = 0; iBlock < blockRows; ++iBlock) {
|
||||
final int pStart = iBlock * BLOCK_SIZE;
|
||||
final int pEnd = Math.min(pStart + BLOCK_SIZE, rows);
|
||||
@ -1321,14 +1324,16 @@ public class DenseRealMatrix extends AbstractRealMatrix implements Serializable
|
||||
}
|
||||
}
|
||||
}
|
||||
return visitor.end();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void walkInRowOrder(final RealMatrixChangingVisitor visitor,
|
||||
final int startRow, final int endRow,
|
||||
final int startColumn, final int endColumn)
|
||||
public double walkInRowOrder(final RealMatrixChangingVisitor visitor,
|
||||
final int startRow, final int endRow,
|
||||
final int startColumn, final int endColumn)
|
||||
throws MatrixIndexException, MatrixVisitorException {
|
||||
checkSubMatrixIndex(startRow, endRow, startColumn, endColumn);
|
||||
visitor.start(rows, columns, startRow, endRow, startColumn, endColumn);
|
||||
for (int iBlock = startRow / BLOCK_SIZE; iBlock < 1 + endRow / BLOCK_SIZE; ++iBlock) {
|
||||
final int p0 = iBlock * BLOCK_SIZE;
|
||||
final int pStart = Math.max(startRow, p0);
|
||||
@ -1346,14 +1351,16 @@ public class DenseRealMatrix extends AbstractRealMatrix implements Serializable
|
||||
}
|
||||
}
|
||||
}
|
||||
return visitor.end();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void walkInRowOrder(final RealMatrixPreservingVisitor visitor,
|
||||
final int startRow, final int endRow,
|
||||
final int startColumn, final int endColumn)
|
||||
public double walkInRowOrder(final RealMatrixPreservingVisitor visitor,
|
||||
final int startRow, final int endRow,
|
||||
final int startColumn, final int endColumn)
|
||||
throws MatrixIndexException, MatrixVisitorException {
|
||||
checkSubMatrixIndex(startRow, endRow, startColumn, endColumn);
|
||||
visitor.start(rows, columns, startRow, endRow, startColumn, endColumn);
|
||||
for (int iBlock = startRow / BLOCK_SIZE; iBlock < 1 + endRow / BLOCK_SIZE; ++iBlock) {
|
||||
final int p0 = iBlock * BLOCK_SIZE;
|
||||
final int pStart = Math.max(startRow, p0);
|
||||
@ -1371,11 +1378,13 @@ public class DenseRealMatrix extends AbstractRealMatrix implements Serializable
|
||||
}
|
||||
}
|
||||
}
|
||||
return visitor.end();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void walkInInternalOrder(final RealMatrixChangingVisitor visitor)
|
||||
public double walkInOptimizedOrder(final RealMatrixChangingVisitor 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);
|
||||
@ -1390,11 +1399,13 @@ public class DenseRealMatrix extends AbstractRealMatrix implements Serializable
|
||||
}
|
||||
}
|
||||
}
|
||||
return visitor.end();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void walkInInternalOrder(final RealMatrixPreservingVisitor visitor)
|
||||
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);
|
||||
@ -1409,14 +1420,16 @@ public class DenseRealMatrix extends AbstractRealMatrix implements Serializable
|
||||
}
|
||||
}
|
||||
}
|
||||
return visitor.end();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void walkInInternalOrder(final RealMatrixChangingVisitor visitor,
|
||||
final int startRow, final int endRow,
|
||||
final int startColumn, final int endColumn)
|
||||
public double walkInOptimizedOrder(final RealMatrixChangingVisitor visitor,
|
||||
final int startRow, final int endRow,
|
||||
final int startColumn, final int endColumn)
|
||||
throws MatrixIndexException, MatrixVisitorException {
|
||||
checkSubMatrixIndex(startRow, endRow, startColumn, endColumn);
|
||||
visitor.start(rows, columns, startRow, endRow, startColumn, endColumn);
|
||||
for (int iBlock = startRow / BLOCK_SIZE; iBlock < 1 + endRow / BLOCK_SIZE; ++iBlock) {
|
||||
final int p0 = iBlock * BLOCK_SIZE;
|
||||
final int pStart = Math.max(startRow, p0);
|
||||
@ -1434,14 +1447,16 @@ public class DenseRealMatrix extends AbstractRealMatrix implements Serializable
|
||||
}
|
||||
}
|
||||
}
|
||||
return visitor.end();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void walkInInternalOrder(final RealMatrixPreservingVisitor visitor,
|
||||
final int startRow, final int endRow,
|
||||
final int startColumn, final int endColumn)
|
||||
public double walkInOptimizedOrder(final RealMatrixPreservingVisitor visitor,
|
||||
final int startRow, final int endRow,
|
||||
final int startColumn, final int endColumn)
|
||||
throws MatrixIndexException, MatrixVisitorException {
|
||||
checkSubMatrixIndex(startRow, endRow, startColumn, endColumn);
|
||||
visitor.start(rows, columns, startRow, endRow, startColumn, endColumn);
|
||||
for (int iBlock = startRow / BLOCK_SIZE; iBlock < 1 + endRow / BLOCK_SIZE; ++iBlock) {
|
||||
final int p0 = iBlock * BLOCK_SIZE;
|
||||
final int pStart = Math.max(startRow, p0);
|
||||
@ -1459,6 +1474,7 @@ public class DenseRealMatrix extends AbstractRealMatrix implements Serializable
|
||||
}
|
||||
}
|
||||
}
|
||||
return visitor.end();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -500,34 +500,57 @@ public interface RealMatrix extends Serializable {
|
||||
|
||||
/**
|
||||
* Visit (and possibly change) all matrix entries in row order.
|
||||
* <p>Row order starts at upper left and iterating through all elements
|
||||
* of a row from left to right before going to the leftmost element
|
||||
* of the next row.</p>
|
||||
* @param visitor visitor used to process all matrix entries
|
||||
* @exception MatrixVisitorException if the visitor cannot process an entry
|
||||
* @see #walkInRowOrder(RealMatrixPreservingVisitor)
|
||||
* @see #walkInRowOrder(RealMatrixChangingVisitor, int, int, int, int)
|
||||
* @see #walkInRowOrder(RealMatrixPreservingVisitor, int, int, int, int)
|
||||
* @see #walkInInternalOrder(RealMatrixChangingVisitor)
|
||||
* @see #walkInInternalOrder(RealMatrixPreservingVisitor)
|
||||
* @see #walkInInternalOrder(RealMatrixChangingVisitor, int, int, int, int)
|
||||
* @see #walkInInternalOrder(RealMatrixPreservingVisitor, int, int, int, int)
|
||||
* @see #walkInColumnOrder(RealMatrixChangingVisitor)
|
||||
* @see #walkInColumnOrder(RealMatrixPreservingVisitor)
|
||||
* @see #walkInColumnOrder(RealMatrixChangingVisitor, int, int, int, int)
|
||||
* @see #walkInColumnOrder(RealMatrixPreservingVisitor, int, int, int, int)
|
||||
* @see #walkInOptimizedOrder(RealMatrixChangingVisitor)
|
||||
* @see #walkInOptimizedOrder(RealMatrixPreservingVisitor)
|
||||
* @see #walkInOptimizedOrder(RealMatrixChangingVisitor, int, int, int, int)
|
||||
* @see #walkInOptimizedOrder(RealMatrixPreservingVisitor, int, int, int, int)
|
||||
* @return the value returned by {@link RealMatrixChangingVisitor#end()} at the end
|
||||
* of the walk
|
||||
*/
|
||||
void walkInRowOrder(RealMatrixChangingVisitor visitor) throws MatrixVisitorException;
|
||||
double walkInRowOrder(RealMatrixChangingVisitor visitor)
|
||||
throws MatrixVisitorException;
|
||||
|
||||
/**
|
||||
* Visit (but don't change) all matrix entries in row order.
|
||||
* <p>Row order starts at upper left and iterating through all elements
|
||||
* of a row from left to right before going to the leftmost element
|
||||
* of the next row.</p>
|
||||
* @param visitor visitor used to process all matrix entries
|
||||
* @exception MatrixVisitorException if the visitor cannot process an entry
|
||||
* @see #walkInRowOrder(RealMatrixChangingVisitor)
|
||||
* @see #walkInRowOrder(RealMatrixChangingVisitor, int, int, int, int)
|
||||
* @see #walkInRowOrder(RealMatrixPreservingVisitor, int, int, int, int)
|
||||
* @see #walkInInternalOrder(RealMatrixChangingVisitor)
|
||||
* @see #walkInInternalOrder(RealMatrixPreservingVisitor)
|
||||
* @see #walkInInternalOrder(RealMatrixChangingVisitor, int, int, int, int)
|
||||
* @see #walkInInternalOrder(RealMatrixPreservingVisitor, int, int, int, int)
|
||||
* @see #walkInColumnOrder(RealMatrixChangingVisitor)
|
||||
* @see #walkInColumnOrder(RealMatrixPreservingVisitor)
|
||||
* @see #walkInColumnOrder(RealMatrixChangingVisitor, int, int, int, int)
|
||||
* @see #walkInColumnOrder(RealMatrixPreservingVisitor, int, int, int, int)
|
||||
* @see #walkInOptimizedOrder(RealMatrixChangingVisitor)
|
||||
* @see #walkInOptimizedOrder(RealMatrixPreservingVisitor)
|
||||
* @see #walkInOptimizedOrder(RealMatrixChangingVisitor, int, int, int, int)
|
||||
* @see #walkInOptimizedOrder(RealMatrixPreservingVisitor, int, int, int, int)
|
||||
* @return the value returned by {@link RealMatrixPreservingVisitor#end()} at the end
|
||||
* of the walk
|
||||
*/
|
||||
void walkInRowOrder(RealMatrixPreservingVisitor visitor) throws MatrixVisitorException;
|
||||
double walkInRowOrder(RealMatrixPreservingVisitor visitor)
|
||||
throws MatrixVisitorException;
|
||||
|
||||
/**
|
||||
* Visit (and possibly change) all matrix entries in row order.
|
||||
* Visit (and possibly change) some matrix entries in row order.
|
||||
* <p>Row order starts at upper left and iterating through all elements
|
||||
* of a row from left to right before going to the leftmost element
|
||||
* of the next row.</p>
|
||||
* @param visitor visitor used to process all matrix entries
|
||||
* @param startRow Initial row index
|
||||
* @param endRow Final row index (inclusive)
|
||||
@ -538,17 +561,26 @@ public interface RealMatrix extends Serializable {
|
||||
* @see #walkInRowOrder(RealMatrixChangingVisitor)
|
||||
* @see #walkInRowOrder(RealMatrixPreservingVisitor)
|
||||
* @see #walkInRowOrder(RealMatrixPreservingVisitor, int, int, int, int)
|
||||
* @see #walkInInternalOrder(RealMatrixChangingVisitor)
|
||||
* @see #walkInInternalOrder(RealMatrixPreservingVisitor)
|
||||
* @see #walkInInternalOrder(RealMatrixChangingVisitor, int, int, int, int)
|
||||
* @see #walkInInternalOrder(RealMatrixPreservingVisitor, int, int, int, int)
|
||||
* @see #walkInColumnOrder(RealMatrixChangingVisitor)
|
||||
* @see #walkInColumnOrder(RealMatrixPreservingVisitor)
|
||||
* @see #walkInColumnOrder(RealMatrixChangingVisitor, int, int, int, int)
|
||||
* @see #walkInColumnOrder(RealMatrixPreservingVisitor, int, int, int, int)
|
||||
* @see #walkInOptimizedOrder(RealMatrixChangingVisitor)
|
||||
* @see #walkInOptimizedOrder(RealMatrixPreservingVisitor)
|
||||
* @see #walkInOptimizedOrder(RealMatrixChangingVisitor, int, int, int, int)
|
||||
* @see #walkInOptimizedOrder(RealMatrixPreservingVisitor, int, int, int, int)
|
||||
* @return the value returned by {@link RealMatrixChangingVisitor#end()} at the end
|
||||
* of the walk
|
||||
*/
|
||||
void walkInRowOrder(RealMatrixChangingVisitor visitor,
|
||||
int startRow, int endRow, int startColumn, int endColumn)
|
||||
double walkInRowOrder(RealMatrixChangingVisitor visitor,
|
||||
int startRow, int endRow, int startColumn, int endColumn)
|
||||
throws MatrixIndexException, MatrixVisitorException;
|
||||
|
||||
/**
|
||||
* Visit (but don't change) all matrix entries in row order.
|
||||
* Visit (but don't change) some matrix entries in row order.
|
||||
* <p>Row order starts at upper left and iterating through all elements
|
||||
* of a row from left to right before going to the leftmost element
|
||||
* of the next row.</p>
|
||||
* @param visitor visitor used to process all matrix entries
|
||||
* @param startRow Initial row index
|
||||
* @param endRow Final row index (inclusive)
|
||||
@ -559,57 +591,179 @@ public interface RealMatrix extends Serializable {
|
||||
* @see #walkInRowOrder(RealMatrixChangingVisitor)
|
||||
* @see #walkInRowOrder(RealMatrixPreservingVisitor)
|
||||
* @see #walkInRowOrder(RealMatrixChangingVisitor, int, int, int, int)
|
||||
* @see #walkInInternalOrder(RealMatrixChangingVisitor)
|
||||
* @see #walkInInternalOrder(RealMatrixPreservingVisitor)
|
||||
* @see #walkInInternalOrder(RealMatrixChangingVisitor, int, int, int, int)
|
||||
* @see #walkInInternalOrder(RealMatrixPreservingVisitor, int, int, int, int)
|
||||
* @see #walkInColumnOrder(RealMatrixChangingVisitor)
|
||||
* @see #walkInColumnOrder(RealMatrixPreservingVisitor)
|
||||
* @see #walkInColumnOrder(RealMatrixChangingVisitor, int, int, int, int)
|
||||
* @see #walkInColumnOrder(RealMatrixPreservingVisitor, int, int, int, int)
|
||||
* @see #walkInOptimizedOrder(RealMatrixChangingVisitor)
|
||||
* @see #walkInOptimizedOrder(RealMatrixPreservingVisitor)
|
||||
* @see #walkInOptimizedOrder(RealMatrixChangingVisitor, int, int, int, int)
|
||||
* @see #walkInOptimizedOrder(RealMatrixPreservingVisitor, int, int, int, int)
|
||||
* @return the value returned by {@link RealMatrixPreservingVisitor#end()} at the end
|
||||
* of the walk
|
||||
*/
|
||||
void walkInRowOrder(RealMatrixPreservingVisitor visitor,
|
||||
int startRow, int endRow, int startColumn, int endColumn)
|
||||
double walkInRowOrder(RealMatrixPreservingVisitor visitor,
|
||||
int startRow, int endRow, int startColumn, int endColumn)
|
||||
throws MatrixIndexException, MatrixVisitorException;
|
||||
|
||||
/**
|
||||
* Visit (and possibly change) all matrix entries in row order.
|
||||
* <p>The matrix internal order depends on the exact matrix class. It may be
|
||||
* different from traditional row order, but is generally faster. If there is no need
|
||||
* for an explicit walk order, this method should be preferred to the {@link
|
||||
* #walkInRowOrder(RealMatrixChangingVisitor)} one.</p>
|
||||
* Visit (and possibly change) all matrix entries in column order.
|
||||
* <p>Column order starts at upper left and iterating through all elements
|
||||
* of a column from top to bottom before going to the topmost element
|
||||
* of the next column.</p>
|
||||
* @param visitor visitor used to process all matrix entries
|
||||
* @exception MatrixVisitorException if the visitor cannot process an entry
|
||||
* @see #walkInRowOrder(RealMatrixChangingVisitor)
|
||||
* @see #walkInRowOrder(RealMatrixPreservingVisitor)
|
||||
* @see #walkInRowOrder(RealMatrixChangingVisitor, int, int, int, int)
|
||||
* @see #walkInRowOrder(RealMatrixPreservingVisitor, int, int, int, int)
|
||||
* @see #walkInInternalOrder(RealMatrixPreservingVisitor)
|
||||
* @see #walkInInternalOrder(RealMatrixChangingVisitor, int, int, int, int)
|
||||
* @see #walkInInternalOrder(RealMatrixPreservingVisitor, int, int, int, int)
|
||||
* @see #walkInColumnOrder(RealMatrixPreservingVisitor)
|
||||
* @see #walkInColumnOrder(RealMatrixChangingVisitor, int, int, int, int)
|
||||
* @see #walkInColumnOrder(RealMatrixPreservingVisitor, int, int, int, int)
|
||||
* @see #walkInOptimizedOrder(RealMatrixChangingVisitor)
|
||||
* @see #walkInOptimizedOrder(RealMatrixPreservingVisitor)
|
||||
* @see #walkInOptimizedOrder(RealMatrixChangingVisitor, int, int, int, int)
|
||||
* @see #walkInOptimizedOrder(RealMatrixPreservingVisitor, int, int, int, int)
|
||||
* @return the value returned by {@link RealMatrixChangingVisitor#end()} at the end
|
||||
* of the walk
|
||||
*/
|
||||
void walkInInternalOrder(RealMatrixChangingVisitor visitor) throws MatrixVisitorException;
|
||||
double walkInColumnOrder(RealMatrixChangingVisitor visitor)
|
||||
throws MatrixVisitorException;
|
||||
|
||||
/**
|
||||
* Visit (but don't change) all matrix entries in row order.
|
||||
* <p>The matrix internal order depends on the exact matrix class. It may be
|
||||
* different from traditional row order, but is generally faster. If there is no need
|
||||
* for an explicit walk order, this method should be preferred to the {@link
|
||||
* #walkInRowOrder(RealMatrixPreservingVisitor)} one.</p>
|
||||
* Visit (but don't change) all matrix entries in column order.
|
||||
* <p>Column order starts at upper left and iterating through all elements
|
||||
* of a column from top to bottom before going to the topmost element
|
||||
* of the next column.</p>
|
||||
* @param visitor visitor used to process all matrix entries
|
||||
* @exception MatrixVisitorException if the visitor cannot process an entry
|
||||
* @see #walkInRowOrder(RealMatrixChangingVisitor)
|
||||
* @see #walkInRowOrder(RealMatrixPreservingVisitor)
|
||||
* @see #walkInRowOrder(RealMatrixChangingVisitor, int, int, int, int)
|
||||
* @see #walkInRowOrder(RealMatrixPreservingVisitor, int, int, int, int)
|
||||
* @see #walkInInternalOrder(RealMatrixChangingVisitor)
|
||||
* @see #walkInInternalOrder(RealMatrixChangingVisitor, int, int, int, int)
|
||||
* @see #walkInInternalOrder(RealMatrixPreservingVisitor, int, int, int, int)
|
||||
* @see #walkInColumnOrder(RealMatrixChangingVisitor)
|
||||
* @see #walkInColumnOrder(RealMatrixChangingVisitor, int, int, int, int)
|
||||
* @see #walkInColumnOrder(RealMatrixPreservingVisitor, int, int, int, int)
|
||||
* @see #walkInOptimizedOrder(RealMatrixChangingVisitor)
|
||||
* @see #walkInOptimizedOrder(RealMatrixPreservingVisitor)
|
||||
* @see #walkInOptimizedOrder(RealMatrixChangingVisitor, int, int, int, int)
|
||||
* @see #walkInOptimizedOrder(RealMatrixPreservingVisitor, int, int, int, int)
|
||||
* @return the value returned by {@link RealMatrixPreservingVisitor#end()} at the end
|
||||
* of the walk
|
||||
*/
|
||||
void walkInInternalOrder(RealMatrixPreservingVisitor visitor) throws MatrixVisitorException;
|
||||
double walkInColumnOrder(RealMatrixPreservingVisitor visitor)
|
||||
throws MatrixVisitorException;
|
||||
|
||||
/**
|
||||
* Visit (and possibly change) all matrix entries in row order.
|
||||
* <p>The matrix internal order depends on the exact matrix class. It may be
|
||||
* different from traditional row order, but is generally faster. If there is no need
|
||||
* for an explicit walk order, this method should be preferred to the {@link
|
||||
* #walkInRowOrder(RealMatrixChangingVisitor, int, int, int, int)} one.</p>
|
||||
* Visit (and possibly change) some matrix entries in column order.
|
||||
* <p>Column order starts at upper left and iterating through all elements
|
||||
* of a column from top to bottom before going to the topmost element
|
||||
* of the next column.</p>
|
||||
* @param visitor visitor used to process all matrix entries
|
||||
* @param startRow Initial row index
|
||||
* @param endRow Final row index (inclusive)
|
||||
* @param startColumn Initial column index
|
||||
* @param endColumn Final column index
|
||||
* @exception MatrixVisitorException if the visitor cannot process an entry
|
||||
* @exception MatrixIndexException if the indices are not valid
|
||||
* @see #walkInRowOrder(RealMatrixChangingVisitor)
|
||||
* @see #walkInRowOrder(RealMatrixPreservingVisitor)
|
||||
* @see #walkInRowOrder(RealMatrixChangingVisitor, int, int, int, int)
|
||||
* @see #walkInRowOrder(RealMatrixPreservingVisitor, int, int, int, int)
|
||||
* @see #walkInColumnOrder(RealMatrixChangingVisitor)
|
||||
* @see #walkInColumnOrder(RealMatrixPreservingVisitor)
|
||||
* @see #walkInColumnOrder(RealMatrixPreservingVisitor, int, int, int, int)
|
||||
* @see #walkInOptimizedOrder(RealMatrixChangingVisitor)
|
||||
* @see #walkInOptimizedOrder(RealMatrixPreservingVisitor)
|
||||
* @see #walkInOptimizedOrder(RealMatrixChangingVisitor, int, int, int, int)
|
||||
* @see #walkInOptimizedOrder(RealMatrixPreservingVisitor, int, int, int, int)
|
||||
* @return the value returned by {@link RealMatrixChangingVisitor#end()} at the end
|
||||
* of the walk
|
||||
*/
|
||||
double walkInColumnOrder(RealMatrixChangingVisitor visitor,
|
||||
int startRow, int endRow, int startColumn, int endColumn)
|
||||
throws MatrixIndexException, MatrixVisitorException;
|
||||
|
||||
/**
|
||||
* Visit (but don't change) some matrix entries in column order.
|
||||
* <p>Column order starts at upper left and iterating through all elements
|
||||
* of a column from top to bottom before going to the topmost element
|
||||
* of the next column.</p>
|
||||
* @param visitor visitor used to process all matrix entries
|
||||
* @param startRow Initial row index
|
||||
* @param endRow Final row index (inclusive)
|
||||
* @param startColumn Initial column index
|
||||
* @param endColumn Final column index
|
||||
* @exception MatrixVisitorException if the visitor cannot process an entry
|
||||
* @exception MatrixIndexException if the indices are not valid
|
||||
* @see #walkInRowOrder(RealMatrixChangingVisitor)
|
||||
* @see #walkInRowOrder(RealMatrixPreservingVisitor)
|
||||
* @see #walkInRowOrder(RealMatrixChangingVisitor, int, int, int, int)
|
||||
* @see #walkInRowOrder(RealMatrixPreservingVisitor, int, int, int, int)
|
||||
* @see #walkInColumnOrder(RealMatrixChangingVisitor)
|
||||
* @see #walkInColumnOrder(RealMatrixPreservingVisitor)
|
||||
* @see #walkInColumnOrder(RealMatrixChangingVisitor, int, int, int, int)
|
||||
* @see #walkInOptimizedOrder(RealMatrixChangingVisitor)
|
||||
* @see #walkInOptimizedOrder(RealMatrixPreservingVisitor)
|
||||
* @see #walkInOptimizedOrder(RealMatrixChangingVisitor, int, int, int, int)
|
||||
* @see #walkInOptimizedOrder(RealMatrixPreservingVisitor, int, int, int, int)
|
||||
* @return the value returned by {@link RealMatrixPreservingVisitor#end()} at the end
|
||||
* of the walk
|
||||
*/
|
||||
double walkInColumnOrder(RealMatrixPreservingVisitor visitor,
|
||||
int startRow, int endRow, int startColumn, int endColumn)
|
||||
throws MatrixIndexException, MatrixVisitorException;
|
||||
|
||||
/**
|
||||
* Visit (and possibly change) all matrix entries using the fastest possible order.
|
||||
* <p>The fastest walking order depends on the exact matrix class. It may be
|
||||
* different from traditional row or column orders.</p>
|
||||
* @param visitor visitor used to process all matrix entries
|
||||
* @exception MatrixVisitorException if the visitor cannot process an entry
|
||||
* @see #walkInRowOrder(RealMatrixChangingVisitor)
|
||||
* @see #walkInRowOrder(RealMatrixPreservingVisitor)
|
||||
* @see #walkInRowOrder(RealMatrixChangingVisitor, int, int, int, int)
|
||||
* @see #walkInRowOrder(RealMatrixPreservingVisitor, int, int, int, int)
|
||||
* @see #walkInColumnOrder(RealMatrixChangingVisitor)
|
||||
* @see #walkInColumnOrder(RealMatrixPreservingVisitor)
|
||||
* @see #walkInColumnOrder(RealMatrixChangingVisitor, int, int, int, int)
|
||||
* @see #walkInColumnOrder(RealMatrixPreservingVisitor, int, int, int, int)
|
||||
* @see #walkInOptimizedOrder(RealMatrixPreservingVisitor)
|
||||
* @see #walkInOptimizedOrder(RealMatrixChangingVisitor, int, int, int, int)
|
||||
* @see #walkInOptimizedOrder(RealMatrixPreservingVisitor, int, int, int, int)
|
||||
* @return the value returned by {@link RealMatrixChangingVisitor#end()} at the end
|
||||
* of the walk
|
||||
*/
|
||||
double walkInOptimizedOrder(RealMatrixChangingVisitor visitor)
|
||||
throws MatrixVisitorException;
|
||||
|
||||
/**
|
||||
* Visit (but don't change) all matrix entries using the fastest possible order.
|
||||
* <p>The fastest walking order depends on the exact matrix class. It may be
|
||||
* different from traditional row or column orders.</p>
|
||||
* @param visitor visitor used to process all matrix entries
|
||||
* @exception MatrixVisitorException if the visitor cannot process an entry
|
||||
* @see #walkInRowOrder(RealMatrixChangingVisitor)
|
||||
* @see #walkInRowOrder(RealMatrixPreservingVisitor)
|
||||
* @see #walkInRowOrder(RealMatrixChangingVisitor, int, int, int, int)
|
||||
* @see #walkInRowOrder(RealMatrixPreservingVisitor, int, int, int, int)
|
||||
* @see #walkInColumnOrder(RealMatrixChangingVisitor)
|
||||
* @see #walkInColumnOrder(RealMatrixPreservingVisitor)
|
||||
* @see #walkInColumnOrder(RealMatrixChangingVisitor, int, int, int, int)
|
||||
* @see #walkInColumnOrder(RealMatrixPreservingVisitor, int, int, int, int)
|
||||
* @see #walkInOptimizedOrder(RealMatrixChangingVisitor)
|
||||
* @see #walkInOptimizedOrder(RealMatrixChangingVisitor, int, int, int, int)
|
||||
* @see #walkInOptimizedOrder(RealMatrixPreservingVisitor, int, int, int, int)
|
||||
* @return the value returned by {@link RealMatrixPreservingVisitor#end()} at the end
|
||||
* of the walk
|
||||
*/
|
||||
double walkInOptimizedOrder(RealMatrixPreservingVisitor visitor)
|
||||
throws MatrixVisitorException;
|
||||
|
||||
/**
|
||||
* Visit (and possibly change) some matrix entries using the fastest possible order.
|
||||
* <p>The fastest walking order depends on the exact matrix class. It may be
|
||||
* different from traditional row or column orders.</p>
|
||||
* @param visitor visitor used to process all matrix entries
|
||||
* @param startRow Initial row index
|
||||
* @param endRow Final row index (inclusive)
|
||||
@ -621,21 +775,24 @@ public interface RealMatrix extends Serializable {
|
||||
* @see #walkInRowOrder(RealMatrixPreservingVisitor)
|
||||
* @see #walkInRowOrder(RealMatrixChangingVisitor, int, int, int, int)
|
||||
* @see #walkInRowOrder(RealMatrixPreservingVisitor, int, int, int, int)
|
||||
* @see #walkInInternalOrder(RealMatrixChangingVisitor)
|
||||
* @see #walkInInternalOrder(RealMatrixPreservingVisitor)
|
||||
* @see #walkInInternalOrder(RealMatrixPreservingVisitor, int, int, int, int)
|
||||
* @see #walkInColumnOrder(RealMatrixChangingVisitor)
|
||||
* @see #walkInColumnOrder(RealMatrixPreservingVisitor)
|
||||
* @see #walkInColumnOrder(RealMatrixChangingVisitor, int, int, int, int)
|
||||
* @see #walkInColumnOrder(RealMatrixPreservingVisitor, int, int, int, int)
|
||||
* @see #walkInOptimizedOrder(RealMatrixChangingVisitor)
|
||||
* @see #walkInOptimizedOrder(RealMatrixPreservingVisitor)
|
||||
* @see #walkInOptimizedOrder(RealMatrixPreservingVisitor, int, int, int, int)
|
||||
* @return the value returned by {@link RealMatrixChangingVisitor#end()} at the end
|
||||
* of the walk
|
||||
*/
|
||||
void walkInInternalOrder(RealMatrixChangingVisitor visitor,
|
||||
int startRow, int endRow, int startColumn, int endColumn)
|
||||
double walkInOptimizedOrder(RealMatrixChangingVisitor visitor,
|
||||
int startRow, int endRow, int startColumn, int endColumn)
|
||||
throws MatrixIndexException, MatrixVisitorException;
|
||||
|
||||
/**
|
||||
* Visit (but don't change) all matrix entries in row order.
|
||||
* Visit (and possibly change) all matrix entries in row order.
|
||||
* <p>The matrix internal order depends on the exact matrix class. It may be
|
||||
* different from traditional row order, but is generally faster. If there is no need
|
||||
* for an explicit walk order, this method should be preferred to the {@link
|
||||
* #walkInRowOrder(RealMatrixPreservingVisitor, int, int, int, int)} one.</p>
|
||||
* Visit (but don't change) some matrix entries using the fastest possible order.
|
||||
* <p>The fastest walking order depends on the exact matrix class. It may be
|
||||
* different from traditional row or column orders.</p>
|
||||
* @param visitor visitor used to process all matrix entries
|
||||
* @param startRow Initial row index
|
||||
* @param endRow Final row index (inclusive)
|
||||
@ -647,12 +804,18 @@ public interface RealMatrix extends Serializable {
|
||||
* @see #walkInRowOrder(RealMatrixPreservingVisitor)
|
||||
* @see #walkInRowOrder(RealMatrixChangingVisitor, int, int, int, int)
|
||||
* @see #walkInRowOrder(RealMatrixPreservingVisitor, int, int, int, int)
|
||||
* @see #walkInInternalOrder(RealMatrixChangingVisitor)
|
||||
* @see #walkInInternalOrder(RealMatrixPreservingVisitor)
|
||||
* @see #walkInInternalOrder(RealMatrixChangingVisitor, int, int, int, int)
|
||||
* @see #walkInColumnOrder(RealMatrixChangingVisitor)
|
||||
* @see #walkInColumnOrder(RealMatrixPreservingVisitor)
|
||||
* @see #walkInColumnOrder(RealMatrixChangingVisitor, int, int, int, int)
|
||||
* @see #walkInColumnOrder(RealMatrixPreservingVisitor, int, int, int, int)
|
||||
* @see #walkInOptimizedOrder(RealMatrixChangingVisitor)
|
||||
* @see #walkInOptimizedOrder(RealMatrixPreservingVisitor)
|
||||
* @see #walkInOptimizedOrder(RealMatrixChangingVisitor, int, int, int, int)
|
||||
* @return the value returned by {@link RealMatrixPreservingVisitor#end()} at the end
|
||||
* of the walk
|
||||
*/
|
||||
void walkInInternalOrder(RealMatrixPreservingVisitor visitor,
|
||||
int startRow, int endRow, int startColumn, int endColumn)
|
||||
double walkInOptimizedOrder(RealMatrixPreservingVisitor visitor,
|
||||
int startRow, int endRow, int startColumn, int endColumn)
|
||||
throws MatrixIndexException, MatrixVisitorException;
|
||||
|
||||
/**
|
||||
|
@ -27,6 +27,19 @@ import java.io.Serializable;
|
||||
*/
|
||||
public interface RealMatrixChangingVisitor extends Serializable {
|
||||
|
||||
/**
|
||||
* Start visiting a matrix.
|
||||
* <p>This method is called once before any entry of the matrix is visited.</p>
|
||||
* @param rows number of rows of the matrix
|
||||
* @param columns number of columns of the matrix
|
||||
* @param startRow Initial row index
|
||||
* @param endRow Final row index (inclusive)
|
||||
* @param startColumn Initial column index
|
||||
* @param endColumn Final column index (inclusive)
|
||||
*/
|
||||
void start(int rows, int columns,
|
||||
int startRow, int endRow, int startColumn, int endColumn);
|
||||
|
||||
/**
|
||||
* Visit one matrix entry.
|
||||
* @param row row index of the entry
|
||||
@ -38,4 +51,11 @@ public interface RealMatrixChangingVisitor extends Serializable {
|
||||
double visit(int row, int column, double value)
|
||||
throws MatrixVisitorException;
|
||||
|
||||
/**
|
||||
* End visiting a matrix.
|
||||
* <p>This method is called once after all entries of the matrix have been visited.</p>
|
||||
* @return the value that the <code>walkInXxxOrder</code> must return
|
||||
*/
|
||||
double end();
|
||||
|
||||
}
|
||||
|
@ -460,57 +460,129 @@ public class RealMatrixImpl extends AbstractRealMatrix implements Serializable {
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void walkInRowOrder(final RealMatrixChangingVisitor visitor)
|
||||
public double walkInRowOrder(final RealMatrixChangingVisitor visitor)
|
||||
throws MatrixVisitorException {
|
||||
final int rows = getRowDimension();
|
||||
final int columns = getColumnDimension();
|
||||
visitor.start(rows, columns, 0, rows - 1, 0, columns - 1);
|
||||
for (int i = 0; i < rows; ++i) {
|
||||
final double[] rowI = data[i];
|
||||
for (int j = 0; j < columns; ++j) {
|
||||
rowI[j] = visitor.visit(i, j, rowI[j]);
|
||||
}
|
||||
}
|
||||
return visitor.end();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void walkInRowOrder(final RealMatrixPreservingVisitor visitor)
|
||||
public double walkInRowOrder(final RealMatrixPreservingVisitor visitor)
|
||||
throws MatrixVisitorException {
|
||||
final int rows = getRowDimension();
|
||||
final int columns = getColumnDimension();
|
||||
visitor.start(rows, columns, 0, rows - 1, 0, columns - 1);
|
||||
for (int i = 0; i < rows; ++i) {
|
||||
final double[] rowI = data[i];
|
||||
for (int j = 0; j < columns; ++j) {
|
||||
visitor.visit(i, j, rowI[j]);
|
||||
}
|
||||
}
|
||||
return visitor.end();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void walkInRowOrder(final RealMatrixChangingVisitor visitor,
|
||||
final int startRow, final int endRow,
|
||||
final int startColumn, final int endColumn)
|
||||
public double walkInRowOrder(final RealMatrixChangingVisitor visitor,
|
||||
final int startRow, final int endRow,
|
||||
final int startColumn, final int endColumn)
|
||||
throws MatrixIndexException, MatrixVisitorException {
|
||||
checkSubMatrixIndex(startRow, endRow, startColumn, endColumn);
|
||||
visitor.start(getRowDimension(), getColumnDimension(),
|
||||
startRow, endRow, startColumn, endColumn);
|
||||
for (int i = startRow; i <= endRow; ++i) {
|
||||
final double[] rowI = data[i];
|
||||
for (int j = startColumn; j <= endColumn; ++j) {
|
||||
rowI[j] = visitor.visit(i, j, rowI[j]);
|
||||
}
|
||||
}
|
||||
return visitor.end();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public void walkInRowOrder(final RealMatrixPreservingVisitor visitor,
|
||||
final int startRow, final int endRow,
|
||||
final int startColumn, final int endColumn)
|
||||
public double walkInRowOrder(final RealMatrixPreservingVisitor visitor,
|
||||
final int startRow, final int endRow,
|
||||
final int startColumn, final int endColumn)
|
||||
throws MatrixIndexException, MatrixVisitorException {
|
||||
checkSubMatrixIndex(startRow, endRow, startColumn, endColumn);
|
||||
visitor.start(getRowDimension(), getColumnDimension(),
|
||||
startRow, endRow, startColumn, endColumn);
|
||||
for (int i = startRow; i <= endRow; ++i) {
|
||||
final double[] rowI = data[i];
|
||||
for (int j = startColumn; j <= endColumn; ++j) {
|
||||
visitor.visit(i, j, rowI[j]);
|
||||
}
|
||||
}
|
||||
return visitor.end();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public double walkInColumnOrder(final RealMatrixChangingVisitor visitor)
|
||||
throws MatrixVisitorException {
|
||||
final int rows = getRowDimension();
|
||||
final int columns = getColumnDimension();
|
||||
visitor.start(rows, columns, 0, rows - 1, 0, columns - 1);
|
||||
for (int j = 0; j < columns; ++j) {
|
||||
for (int i = 0; i < rows; ++i) {
|
||||
final double[] rowI = data[i];
|
||||
rowI[j] = visitor.visit(i, j, rowI[j]);
|
||||
}
|
||||
}
|
||||
return visitor.end();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public double walkInColumnOrder(final RealMatrixPreservingVisitor visitor)
|
||||
throws MatrixVisitorException {
|
||||
final int rows = getRowDimension();
|
||||
final int columns = getColumnDimension();
|
||||
visitor.start(rows, columns, 0, rows - 1, 0, columns - 1);
|
||||
for (int j = 0; j < columns; ++j) {
|
||||
for (int i = 0; i < rows; ++i) {
|
||||
visitor.visit(i, j, data[i][j]);
|
||||
}
|
||||
}
|
||||
return visitor.end();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public double walkInColumnOrder(final RealMatrixChangingVisitor visitor,
|
||||
final int startRow, final int endRow,
|
||||
final int startColumn, final int endColumn)
|
||||
throws MatrixIndexException, MatrixVisitorException {
|
||||
checkSubMatrixIndex(startRow, endRow, startColumn, endColumn);
|
||||
visitor.start(getRowDimension(), getColumnDimension(),
|
||||
startRow, endRow, startColumn, endColumn);
|
||||
for (int j = startColumn; j <= endColumn; ++j) {
|
||||
for (int i = startRow; i <= endRow; ++i) {
|
||||
final double[] rowI = data[i];
|
||||
rowI[j] = visitor.visit(i, j, rowI[j]);
|
||||
}
|
||||
}
|
||||
return visitor.end();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public double walkInColumnOrder(final RealMatrixPreservingVisitor visitor,
|
||||
final int startRow, final int endRow,
|
||||
final int startColumn, final int endColumn)
|
||||
throws MatrixIndexException, MatrixVisitorException {
|
||||
checkSubMatrixIndex(startRow, endRow, startColumn, endColumn);
|
||||
visitor.start(getRowDimension(), getColumnDimension(),
|
||||
startRow, endRow, startColumn, endColumn);
|
||||
for (int j = startColumn; j <= endColumn; ++j) {
|
||||
for (int i = startRow; i <= endRow; ++i) {
|
||||
visitor.visit(i, j, data[i][j]);
|
||||
}
|
||||
}
|
||||
return visitor.end();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -27,6 +27,19 @@ import java.io.Serializable;
|
||||
*/
|
||||
public interface RealMatrixPreservingVisitor extends Serializable {
|
||||
|
||||
/**
|
||||
* Start visiting a matrix.
|
||||
* <p>This method is called once before any entry of the matrix is visited.</p>
|
||||
* @param rows number of rows of the matrix
|
||||
* @param columns number of columns of the matrix
|
||||
* @param startRow Initial row index
|
||||
* @param endRow Final row index (inclusive)
|
||||
* @param startColumn Initial column index
|
||||
* @param endColumn Final column index (inclusive)
|
||||
*/
|
||||
void start(int rows, int columns,
|
||||
int startRow, int endRow, int startColumn, int endColumn);
|
||||
|
||||
/**
|
||||
* Visit one matrix entry.
|
||||
* @param row row index of the entry
|
||||
@ -37,4 +50,11 @@ public interface RealMatrixPreservingVisitor extends Serializable {
|
||||
void visit(int row, int column, double value)
|
||||
throws MatrixVisitorException;
|
||||
|
||||
/**
|
||||
* End visiting a matrix.
|
||||
* <p>This method is called once after all entries of the matrix have been visited.</p>
|
||||
* @return the value that the <code>walkInXxxOrder</code> must return
|
||||
*/
|
||||
double end();
|
||||
|
||||
}
|
||||
|
@ -41,9 +41,10 @@ The <action> type attribute can be add,update,fix,remove.
|
||||
<release version="2.0" date="TBD" description="TBD">
|
||||
<action dev="luc" type="add" >
|
||||
Added method to walk matrix entries with or without changing them in the
|
||||
visitor design pattern sense. Two different orders can be used, row by row
|
||||
of following internal storage. Internal order should be preferred when no
|
||||
specific order is needed, because it will be more cache efficient.
|
||||
visitor design pattern sense. Three different orders can be used, row by row,
|
||||
column by column or optimized order according to internal storage. Optimized
|
||||
order should be preferred when no specific order is needed, because it will be
|
||||
more cache efficient.
|
||||
</action>
|
||||
<action dev="luc" type="add" issue="MATH-215" due-to="Bernhard Grünewaldt">
|
||||
Added Fast Hadamard Transform.
|
||||
|
@ -374,8 +374,8 @@ public final class DenseRealMatrixTest extends TestCase {
|
||||
/** test transpose */
|
||||
public void testTranspose() {
|
||||
RealMatrix m = new DenseRealMatrix(testData);
|
||||
RealMatrix mIT = new LUSolver(new LUDecompositionImpl(m)).getInverse().transpose();
|
||||
RealMatrix mTI = new LUSolver(new LUDecompositionImpl(m.transpose())).getInverse();
|
||||
RealMatrix mIT = new LUDecompositionImpl(m).getSolver().getInverse().transpose();
|
||||
RealMatrix mTI = new LUDecompositionImpl(m.transpose()).getSolver().getInverse();
|
||||
assertClose(mIT, mTI, normTolerance);
|
||||
m = new DenseRealMatrix(testData2);
|
||||
RealMatrix mt = new DenseRealMatrix(testData2T);
|
||||
@ -1027,13 +1027,13 @@ public final class DenseRealMatrixTest extends TestCase {
|
||||
RealMatrix m = new DenseRealMatrix(rows, columns);
|
||||
m.walkInRowOrder(new SetVisitor());
|
||||
GetVisitor getVisitor = new GetVisitor();
|
||||
m.walkInInternalOrder(getVisitor);
|
||||
m.walkInOptimizedOrder(getVisitor);
|
||||
assertEquals(rows * columns, getVisitor.getCount());
|
||||
|
||||
m = new DenseRealMatrix(rows, columns);
|
||||
m.walkInRowOrder(new SetVisitor(), 1, rows - 2, 1, columns - 2);
|
||||
getVisitor = new GetVisitor();
|
||||
m.walkInInternalOrder(getVisitor, 1, rows - 2, 1, columns - 2);
|
||||
m.walkInOptimizedOrder(getVisitor, 1, rows - 2, 1, columns - 2);
|
||||
assertEquals((rows - 2) * (columns - 2), getVisitor.getCount());
|
||||
for (int i = 0; i < rows; ++i) {
|
||||
assertEquals(0.0, m.getEntry(i, 0), 0);
|
||||
@ -1044,15 +1044,34 @@ public final class DenseRealMatrixTest extends TestCase {
|
||||
assertEquals(0.0, m.getEntry(rows - 1, j), 0);
|
||||
}
|
||||
|
||||
m = new DenseRealMatrix(rows, columns);
|
||||
m.walkInColumnOrder(new SetVisitor());
|
||||
getVisitor = new GetVisitor();
|
||||
m.walkInOptimizedOrder(getVisitor);
|
||||
assertEquals(rows * columns, getVisitor.getCount());
|
||||
|
||||
m = new DenseRealMatrix(rows, columns);
|
||||
m.walkInInternalOrder(new SetVisitor());
|
||||
m.walkInColumnOrder(new SetVisitor(), 1, rows - 2, 1, columns - 2);
|
||||
getVisitor = new GetVisitor();
|
||||
m.walkInOptimizedOrder(getVisitor, 1, rows - 2, 1, columns - 2);
|
||||
assertEquals((rows - 2) * (columns - 2), getVisitor.getCount());
|
||||
for (int i = 0; i < rows; ++i) {
|
||||
assertEquals(0.0, m.getEntry(i, 0), 0);
|
||||
assertEquals(0.0, m.getEntry(i, columns - 1), 0);
|
||||
}
|
||||
for (int j = 0; j < columns; ++j) {
|
||||
assertEquals(0.0, m.getEntry(0, j), 0);
|
||||
assertEquals(0.0, m.getEntry(rows - 1, j), 0);
|
||||
}
|
||||
|
||||
m = new DenseRealMatrix(rows, columns);
|
||||
m.walkInOptimizedOrder(new SetVisitor());
|
||||
getVisitor = new GetVisitor();
|
||||
m.walkInRowOrder(getVisitor);
|
||||
assertEquals(rows * columns, getVisitor.getCount());
|
||||
|
||||
m = new DenseRealMatrix(rows, columns);
|
||||
m.walkInInternalOrder(new SetVisitor(), 1, rows - 2, 1, columns - 2);
|
||||
m.walkInOptimizedOrder(new SetVisitor(), 1, rows - 2, 1, columns - 2);
|
||||
getVisitor = new GetVisitor();
|
||||
m.walkInRowOrder(getVisitor, 1, rows - 2, 1, columns - 2);
|
||||
assertEquals((rows - 2) * (columns - 2), getVisitor.getCount());
|
||||
@ -1065,18 +1084,47 @@ public final class DenseRealMatrixTest extends TestCase {
|
||||
assertEquals(0.0, m.getEntry(rows - 1, j), 0);
|
||||
}
|
||||
|
||||
m = new DenseRealMatrix(rows, columns);
|
||||
m.walkInOptimizedOrder(new SetVisitor());
|
||||
getVisitor = new GetVisitor();
|
||||
m.walkInColumnOrder(getVisitor);
|
||||
assertEquals(rows * columns, getVisitor.getCount());
|
||||
|
||||
m = new DenseRealMatrix(rows, columns);
|
||||
m.walkInOptimizedOrder(new SetVisitor(), 1, rows - 2, 1, columns - 2);
|
||||
getVisitor = new GetVisitor();
|
||||
m.walkInColumnOrder(getVisitor, 1, rows - 2, 1, columns - 2);
|
||||
assertEquals((rows - 2) * (columns - 2), getVisitor.getCount());
|
||||
for (int i = 0; i < rows; ++i) {
|
||||
assertEquals(0.0, m.getEntry(i, 0), 0);
|
||||
assertEquals(0.0, m.getEntry(i, columns - 1), 0);
|
||||
}
|
||||
for (int j = 0; j < columns; ++j) {
|
||||
assertEquals(0.0, m.getEntry(0, j), 0);
|
||||
assertEquals(0.0, m.getEntry(rows - 1, j), 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class SetVisitor implements RealMatrixChangingVisitor {
|
||||
private static final long serialVersionUID = -5724808764099124932L;
|
||||
public void start(int rows, int columns, int startRow, int endRow,
|
||||
int startColumn, int endColumn) {
|
||||
}
|
||||
public double visit(int i, int j, double value) {
|
||||
return i + j / 1024.0;
|
||||
}
|
||||
public double end() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private static class GetVisitor implements RealMatrixPreservingVisitor {
|
||||
private static final long serialVersionUID = 1299771253908695242L;
|
||||
int count = 0;
|
||||
public void start(int rows, int columns, int startRow, int endRow,
|
||||
int startColumn, int endColumn) {
|
||||
}
|
||||
public void visit(int i, int j, double value) {
|
||||
++count;
|
||||
assertEquals(i + j / 1024.0, value, 0.0);
|
||||
@ -1084,6 +1132,9 @@ public final class DenseRealMatrixTest extends TestCase {
|
||||
public int getCount() {
|
||||
return count;
|
||||
}
|
||||
public double end() {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
//--------------- -----------------Protected methods
|
||||
|
@ -813,13 +813,13 @@ public final class RealMatrixImplTest extends TestCase {
|
||||
RealMatrix m = new RealMatrixImpl(rows, columns);
|
||||
m.walkInRowOrder(new SetVisitor());
|
||||
GetVisitor getVisitor = new GetVisitor();
|
||||
m.walkInInternalOrder(getVisitor);
|
||||
m.walkInOptimizedOrder(getVisitor);
|
||||
assertEquals(rows * columns, getVisitor.getCount());
|
||||
|
||||
m = new RealMatrixImpl(rows, columns);
|
||||
m.walkInRowOrder(new SetVisitor(), 1, rows - 2, 1, columns - 2);
|
||||
getVisitor = new GetVisitor();
|
||||
m.walkInInternalOrder(getVisitor, 1, rows - 2, 1, columns - 2);
|
||||
m.walkInOptimizedOrder(getVisitor, 1, rows - 2, 1, columns - 2);
|
||||
assertEquals((rows - 2) * (columns - 2), getVisitor.getCount());
|
||||
for (int i = 0; i < rows; ++i) {
|
||||
assertEquals(0.0, m.getEntry(i, 0), 0);
|
||||
@ -830,15 +830,34 @@ public final class RealMatrixImplTest extends TestCase {
|
||||
assertEquals(0.0, m.getEntry(rows - 1, j), 0);
|
||||
}
|
||||
|
||||
m = new RealMatrixImpl(rows, columns);
|
||||
m.walkInColumnOrder(new SetVisitor());
|
||||
getVisitor = new GetVisitor();
|
||||
m.walkInOptimizedOrder(getVisitor);
|
||||
assertEquals(rows * columns, getVisitor.getCount());
|
||||
|
||||
m = new RealMatrixImpl(rows, columns);
|
||||
m.walkInInternalOrder(new SetVisitor());
|
||||
m.walkInColumnOrder(new SetVisitor(), 1, rows - 2, 1, columns - 2);
|
||||
getVisitor = new GetVisitor();
|
||||
m.walkInOptimizedOrder(getVisitor, 1, rows - 2, 1, columns - 2);
|
||||
assertEquals((rows - 2) * (columns - 2), getVisitor.getCount());
|
||||
for (int i = 0; i < rows; ++i) {
|
||||
assertEquals(0.0, m.getEntry(i, 0), 0);
|
||||
assertEquals(0.0, m.getEntry(i, columns - 1), 0);
|
||||
}
|
||||
for (int j = 0; j < columns; ++j) {
|
||||
assertEquals(0.0, m.getEntry(0, j), 0);
|
||||
assertEquals(0.0, m.getEntry(rows - 1, j), 0);
|
||||
}
|
||||
|
||||
m = new RealMatrixImpl(rows, columns);
|
||||
m.walkInOptimizedOrder(new SetVisitor());
|
||||
getVisitor = new GetVisitor();
|
||||
m.walkInRowOrder(getVisitor);
|
||||
assertEquals(rows * columns, getVisitor.getCount());
|
||||
|
||||
m = new RealMatrixImpl(rows, columns);
|
||||
m.walkInInternalOrder(new SetVisitor(), 1, rows - 2, 1, columns - 2);
|
||||
m.walkInOptimizedOrder(new SetVisitor(), 1, rows - 2, 1, columns - 2);
|
||||
getVisitor = new GetVisitor();
|
||||
m.walkInRowOrder(getVisitor, 1, rows - 2, 1, columns - 2);
|
||||
assertEquals((rows - 2) * (columns - 2), getVisitor.getCount());
|
||||
@ -851,18 +870,47 @@ public final class RealMatrixImplTest extends TestCase {
|
||||
assertEquals(0.0, m.getEntry(rows - 1, j), 0);
|
||||
}
|
||||
|
||||
m = new RealMatrixImpl(rows, columns);
|
||||
m.walkInOptimizedOrder(new SetVisitor());
|
||||
getVisitor = new GetVisitor();
|
||||
m.walkInColumnOrder(getVisitor);
|
||||
assertEquals(rows * columns, getVisitor.getCount());
|
||||
|
||||
m = new RealMatrixImpl(rows, columns);
|
||||
m.walkInOptimizedOrder(new SetVisitor(), 1, rows - 2, 1, columns - 2);
|
||||
getVisitor = new GetVisitor();
|
||||
m.walkInColumnOrder(getVisitor, 1, rows - 2, 1, columns - 2);
|
||||
assertEquals((rows - 2) * (columns - 2), getVisitor.getCount());
|
||||
for (int i = 0; i < rows; ++i) {
|
||||
assertEquals(0.0, m.getEntry(i, 0), 0);
|
||||
assertEquals(0.0, m.getEntry(i, columns - 1), 0);
|
||||
}
|
||||
for (int j = 0; j < columns; ++j) {
|
||||
assertEquals(0.0, m.getEntry(0, j), 0);
|
||||
assertEquals(0.0, m.getEntry(rows - 1, j), 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class SetVisitor implements RealMatrixChangingVisitor {
|
||||
private static final long serialVersionUID = -5724808764099124932L;
|
||||
public void start(int rows, int columns, int startRow, int endRow,
|
||||
int startColumn, int endColumn) {
|
||||
}
|
||||
public double visit(int i, int j, double value) {
|
||||
return i + j / 1024.0;
|
||||
}
|
||||
public double end() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private static class GetVisitor implements RealMatrixPreservingVisitor {
|
||||
private static final long serialVersionUID = 1299771253908695242L;
|
||||
int count = 0;
|
||||
public void start(int rows, int columns, int startRow, int endRow,
|
||||
int startColumn, int endColumn) {
|
||||
}
|
||||
public void visit(int i, int j, double value) {
|
||||
++count;
|
||||
assertEquals(i + j / 1024.0, value, 0.0);
|
||||
@ -870,6 +918,9 @@ public final class RealMatrixImplTest extends TestCase {
|
||||
public int getCount() {
|
||||
return count;
|
||||
}
|
||||
public double end() {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
//--------------- -----------------Protected methods
|
||||
|
Loading…
x
Reference in New Issue
Block a user