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 <christoph.di...@ipvs.uni-stuttgart.de>
Authored: Wed Oct 12 13:52:09 2016 +0200
Committer: Emmanuel Bourg <ebo...@apache.org>
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!
   </properties>
   <body>
     <release version="TBD" date="TBD" description="TBD">
+      <action dev="ebourg" type="update" issue="MATH-1389" due-to="Christoph 
Dibak">
+        Performance improvement for Array2DRowRealMatrix.getSubMatrix()
+      </action>
     </release>
     <release version="3.6.1" date="2016-03-21" description="
 This is a minor bug fix release. It incorporates three bug fixes since version 
3.6.

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

Reply via email to