commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From er...@apache.org
Subject svn commit: r1402716 - in /commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear: EigenDecompositionTest.java SingularValueDecompositionTest.java
Date Fri, 26 Oct 2012 23:37:32 GMT
Author: erans
Date: Fri Oct 26 23:37:32 2012
New Revision: 1402716

URL: http://svn.apache.org/viewvc?rev=1402716&view=rev
Log:
Removed quasi-duplicate code.

Modified:
    commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/EigenDecompositionTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/SingularValueDecompositionTest.java

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/EigenDecompositionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/EigenDecompositionTest.java?rev=1402716&r1=1402715&r2=1402716&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/EigenDecompositionTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/EigenDecompositionTest.java
Fri Oct 26 23:37:32 2012
@@ -488,7 +488,7 @@ public class EigenDecompositionTest {
     @Test
     public void testDiagonal() {
         double[] diagonal = new double[] { -3.0, -2.0, 2.0, 5.0 };
-        RealMatrix m = createDiagonalMatrix(diagonal, diagonal.length, diagonal.length);
+        RealMatrix m = MatrixUtils.createRealDiagonalMatrix(diagonal);
         EigenDecomposition ed;
         ed = new EigenDecomposition(m);
         Assert.assertEquals(diagonal[0], ed.getRealEigenvalue(3), 2.0e-15);
@@ -640,7 +640,7 @@ public class EigenDecompositionTest {
     static RealMatrix createTestMatrix(final Random r, final double[] eigenValues) {
         final int n = eigenValues.length;
         final RealMatrix v = createOrthogonalMatrix(r, n);
-        final RealMatrix d = createDiagonalMatrix(eigenValues, n, n);
+        final RealMatrix d = MatrixUtils.createRealDiagonalMatrix(eigenValues);
         return v.multiply(d).multiply(v.transpose());
     }
 
@@ -686,14 +686,4 @@ public class EigenDecompositionTest {
         return MatrixUtils.createRealMatrix(data);
 
     }
-
-    public static RealMatrix createDiagonalMatrix(final double[] diagonal,
-                                                  final int rows, final int columns) {
-        final double[][] dData = new double[rows][columns];
-        for (int i = 0; i < FastMath.min(rows, columns); ++i) {
-            dData[i][i] = diagonal[i];
-        }
-        return MatrixUtils.createRealMatrix(dData);
-    }
-
 }

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/SingularValueDecompositionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/SingularValueDecompositionTest.java?rev=1402716&r1=1402715&r2=1402716&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/SingularValueDecompositionTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/SingularValueDecompositionTest.java
Fri Oct 26 23:37:32 2012
@@ -307,12 +307,10 @@ public class SingularValueDecompositionT
 
     private RealMatrix createTestMatrix(final Random r, final int rows, final int columns,
                                         final double[] singularValues) {
-        final RealMatrix u =
-            EigenDecompositionTest.createOrthogonalMatrix(r, rows);
-        final RealMatrix d =
-            EigenDecompositionTest.createDiagonalMatrix(singularValues, rows, columns);
-        final RealMatrix v =
-            EigenDecompositionTest.createOrthogonalMatrix(r, columns);
+        final RealMatrix u = EigenDecompositionTest.createOrthogonalMatrix(r, rows);
+        final RealMatrix d = new Array2DRowRealMatrix(rows, columns);
+        d.setSubMatrix(MatrixUtils.createRealDiagonalMatrix(singularValues).getData(), 0,
0);
+        final RealMatrix v = EigenDecompositionTest.createOrthogonalMatrix(r, columns);
         return u.multiply(d).multiply(v);
     }
 



Mime
View raw message