sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1529183 - in /sis/branches/JDK7/core: sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/ sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/ sis-utility/src/main/java/org/apache/sis/util/resou...
Date Fri, 04 Oct 2013 15:20:25 GMT
Author: desruisseaux
Date: Fri Oct  4 15:20:24 2013
New Revision: 1529183

URL: http://svn.apache.org/r1529183
Log:
MatrixSIS.solve(...) delegate to Solver.

Modified:
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrices.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix1.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/Solver.java
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/MatrixTestCase.java
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/NonSquareMatrixTest.java
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/SolverTest.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrices.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrices.java?rev=1529183&r1=1529182&r2=1529183&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrices.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrices.java
[UTF-8] Fri Oct  4 15:20:24 2013
@@ -55,7 +55,8 @@ import java.util.Objects;
  *       {@link #isAffine   isAffine},
  *       {@link #isIdentity isIdentity},
  *       {@link #equals(Matrix, Matrix, double, boolean) equals},
- *       {@link #equals(Matrix, Matrix, ComparisonMode)  equals}.
+ *       {@link #equals(Matrix, Matrix, ComparisonMode)  equals},
+ *       {@link #toString(Matrix) toString}.
  *   </li>
  * </ul>
  *

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix1.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix1.java?rev=1529183&r1=1529182&r2=1529183&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix1.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix1.java
[UTF-8] Fri Oct  4 15:20:24 2013
@@ -238,26 +238,6 @@ public final class Matrix1 extends Matri
     }
 
     /**
-     * {@inheritDoc}
-     */
-    @Override
-    public MatrixSIS solve(final Matrix matrix) throws MismatchedMatrixSizeException, NoninvertibleMatrixException
{
-        final int nc = matrix.getNumCol();
-        ensureNumRowMatch(SIZE, matrix, nc);
-        if (m00 == 0) {
-            throw new NoninvertibleMatrixException();
-        }
-        if (nc != SIZE) {
-            final NonSquareMatrix m = new NonSquareMatrix(SIZE, nc, false, 1);
-            for (int i=0; i<nc; i++) {
-                m.elements[i] = matrix.getElement(0, i) / m00;
-            }
-            return m;
-        }
-        return new Matrix1(matrix.getElement(0,0) / m00);
-    }
-
-    /**
      * Returns {@code true} if the specified object is of type {@code Matrix1} and
      * all of the data members are equal to the corresponding data members in this matrix.
      *

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=1529183&r1=1529182&r2=1529183&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
Fri Oct  4 15:20:24 2013
@@ -94,9 +94,8 @@ public abstract class MatrixSIS implemen
     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));
+                    Errors.Keys.MismatchedMatrixSize_4, expected, "⒩", actual, numCol));
         }
     }
 
@@ -226,7 +225,7 @@ public abstract class MatrixSIS implemen
      * @throws NoninvertibleMatrixException if this matrix is not invertible.
      */
     public MatrixSIS solve(final Matrix matrix) throws MismatchedMatrixSizeException, NoninvertibleMatrixException
{
-        throw new UnsupportedOperationException(); // TODO
+        return Solver.solve(this, matrix);
     }
 
     /**

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Solver.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Solver.java?rev=1529183&r1=1529182&r2=1529183&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Solver.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Solver.java
[UTF-8] Fri Oct  4 15:20:24 2013
@@ -18,6 +18,7 @@ package org.apache.sis.referencing.opera
 
 import org.opengis.referencing.operation.Matrix;
 import org.apache.sis.internal.util.DoubleDouble;
+import org.apache.sis.util.resources.Errors;
 import org.apache.sis.util.ArraysExt;
 
 
@@ -97,11 +98,16 @@ final class Solver implements Matrix {
     }
 
     /**
-     * Computes the inverse of the given matrix. This method shall be invoked only for square
matrices
-     * (this is <strong>not</strong> verified by this method).
+     * Computes the inverse of the given matrix. This method shall be invoked only for square
matrices.
+     *
+     * @throws NoninvertibleMatrixException If the {@code X} matrix is not square or singular.
      */
     static MatrixSIS inverse(final MatrixSIS X) throws NoninvertibleMatrixException {
         final int size = X.getNumRow();
+        final int numCol = X.getNumCol();
+        if (numCol != size) {
+            throw new NoninvertibleMatrixException(Errors.format(Errors.Keys.NonInvertibleMatrix_2,
size, numCol));
+        }
         return solve(X, IDENTITY, null, size, size);
     }
 
@@ -109,28 +115,18 @@ final class Solver implements Matrix {
      * Solves {@code X} × <var>U</var> = {@code Y}.
      * This method is an adaptation of the {@code LUDecomposition} class of the JAMA matrix
package.
      *
-     * <p>This method does <strong>not</strong> checks the matrix size.
-     * Check for matrix size shall be performed by the caller like below:</p>
-     *
-     * {@preformat java
-     *     final int size = X.getNumRow();
-     *     if (X.getNumCol() != size) {
-     *         throw new NoninvertibleTransformException("Matrix must be square.");
-     *     }
-     *     if (Y.getNumRow() != size) {
-     *         throw new MismatchedMatrixSizeException("Matrix row dimensions must agree.");
-     *     }
-     * }
-     *
      * @param  X The matrix to invert.
      * @param  Y The desired result of {@code X} × <var>U</var>.
-     * @param  size The value of {@code X.getNumRow()}, {@code X.getNumCol()} and {@code
Y.getNumRow()}.
-     * @param  innerSize The value of {@code Y.getNumCol()}.
-     * @throws NoninvertibleMatrixException If the {@code X} matrix is singular.
+     * @throws NoninvertibleMatrixException If the {@code X} matrix is not square or singular.
      */
-    static MatrixSIS solve(final MatrixSIS X, final Matrix Y, final int size, final int innerSize)
-            throws NoninvertibleMatrixException
-    {
+    static MatrixSIS solve(final MatrixSIS X, final Matrix Y) throws NoninvertibleMatrixException
{
+        final int size = X.getNumRow();
+        final int numCol = X.getNumCol();
+        if (numCol != size) {
+            throw new NoninvertibleMatrixException(Errors.format(Errors.Keys.NonInvertibleMatrix_2,
size, numCol));
+        }
+        final int innerSize = Y.getNumCol();
+        GeneralMatrix.ensureNumRowMatch(size, Y, innerSize);
         double[] eltY = null;
         if (Y instanceof GeneralMatrix) {
             eltY = ((GeneralMatrix) Y).elements;
@@ -145,7 +141,25 @@ final class Solver implements Matrix {
      * Implementation of {@code solve} and {@code inverse} methods.
      * Use a "left-looking", dot-product, Crout/Doolittle algorithm.
      *
-     * @param eltY Elements and error terms of the {@code Y} matrix, or {@code null} if not
available.
+     * <p>This method does <strong>not</strong> checks the matrix size.
+     * Check for matrix size shall be performed by the caller like below:</p>
+     *
+     * {@preformat java
+     *     final int size = X.getNumRow();
+     *     if (X.getNumCol() != size) {
+     *         throw new NoninvertibleMatrixException("Matrix must be square.");
+     *     }
+     *     if (Y.getNumRow() != size) {
+     *         throw new MismatchedMatrixSizeException("Matrix row dimensions must agree.");
+     *     }
+     * }
+     *
+     * @param  X         The matrix to invert.
+     * @param  Y         The desired result of {@code X} × <var>U</var>.
+     * @param  eltY      Elements and error terms of the {@code Y} matrix, or {@code null}
if not available.
+     * @param  size      The value of {@code X.getNumRow()}, {@code X.getNumCol()} and {@code
Y.getNumRow()}.
+     * @param  innerSize The value of {@code Y.getNumCol()}.
+     * @throws NoninvertibleMatrixException If the {@code X} matrix is not square or singular.
      */
     private static MatrixSIS solve(final MatrixSIS X, final Matrix Y, final double[] eltY,
             final int size, final int innerSize) throws NoninvertibleMatrixException
@@ -242,7 +256,8 @@ final class Solver implements Matrix {
         for (int j=0; j<size; j++) {
             rat.setFrom(LU, j*size + j, errorLU);
             if (rat.isZero()) {
-                throw new NoninvertibleMatrixException();
+                final Integer n = size;
+                throw new NoninvertibleMatrixException(Errors.format(Errors.Keys.NonInvertibleMatrix_2,
n, n));
             }
         }
         /*

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=1529183&r1=1529182&r2=1529183&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] Fri Oct  4 15:20:24 2013
@@ -401,14 +401,11 @@ public abstract strictfp class MatrixTes
     @Test
     @DependsOnMethod("testMultiply")
     public void testSolve() throws NoninvertibleMatrixException {
-        initialize(2108474073121762244L);
+        initialize(2108474073121762243L);
         for (int n=0; n<NUMBER_OF_REPETITIONS; n++) {
             prepareNewMatrixSize(random);
             final int numRow = getNumRow();
             final int numCol = getNumCol();
-
-            if (numRow != 1 || numCol != 1) return; // Temporary limitation.
-
             double[] elements = createRandomPositiveValues(numRow * numCol);
             final Matrix reference = new Matrix(elements, numCol).transpose();
             if (!(reference.det() >= DETERMINANT_THRESHOLD)) {
@@ -432,7 +429,7 @@ public abstract strictfp class MatrixTes
              */
             final Matrix referenceResult = reference.solve(referenceArg);
             final MatrixSIS matrixResult = matrix.solve(matrixArg);
-            assertMatrixEquals(referenceResult, matrixResult, TOLERANCE);
+            assertMatrixEquals(referenceResult, matrixResult, SolverTest.TOLERANCE);
         }
     }
 

Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/NonSquareMatrixTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/NonSquareMatrixTest.java?rev=1529183&r1=1529182&r2=1529183&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/NonSquareMatrixTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/NonSquareMatrixTest.java
[UTF-8] Fri Oct  4 15:20:24 2013
@@ -81,6 +81,14 @@ public final strictfp class NonSquareMat
     }
 
     /**
+     * TODO: inverse transform not yet implemented for non-square matrix.
+     */
+    @Override
+    @org.junit.Ignore
+    public void testSolve() throws NoninvertibleMatrixException {
+    }
+
+    /**
      * Prints the statistics about the differences between JAMA and SIS matrix elements.
      * Those statistics will be visible only if {@link #verbose} is {@code true}.
      */

Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/SolverTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/SolverTest.java?rev=1529183&r1=1529182&r2=1529183&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/SolverTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/matrix/SolverTest.java
[UTF-8] Fri Oct  4 15:20:24 2013
@@ -109,7 +109,7 @@ public final strictfp class SolverTest e
                 out.println(e); // "Matrix is singular."
                 continue;
             }
-            final MatrixSIS U = Solver.solve(matrix, matrixArg, matrixArg.getNumRow(), matrixArg.getNumCol());
+            final MatrixSIS U = Solver.solve(matrix, matrixArg);
             MatrixTestCase.assertMatrixEquals(jama, U, TOLERANCE);
         }
     }

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java?rev=1529183&r1=1529182&r2=1529183&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.java
[UTF-8] Fri Oct  4 15:20:24 2013
@@ -456,6 +456,11 @@ public final class Errors extends Indexe
         public static final int NonInvertibleConversion = 82;
 
         /**
+         * Non invertible {0}×{1} matrix.
+         */
+        public static final int NonInvertibleMatrix_2 = 124;
+
+        /**
          * Transform is not invertible.
          */
         public static final int NonInvertibleTransform = 83;

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties?rev=1529183&r1=1529182&r2=1529183&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
[ISO-8859-1] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors.properties
[ISO-8859-1] Fri Oct  4 15:20:24 2013
@@ -98,6 +98,7 @@ NodeIsLeaf_1                    = Node \
 NodeNotFound_1                  = No \u201c{0}\u201d node found.
 NonEquilibratedParenthesis_2    = Missing a \u2018{1}\u2019 parenthesis in \u201c{0}\u201d.
 NonInvertibleConversion         = Conversion is not invertible.
+NonInvertibleMatrix_2           = Non invertible {0}\u00d7{1} matrix.
 NonInvertibleTransform          = Transform is not invertible.
 NonAngularUnit_1                = \u201c{0}\u201d is not an angular unit.
 NonLinearUnit_1                 = \u201c{0}\u201d is not a linear unit.

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties?rev=1529183&r1=1529182&r2=1529183&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
[ISO-8859-1] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/resources/Errors_fr.properties
[ISO-8859-1] Fri Oct  4 15:20:24 2013
@@ -88,6 +88,7 @@ NodeIsLeaf_1                    = Le n\u
 NodeNotFound_1                  = Aucun n\u0153ud \u201c{0}\u201d n\u2019a \u00e9t\u00e9
trouv\u00e9.
 NonEquilibratedParenthesis_2    = Il manque une parenth\u00e8se \u2018{1}\u2019 dans \u201c{0}\u201d.
 NonInvertibleConversion         = La conversion n\u2019est pas inversible.
+NonInvertibleMatrix_2           = Matrice {0}\u00d7{1} non inversible.
 NonInvertibleTransform          = La transformation n\u2019est pas inversible.
 NonAngularUnit_1                = \u201c{0}\u201d n\u2019est pas une unit\u00e9 d\u2019angles.
 NonLinearUnit_1                 = \u201c{0}\u201d n\u2019est pas une unit\u00e9 de longueurs.



Mime
View raw message