sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1522660 - in /sis/branches/JDK7/core/sis-referencing/src: main/java/org/apache/sis/referencing/operation/matrix/ test/java/org/apache/sis/referencing/operation/matrix/
Date Thu, 12 Sep 2013 16:47:00 GMT
Author: desruisseaux
Date: Thu Sep 12 16:47:00 2013
New Revision: 1522660

URL: http://svn.apache.org/r1522660
Log:
Added test cases.

Modified:
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/GeneralMatrix.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix2.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix3.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix4.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/MatrixSIS.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/NonSquareMatrix.java
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/Matrix1Test.java
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/Matrix2Test.java
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/Matrix3Test.java
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/Matrix4Test.java
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/MatrixTestCase.java

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/GeneralMatrix.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/GeneralMatrix.java?rev=1522660&r1=1522659&r2=1522660&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/GeneralMatrix.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/GeneralMatrix.java
[UTF-8] Thu Sep 12 16:47:00 2013
@@ -18,7 +18,6 @@ package org.apache.sis.referencing.opera
 
 import java.util.Arrays;
 import org.opengis.referencing.operation.Matrix;
-import org.apache.sis.util.resources.Errors;
 import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.math.MathFunctions;
 
@@ -289,14 +288,11 @@ class GeneralMatrix extends MatrixSIS {
      * {@inheritDoc}
      */
     @Override
-    public MatrixSIS multiply(final Matrix matrix) {
+    public final MatrixSIS multiply(final Matrix matrix) {
         final int numRow = this.numRow; // Protection against accidental changes.
         final int numCol = this.numCol;
         final int nc = matrix.getNumCol();
-        if (matrix.getNumRow() != numCol) {
-            throw new MismatchedMatrixSizeException(Errors.format(
-                    Errors.Keys.MismatchedMatrixSize_4, numCol, nc, matrix.getNumRow(), nc));
-        }
+        ensureNumRowMatch(numCol, matrix, nc);
         final MatrixSIS result = Matrices.createZero(numRow, nc);
         for (int j=0; j<numRow; j++) {
             final int srcOff = j * numCol;
@@ -319,7 +315,7 @@ class GeneralMatrix extends MatrixSIS {
      * @return {@code true} if the given object is equal to this matrix.
      */
     @Override
-    public boolean equals(final Object object) {
+    public final boolean equals(final Object object) {
         if (object instanceof GeneralMatrix) {
             final GeneralMatrix that = (GeneralMatrix) object;
             return numRow == that.numRow &&
@@ -333,7 +329,7 @@ class GeneralMatrix extends MatrixSIS {
      * Returns a hash code value based on the data values in this object.
      */
     @Override
-    public int hashCode() {
+    public final int hashCode() {
         return ((numRow << Short.SIZE) | numCol) ^ Arrays.hashCode(elements) ^ (int)
serialVersionUID;
     }
 

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix2.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix2.java?rev=1522660&r1=1522659&r2=1522660&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix2.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix2.java
[UTF-8] Thu Sep 12 16:47:00 2013
@@ -266,13 +266,12 @@ public final class Matrix2 extends Matri
      */
     @Override
     public MatrixSIS multiply(final Matrix matrix) {
-        final Matrix2 k;
-        if (matrix instanceof Matrix2) {
-            k = (Matrix2) matrix;
-        } else {
-            ensureSizeMatch(SIZE, matrix);
-            k = new Matrix2(matrix);
+        final int nc = matrix.getNumCol();
+        ensureNumRowMatch(SIZE, matrix, nc);
+        if (nc != SIZE) {
+            return new NonSquareMatrix(this, matrix);
         }
+        final Matrix2 k = (matrix instanceof Matrix2) ? (Matrix2) matrix : new Matrix2(matrix);
         return new Matrix2(m00 * k.m00  +  m01 * k.m10,
                            m00 * k.m01  +  m01 * k.m11,
                            m10 * k.m00  +  m11 * k.m10,

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix3.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix3.java?rev=1522660&r1=1522659&r2=1522660&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix3.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix3.java
[UTF-8] Thu Sep 12 16:47:00 2013
@@ -304,13 +304,12 @@ public final class Matrix3 extends Matri
      */
     @Override
     public MatrixSIS multiply(final Matrix matrix) {
-        final Matrix3 k;
-        if (matrix instanceof Matrix3) {
-            k = (Matrix3) matrix;
-        } else {
-            ensureSizeMatch(SIZE, matrix);
-            k = new Matrix3(matrix);
+        final int nc = matrix.getNumCol();
+        ensureNumRowMatch(SIZE, matrix, nc);
+        if (nc != SIZE) {
+            return new NonSquareMatrix(this, matrix);
         }
+        final Matrix3 k = (matrix instanceof Matrix3) ? (Matrix3) matrix : new Matrix3(matrix);
         return new Matrix3(m00 * k.m00  +  m01 * k.m10  +  m02 * k.m20,
                            m00 * k.m01  +  m01 * k.m11  +  m02 * k.m21,
                            m00 * k.m02  +  m01 * k.m12  +  m02 * k.m22,

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix4.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix4.java?rev=1522660&r1=1522659&r2=1522660&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix4.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix4.java
[UTF-8] Thu Sep 12 16:47:00 2013
@@ -355,13 +355,12 @@ public final class Matrix4 extends Matri
      */
     @Override
     public MatrixSIS multiply(final Matrix matrix) {
-        final Matrix4 k;
-        if (matrix instanceof Matrix4) {
-            k = (Matrix4) matrix;
-        } else {
-            ensureSizeMatch(SIZE, matrix);
-            k = new Matrix4(matrix);
+        final int nc = matrix.getNumCol();
+        ensureNumRowMatch(SIZE, matrix, nc);
+        if (nc != SIZE) {
+            return new NonSquareMatrix(this, matrix);
         }
+        final Matrix4 k = (matrix instanceof Matrix4) ? (Matrix4) matrix : new Matrix4(matrix);
         return new Matrix4(m00 * k.m00  +  m01 * k.m10  +  m02 * k.m20  +  m03 * k.m30,
                            m00 * k.m01  +  m01 * k.m11  +  m02 * k.m21  +  m03 * k.m31,
                            m00 * k.m02  +  m01 * k.m12  +  m02 * k.m22  +  m03 * k.m32,

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/MatrixSIS.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/MatrixSIS.java?rev=1522660&r1=1522659&r2=1522660&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/MatrixSIS.java
(original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/MatrixSIS.java
Thu Sep 12 16:47:00 2013
@@ -83,6 +83,24 @@ public abstract class MatrixSIS implemen
     }
 
     /**
+     * Ensures that the number of rows of the given matrix matches the given value.
+     * This is a convenience method for {@link #multiply(Matrix)} implementations.
+     *
+     * @param expected The expected number of rows.
+     * @param matrix   The matrix to verify.
+     * @param numCol   The number of columns to report in case of errors. This is an arbitrary
+     *                 value and have no incidence on the verification performed by this
method.
+     */
+    static void ensureNumRowMatch(final int expected, final Matrix matrix, final int numCol)
{
+        final int actual = matrix.getNumRow();
+        if (actual != expected) {
+            final Integer n = numCol;
+            throw new MismatchedMatrixSizeException(Errors.format(
+                    Errors.Keys.MismatchedMatrixSize_4, expected, n, actual, n));
+        }
+    }
+
+    /**
      * Returns an exception for the given indices.
      */
     static IndexOutOfBoundsException indexOutOfBounds(final int row, final int column) {

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/NonSquareMatrix.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/NonSquareMatrix.java?rev=1522660&r1=1522659&r2=1522660&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/NonSquareMatrix.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/NonSquareMatrix.java
[UTF-8] Thu Sep 12 16:47:00 2013
@@ -79,6 +79,28 @@ final class NonSquareMatrix extends Gene
     }
 
     /**
+     * Initializes this matrix to the product of the given matrices.
+     * This constructor shall be invoked only when the result is known to be a non-square
matrix.
+     */
+    NonSquareMatrix(final Matrix A, final Matrix B) {
+        super(A.getNumRow(), B.getNumCol(), false);
+        final int numRow = this.numRow; // Protection against accidental changes.
+        final int numCol = this.numCol;
+        final int common = A.getNumCol();
+        ensureNumRowMatch(common, B, numCol);
+        int offset = 0;
+        for (int j=0; j<numRow; j++) {
+            for (int i=0; i<numCol; i++) {
+                double sum = 0;
+                for (int k=0; k<common; k++) {
+                    sum += A.getElement(j, k) * B.getElement(k, i);
+                }
+                elements[offset++] = sum;
+            }
+        }
+    }
+
+    /**
      * Sets the value of this matrix to its transpose.
      */
     @Override

Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/Matrix1Test.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/Matrix1Test.java?rev=1522660&r1=1522659&r2=1522660&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/Matrix1Test.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/Matrix1Test.java
[UTF-8] Thu Sep 12 16:47:00 2013
@@ -53,7 +53,7 @@ public final strictfp class Matrix1Test 
      */
     @Test
     public void testConstructor() {
-        final double[] elements = createRandomElements(SIZE * SIZE);
+        final double[] elements = createRandomPositiveValues(SIZE * SIZE);
         final Matrix1 matrix = new Matrix1(
                 elements[0]);
         validate(matrix);

Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/Matrix2Test.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/Matrix2Test.java?rev=1522660&r1=1522659&r2=1522660&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/Matrix2Test.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/Matrix2Test.java
[UTF-8] Thu Sep 12 16:47:00 2013
@@ -53,7 +53,7 @@ public final strictfp class Matrix2Test 
      */
     @Test
     public void testConstructor() {
-        final double[] elements = createRandomElements(SIZE * SIZE);
+        final double[] elements = createRandomPositiveValues(SIZE * SIZE);
         final Matrix2 matrix = new Matrix2(
                 elements[0],
                 elements[1],

Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/Matrix3Test.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/Matrix3Test.java?rev=1522660&r1=1522659&r2=1522660&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/Matrix3Test.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/Matrix3Test.java
[UTF-8] Thu Sep 12 16:47:00 2013
@@ -54,7 +54,7 @@ public final strictfp class Matrix3Test 
      */
     @Test
     public void testConstructor() {
-        final double[] elements = createRandomElements(SIZE * SIZE);
+        final double[] elements = createRandomPositiveValues(SIZE * SIZE);
         final Matrix3 matrix = new Matrix3(
                 elements[0],
                 elements[1],

Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/Matrix4Test.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/Matrix4Test.java?rev=1522660&r1=1522659&r2=1522660&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/Matrix4Test.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/Matrix4Test.java
[UTF-8] Thu Sep 12 16:47:00 2013
@@ -54,7 +54,7 @@ public final strictfp class Matrix4Test 
      */
     @Test
     public void testConstructor() {
-        final double[] elements = createRandomElements(SIZE * SIZE);
+        final double[] elements = createRandomPositiveValues(SIZE * SIZE);
         final Matrix4 matrix = new Matrix4(
                 elements[ 0],
                 elements[ 1],

Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/MatrixTestCase.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/MatrixTestCase.java?rev=1522660&r1=1522659&r2=1522660&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/MatrixTestCase.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/MatrixTestCase.java
[UTF-8] Thu Sep 12 16:47:00 2013
@@ -54,6 +54,13 @@ public abstract strictfp class MatrixTes
     static final double STRICT = 0;
 
     /**
+     * Tolerance factor for comparisons of floating point numbers.
+     * The matrix elements used in this class varies between 0 and 100,
+     * and the {@code Math.ulp(100.0)} value is approximatively 1.4E-14.
+     */
+    static final double TOLERANCE = 1E-10;
+
+    /**
      * Random number generator, created by {@link #initialize(String, boolean)} when first
needed.
      */
     final Random random;
@@ -94,10 +101,11 @@ public abstract strictfp class MatrixTes
     }
 
     /**
-     * Creates an array of the given length filled with random values.
-     * This is a convenience method for the {@link testConstructor()} methods in {@code Matrix1…4Test}
subclasses.
+     * Creates an array of the given length filled with random values. All random values
are between 0 inclusive
+     * and 100 exclusive. This method never write negative values. Consequently, any strictly
negative value set
+     * by the test method is guaranteed to be different than all original values in the returned
array.
      */
-    final double[] createRandomElements(final int length) {
+    final double[] createRandomPositiveValues(final int length) {
         final double[] elements = new double[length];
         for (int k=0; k<length; k++) {
             elements[k] = random.nextDouble() * 100;
@@ -117,7 +125,7 @@ public abstract strictfp class MatrixTes
     public void testGetElements() {
         final int numRow = getNumRow();
         final int numCol = getNumCol();
-        final double[] elements = createRandomElements(numRow * numCol);
+        final double[] elements = createRandomPositiveValues(numRow * numCol);
         final MatrixSIS matrix = Matrices.create(numRow, numCol, elements);
         validate(matrix);
         /*
@@ -189,6 +197,34 @@ public abstract strictfp class MatrixTes
     }
 
     /**
+     * Tests {@link MatrixSIS#clone()}, {@link MatrixSIS#equals(Object)} and {@link MatrixSIS#hashCode()}.
+     */
+    @Test
+    @DependsOnMethod("testSetElement")
+    public void testCloneEquals() {
+        final int numRow = getNumRow();
+        final int numCol = getNumCol();
+        final double[] elements = createRandomPositiveValues(numRow * numCol);
+        final MatrixSIS matrix = Matrices.create(numRow, numCol, elements);
+        final MatrixSIS clone  = matrix.clone();
+        validate(matrix);
+        validate(clone);
+        assertNotSame("clone", matrix, clone);
+        assertEquals("equals", matrix, clone);
+        assertEquals("hashCode", matrix.hashCode(), clone.hashCode());
+        for (int j=0; j<numRow; j++) {
+            for (int i=0; i<numCol; i++) {
+                final double element = clone.getElement(j,i);
+                clone.setElement(j, i, random.nextDouble() - 2); // Negative value is guaranteed
to be different.
+                assertFalse(matrix.equals(clone));
+                assertFalse(clone.equals(matrix));
+                clone.setElement(j, i, element);
+            }
+        }
+        assertEquals("equals", matrix, clone);
+    }
+
+    /**
      * Tests {@link MatrixSIS#transpose()}.
      */
     @Test
@@ -196,7 +232,7 @@ public abstract strictfp class MatrixTes
     public void testTranspose() {
         final int numRow = getNumRow();
         final int numCol = getNumCol();
-        final double[] elements = createRandomElements(numRow * numCol);
+        final double[] elements = createRandomPositiveValues(numRow * numCol);
         final MatrixSIS matrix = Matrices.create(numRow, numCol, elements);
         validate(matrix);
         /*
@@ -206,4 +242,87 @@ public abstract strictfp class MatrixTes
         matrix.transpose();
         assertMatrixEquals(new Matrix(elements, numCol), matrix, STRICT);
     }
+
+    /**
+     * Tests {@link MatrixSIS#normalizeColumns()}.
+     */
+    @Test
+    @DependsOnMethod("testGetElements")
+    public void testNormalizeColumns() {
+        final int numRow = getNumRow();
+        final int numCol = getNumCol();
+        final double[] elements = createRandomPositiveValues(numRow * numCol);
+        final MatrixSIS matrix = Matrices.create(numRow, numCol, elements);
+        validate(matrix);
+        matrix.normalizeColumns();
+        for (int i=0; i<numCol; i++) {
+            double m = 0;
+            for (int j=0; j<numRow; j++) {
+                final double e = matrix.getElement(j, i);
+                m += e*e;
+            }
+            m = StrictMath.sqrt(m);
+            assertEquals(1, m, TOLERANCE);
+        }
+    }
+
+    /**
+     * Tests {@link MatrixSIS#multiply(Matrix)} with a matrix argument of size {@code numCol}
× {@code numRow}
+     * (i.e. the shape of a transposed matrix).
+     */
+    @Test
+    @DependsOnMethod("testGetElements")
+    public void testMultiplyByMatrix() {
+        final int numRow = getNumRow();
+        final int numCol = getNumCol();
+        final double[] elements = createRandomPositiveValues(numRow * numCol);
+        final MatrixSIS matrix = Matrices.create(numRow, numCol, elements);
+        final Matrix reference = new Matrix(elements, numCol).transpose();
+        /*
+         * Computes new random value for the argument. We mix positive and negative values,
+         * but with more positive values than negative ones in order to reduce the chances
+         * to have a product of zero for an element.
+         */
+        for (int k=0; k<elements.length; k++) {
+            elements[k] = 8 - random.nextDouble() * 10;
+        }
+        final MatrixSIS matrixArg = Matrices.create(numCol, numRow, elements);
+        final Matrix referenceArg = new Matrix(elements, numRow).transpose();
+        /*
+         * Performs the multiplication and compare.
+         */
+        final MatrixSIS matrixResult = matrix.multiply(matrixArg);
+        final Matrix referenceResult = reference.times(referenceArg);
+        assertMatrixEquals(referenceResult, matrixResult, TOLERANCE);
+    }
+
+    /**
+     * Tests {@link MatrixSIS#multiply(Matrix)} with a matrix argument of size {@code numCol}
× 1.
+     */
+    @Test
+    @DependsOnMethod("testMultiplyByMatrix")
+    public void testMultiplyByVector() {
+        final int numRow = getNumRow();
+        final int numCol = getNumCol();
+        double[] elements = createRandomPositiveValues(numRow * numCol);
+        final MatrixSIS matrix = Matrices.create(numRow, numCol, elements);
+        final Matrix reference = new Matrix(elements, numCol).transpose();
+        /*
+         * Computes new random value for the argument. We mix positive and negative values,
+         * but with more positive values than negative ones in order to reduce the chances
+         * to have a product of zero for an element.
+         */
+        elements = new double[numCol];
+        for (int k=0; k<numCol; k++) {
+            elements[k] = 8 - random.nextDouble() * 10;
+        }
+        final MatrixSIS matrixArg = Matrices.create(numCol, 1, elements);
+        final Matrix referenceArg = new Matrix(elements, numCol);
+        /*
+         * Performs the multiplication and compare.
+         */
+        final MatrixSIS matrixResult = matrix.multiply(matrixArg);
+        final Matrix referenceResult = reference.times(referenceArg);
+        assertMatrixEquals(referenceResult, matrixResult, TOLERANCE);
+    }
 }



Mime
View raw message