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 <christoph.di...@ipvs.uni-stuttgart.de>
Authored: Wed Oct 12 12:41:45 2016 +0200
Committer: Emmanuel Bourg <ebo...@apache.org>
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!
     </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>

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();

Reply via email to