commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From celes...@apache.org
Subject svn commit: r1354330 - /commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java
Date Wed, 27 Jun 2012 05:53:09 GMT
Author: celestin
Date: Wed Jun 27 05:53:09 2012
New Revision: 1354330

URL: http://svn.apache.org/viewvc?rev=1354330&view=rev
Log:
MATH-795: factored out unit test of
RealMatrix RealVector.outerProduct(RealVector)
This test fails with the default implementation provided by the abstract class RealMatrix.

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

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java?rev=1354330&r1=1354329&r2=1354330&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java
Wed Jun 27 05:53:09 2012
@@ -924,6 +924,45 @@ public abstract class RealVectorAbstract
         }
     }
 
+    private void doTestOuterProduct(final boolean mixed) {
+        final double[] dataU = values;
+        final RealVector u = create(dataU);
+        final double[] dataV = new double[values.length + 3];
+        System.arraycopy(values, 0, dataV, 0, values.length);
+        dataV[values.length] = 1d;
+        dataV[values.length] = -2d;
+        dataV[values.length] = 3d;
+        final RealVector v;
+        if (mixed) {
+            v = createAlien(dataV);
+        } else {
+            v = create(dataV);
+        }
+        final RealMatrix uv = u.outerProduct(v);
+        Assert.assertEquals("number of rows", dataU.length, uv
+            .getRowDimension());
+        Assert.assertEquals("number of columns", dataV.length, uv
+            .getColumnDimension());
+        for (int i = 0; i < dataU.length; i++) {
+            for (int j = 0; j < dataV.length; j++) {
+                final double expected = dataU[i] * dataV[j];
+                final double actual = uv.getEntry(i, j);
+                Assert.assertEquals("[" + i + "][" + j + "]", expected, actual,
+                    0d);
+            }
+        }
+    }
+
+    @Test
+    public void testOuterProductSameType() {
+        doTestOuterProduct(false);
+    }
+
+    @Test
+    public void testOuterProductMixedTypes() {
+        doTestOuterProduct(true);
+    }
+
     @Test
     public void testDataInOut() {
         final RealVector v1 = create(vec1);
@@ -998,14 +1037,6 @@ public abstract class RealVectorAbstract
         double dot_2 = v1.dotProduct(v2_t);
         Assert.assertEquals("compare val ", 32d, dot_2, normTolerance);
 
-        RealMatrix m_outerProduct = v1.outerProduct(v2);
-        Assert.assertEquals("compare val ", 4d, m_outerProduct.getEntry(0, 0),
-                            normTolerance);
-
-        RealMatrix m_outerProduct_2 = v1.outerProduct(v2_t);
-        Assert.assertEquals("compare val ", 4d,
-                            m_outerProduct_2.getEntry(0, 0), normTolerance);
-
         RealVector v_unitVector = v1.unitVector();
         RealVector v_unitVector_2 = v1.mapDivide(v1.getNorm());
         assertClose("compare vect", v_unitVector.toArray(),
@@ -1038,22 +1069,6 @@ public abstract class RealVectorAbstract
     }
 
     @Test
-    public void testOuterProduct() {
-        final RealVector u = create(new double[] {1, 2, -3});
-        final RealVector v = create(new double[] {4, -2});
-
-        final RealMatrix uv = u.outerProduct(v);
-
-        final double tol = Math.ulp(1d);
-        Assert.assertEquals(4, uv.getEntry(0, 0), tol);
-        Assert.assertEquals(-2, uv.getEntry(0, 1), tol);
-        Assert.assertEquals(8, uv.getEntry(1, 0), tol);
-        Assert.assertEquals(-4, uv.getEntry(1, 1), tol);
-        Assert.assertEquals(-12, uv.getEntry(2, 0), tol);
-        Assert.assertEquals(6, uv.getEntry(2, 1), tol);
-    }
-
-    @Test
     public void testMisc() {
         RealVector v1 = create(vec1);
         RealVector v4 = create(vec4);



Mime
View raw message