Skip to content

Commit

Permalink
MATH-1389: Performance improvement for Array2DRowRealMatrix.getSubMat…
Browse files Browse the repository at this point in the history
…rix()
  • Loading branch information
Christoph Dibak authored and ebourg committed Oct 12, 2016
1 parent f672e82 commit 72df12f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ If the output is not quite correct, check for invisible trailing spaces!
</release>

<release version="4.0" date="XXXX-XX-XX" description="">
<action dev="ebourg" type="update" issue="MATH-1389" due-to="Christoph Dibak">
Performance improvement for Array2DRowRealMatrix.getSubMatrix()
</action>
<action dev="erans" type="add" issue="MATH-1383">
Dependency toward the "Commons Rng" component.
</action>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,24 @@ public double[] preMultiply(final double[] v)

}

/** {@inheritDoc} */
@Override
public RealMatrix getSubMatrix(final int startRow, final int endRow,
final int startColumn, final int endColumn)
throws OutOfRangeException, NumberIsTooSmallException {
MatrixUtils.checkSubMatrixIndex(this, startRow, endRow, startColumn, endColumn);
final int rowCount = endRow - startRow + 1;
final int columnCount = endColumn - startColumn + 1;
final double[][] outData = new double[rowCount][columnCount];
for (int i = 0; i < rowCount; ++i) {
System.arraycopy(data[startRow + i], startColumn, outData[i], 0, columnCount);
}

Array2DRowRealMatrix subMatrix = new Array2DRowRealMatrix();
subMatrix.data = outData;
return subMatrix;
}

/** {@inheritDoc} */
@Override
public double walkInRowOrder(final RealMatrixChangingVisitor visitor) {
Expand Down

0 comments on commit 72df12f

Please sign in to comment.