[math] MATH-1389: Performance improvement for Array2DRowRealMatrix.getSubMatrix()
Repository: commons-math Updated Branches: refs/heads/MATH_3_X 61c53a4f5 -> dc256771c MATH-1389: Performance improvement for Array2DRowRealMatrix.getSubMatrix() Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/dc256771 Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/dc256771 Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/dc256771 Branch: refs/heads/MATH_3_X Commit: dc256771c2a81f7244115cc430a1685cf891803e Parents: 61c53a4 Author: Christoph Dibak Authored: Wed Oct 12 13:52:09 2016 +0200 Committer: Emmanuel Bourg Committed: Wed Oct 12 13:52:09 2016 +0200 -- src/changes/changes.xml | 3 +++ .../math3/linear/Array2DRowRealMatrix.java| 18 ++ 2 files changed, 21 insertions(+) -- http://git-wip-us.apache.org/repos/asf/commons-math/blob/dc256771/src/changes/changes.xml -- diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 0bc49aa..6901fef 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -51,6 +51,9 @@ If the output is not quite correct, check for invisible trailing spaces! + +Performance improvement for Array2DRowRealMatrix.getSubMatrix() + http://git-wip-us.apache.org/repos/asf/commons-math/blob/dc256771/src/main/java/org/apache/commons/math3/linear/Array2DRowRealMatrix.java -- diff --git a/src/main/java/org/apache/commons/math3/linear/Array2DRowRealMatrix.java b/src/main/java/org/apache/commons/math3/linear/Array2DRowRealMatrix.java index 6302cf3..5edda93 100644 --- a/src/main/java/org/apache/commons/math3/linear/Array2DRowRealMatrix.java +++ b/src/main/java/org/apache/commons/math3/linear/Array2DRowRealMatrix.java @@ -390,6 +390,24 @@ public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializ /** {@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) { final int rows= getRowDimension(); final int columns = getColumnDimension();
[math] MATH-1389: Performance improvement for Array2DRowRealMatrix.getSubMatrix()
Repository: commons-math Updated Branches: refs/heads/master f672e826f -> 72df12fb2 MATH-1389: Performance improvement for Array2DRowRealMatrix.getSubMatrix() Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/72df12fb Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/72df12fb Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/72df12fb Branch: refs/heads/master Commit: 72df12fb2ba453afb57cf185d25c502d4daec6d1 Parents: f672e82 Author: Christoph Dibak Authored: Wed Oct 12 12:41:45 2016 +0200 Committer: Emmanuel Bourg Committed: Wed Oct 12 12:41:45 2016 +0200 -- src/changes/changes.xml | 3 +++ .../math4/linear/Array2DRowRealMatrix.java| 18 ++ 2 files changed, 21 insertions(+) -- http://git-wip-us.apache.org/repos/asf/commons-math/blob/72df12fb/src/changes/changes.xml -- diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 1e43272..ac6d23a 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -54,6 +54,9 @@ If the output is not quite correct, check for invisible trailing spaces! + +Performance improvement for Array2DRowRealMatrix.getSubMatrix() + Dependency toward the "Commons Rng" component. http://git-wip-us.apache.org/repos/asf/commons-math/blob/72df12fb/src/main/java/org/apache/commons/math4/linear/Array2DRowRealMatrix.java -- diff --git a/src/main/java/org/apache/commons/math4/linear/Array2DRowRealMatrix.java b/src/main/java/org/apache/commons/math4/linear/Array2DRowRealMatrix.java index 3778db5..ed1ca9f 100644 --- a/src/main/java/org/apache/commons/math4/linear/Array2DRowRealMatrix.java +++ b/src/main/java/org/apache/commons/math4/linear/Array2DRowRealMatrix.java @@ -390,6 +390,24 @@ public class Array2DRowRealMatrix extends AbstractRealMatrix implements Serializ /** {@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) { final int rows= getRowDimension(); final int columns = getColumnDimension();