You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2013/10/25 15:11:51 UTC

svn commit: r1535725 - /commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/EigenDecompositionTest.java

Author: erans
Date: Fri Oct 25 13:11:50 2013
New Revision: 1535725

URL: http://svn.apache.org/r1535725
Log:
MATH-1045
Added unit test (tiny eigenvalues).

Modified:
    commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/EigenDecompositionTest.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=1535725&r1=1535724&r2=1535725&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 25 13:11:50 2013
@@ -24,6 +24,7 @@ import java.util.Random;
 import org.apache.commons.math3.distribution.NormalDistribution;
 import org.apache.commons.math3.util.FastMath;
 import org.apache.commons.math3.util.Precision;
+import org.apache.commons.math3.util.MathArrays;
 import org.apache.commons.math3.exception.MathUnsupportedOperationException;
 import org.junit.After;
 import org.junit.Assert;
@@ -601,6 +602,28 @@ public class EigenDecompositionTest {
         double isqrt6 = 1/FastMath.sqrt(6.0);
         checkEigenVector((new double[] {2*isqrt6,-isqrt6,isqrt6}), ed, 1E-12);
     }
+
+    /**
+     * Verifies operation on very small values.
+     * Matrix with eigenvalues {2e-100, 0, 12e-100}
+     */
+    @Test
+    public void testTinyValues() {
+        final double tiny = 1e-100;
+        RealMatrix distinct = MatrixUtils.createRealMatrix(new double[][] {
+                {3, 1, -4},
+                {1, 3, -4},
+                {-4, -4, 8}
+        });
+        distinct = distinct.scalarMultiply(tiny);
+
+        final EigenDecomposition ed = new EigenDecomposition(distinct);
+        checkEigenValues(MathArrays.scale(tiny, new double[] {2, 0, 12}), ed, 1e-12 * tiny);
+        checkEigenVector(new double[] {1, -1, 0}, ed, 1e-12);
+        checkEigenVector(new double[] {1, 1, 1}, ed, 1e-12);
+        checkEigenVector(new double[] {-1, -1, 2}, ed, 1e-12);
+    }
+
     /**
      * Verifies that the given EigenDecomposition has eigenvalues equivalent to
      * the targetValues, ignoring the order of the values and allowing