Repository: commons-math
Updated Branches:
  refs/heads/master 7a7b39052 -> ed1ce82d8


MATH-1417: Incorrect loop start.

Thanks to Jean-François Lecomte for the report and the fix.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/ed1ce82d
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/ed1ce82d
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/ed1ce82d

Branch: refs/heads/master
Commit: ed1ce82d822ffe185875b7b7d38352f20171c096
Parents: 7a7b390
Author: Gilles <[email protected]>
Authored: Tue May 9 21:31:24 2017 +0200
Committer: Gilles <[email protected]>
Committed: Tue May 9 21:31:24 2017 +0200

----------------------------------------------------------------------
 src/changes/changes.xml                           |  3 +++
 .../commons/math4/linear/RRQRDecomposition.java   |  7 +++----
 .../math4/linear/RRQRDecompositionTest.java       | 18 ++++++++++++++++++
 3 files changed, 24 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/ed1ce82d/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 1b75585..622b449 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="erans" type="fix" issue="MATH-1417" due-to="Jean-Francois 
Lecomte">
+        "RRQRDecomposition": bug in method "performHouseholderReflection".
+      </action>
       <action dev="kinow" type="fix" issue="MATH-1381" due-to="Kexin Xie">
         BinomialTest P-value > 1
       </action>

http://git-wip-us.apache.org/repos/asf/commons-math/blob/ed1ce82d/src/main/java/org/apache/commons/math4/linear/RRQRDecomposition.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/commons/math4/linear/RRQRDecomposition.java 
b/src/main/java/org/apache/commons/math4/linear/RRQRDecomposition.java
index 9f41ea6..261ba09 100644
--- a/src/main/java/org/apache/commons/math4/linear/RRQRDecomposition.java
+++ b/src/main/java/org/apache/commons/math4/linear/RRQRDecomposition.java
@@ -68,7 +68,7 @@ public class RRQRDecomposition extends QRDecomposition {
         this(matrix, 0d);
     }
 
-   /**
+    /**
      * Calculates the QR-decomposition of the given matrix.
      *
      * @param matrix The matrix to decompose.
@@ -92,18 +92,18 @@ public class RRQRDecomposition extends QRDecomposition {
     }
 
     /** Perform Householder reflection for a minor A(minor, minor) of A.
+     *
      * @param minor minor index
      * @param qrt transposed matrix
      */
     @Override
     protected void performHouseholderReflection(int minor, double[][] qrt) {
-
         double l2NormSquaredMax = 0;
         // Find the unreduced column with the greatest L2-Norm
         int l2NormSquaredMaxIndex = minor;
         for (int i = minor; i < qrt.length; i++) {
             double l2NormSquared = 0;
-            for (int j = 0; j < qrt[i].length; j++) {
+            for (int j = minor; j < qrt[i].length; j++) {
                 l2NormSquared += qrt[i][j] * qrt[i][j];
             }
             if (l2NormSquared > l2NormSquaredMax) {
@@ -122,7 +122,6 @@ public class RRQRDecomposition extends QRDecomposition {
         }
 
         super.performHouseholderReflection(minor, qrt);
-
     }
 
 

http://git-wip-us.apache.org/repos/asf/commons-math/blob/ed1ce82d/src/test/java/org/apache/commons/math4/linear/RRQRDecompositionTest.java
----------------------------------------------------------------------
diff --git 
a/src/test/java/org/apache/commons/math4/linear/RRQRDecompositionTest.java 
b/src/test/java/org/apache/commons/math4/linear/RRQRDecompositionTest.java
index 01acaae..c2e9c33 100644
--- a/src/test/java/org/apache/commons/math4/linear/RRQRDecompositionTest.java
+++ b/src/test/java/org/apache/commons/math4/linear/RRQRDecompositionTest.java
@@ -244,4 +244,22 @@ public class RRQRDecompositionTest {
         RRQRDecomposition qr = new RRQRDecomposition(m);
         Assert.assertEquals(2, qr.getRank(1e-14));
     }
+
+    // MATH-1417
+    @Test
+    public void testRank3() {
+        double[][] d = {
+            {0, 0, 0, 0, 0, 0, 0, 0, 0},
+            {0, 1, 0, 0, 0, 0, 0, 0, 0},
+            {0, 0, 1, 0, 0, 0, 0, 0, 0},
+            {0, 0, 1, 0, 0, 0, 0, 0, 0},
+            {0, 0, 1, 0, 0, 0, 0, 0, 0},
+            {0, 0, 0, 1, 0, 0, 0, 0, 0},
+            {0, 0, 0, 0, 0, 0, 1, 0, 0},
+            {0, 0, 0, 0, 0, 0, 0, 0, 0}
+        };
+        RealMatrix m = new Array2DRowRealMatrix(d);
+        RRQRDecomposition qr = new RRQRDecomposition(m.transpose());
+        Assert.assertEquals(4, qr.getRank(1e-14));
+    }
 }

Reply via email to