sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1528428 - in /sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix: GeneralMatrix.java NonSquareMatrix.java
Date Wed, 02 Oct 2013 11:17:36 GMT
Author: desruisseaux
Date: Wed Oct  2 11:17:36 2013
New Revision: 1528428

URL: http://svn.apache.org/r1528428
Log:
Set error terms to "inferred" values, and stricter check for the error terms in isAffine()
and isIdentity().

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/NonSquareMatrix.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=1528428&r1=1528427&r2=1528428&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] Wed Oct  2 11:17:36 2013
@@ -105,6 +105,7 @@ class GeneralMatrix extends MatrixSIS {
         this.numRow = (short) numRow;
         this.numCol = (short) numCol;
         this.elements = Arrays.copyOf(elements, length * precision);
+        inferErrors();
     }
 
     /**
@@ -126,6 +127,7 @@ class GeneralMatrix extends MatrixSIS {
                 elements[k++] = matrix.getElement(j, i);
             }
         }
+        inferErrors();
     }
 
     /**
@@ -138,6 +140,19 @@ class GeneralMatrix extends MatrixSIS {
     }
 
     /**
+     * Infers all {@link DoubleDouble#error} with a default values inferred from {@link DoubleDouble#value}.
+     * For example if a matrix element is exactly 3.141592653589793, there is good chances
that the user's
+     * intend was to specify the {@link Math#PI} value, in which case this method will infer
that we would
+     * need to add 1.2246467991473532E-16 in order to get a value closer to π.
+     */
+    private void inferErrors() {
+        final int length = numRow * numCol;
+        for (int i=length; i<elements.length; i++) {
+            elements[i] = DoubleDouble.errorForWellKnownValue(elements[i - length]);
+        }
+    }
+
+    /**
      * Ensures that the given matrix size is valid for this {@code GeneralMatrix} implementation.
      */
     private static void ensureValidSize(final int numRow, final int numCol) {
@@ -187,7 +202,12 @@ class GeneralMatrix extends MatrixSIS {
     @Override
     public final void setElement(final int row, final int column, final double value) {
         if (row >= 0 && row < numRow && column >= 0 && column
< numCol) {
-            elements[row * numCol + column] = value;
+            int i = row * numCol + column;
+            elements[i] = value;
+            i += numRow * numCol;
+            if (i < elements.length) {
+                elements[i] = DoubleDouble.errorForWellKnownValue(value);
+            }
         } else {
             throw indexOutOfBounds(row, column);
         }
@@ -208,13 +228,11 @@ class GeneralMatrix extends MatrixSIS {
     public final void setElements(final double[] elements) {
         ensureLengthMatch(numRow*numCol, elements);
         System.arraycopy(elements, 0, this.elements, 0, elements.length);
+        inferErrors();
     }
 
     /**
      * {@inheritDoc}
-     *
-     * <p>If this matrix has extended precision, then the {@link DoubleDouble#error}
values are ignored.
-     * Only the values representable as a {@code double} are verified.</p>
      */
     @Override
     public final boolean isAffine() {
@@ -229,6 +247,15 @@ class GeneralMatrix extends MatrixSIS {
                         return false;
                     }
                 }
+                /*
+                 * At this point, the 'double' values are those of an affine transform.
+                 * If this matrix uses extended precision, ensures that their errors are
zero.
+                 */
+                for (i = base + numRow*numCol; i < elements.length; i++) {
+                    if (elements[i] != 0) {
+                        return false;
+                    }
+                }
                 return true;
             }
         }
@@ -237,9 +264,6 @@ class GeneralMatrix extends MatrixSIS {
 
     /**
      * {@inheritDoc}
-     *
-     * <p>If this matrix has extended precision, then the {@link DoubleDouble#error}
values are ignored.
-     * Only the values representable as a {@code double} are verified.</p>
      */
     @Override
     public final boolean isIdentity() {
@@ -259,6 +283,15 @@ class GeneralMatrix extends MatrixSIS {
                 if (element != 0) return false;
             }
         }
+        /*
+         * At this point, the 'double' values are those of an identity transform.
+         * If this matrix uses extended precision, ensures that all errors are zero.
+         */
+        for (int i=length; i<elements.length; i++) {
+            if (elements[i] != 0) {
+                return false;
+            }
+        }
         return true;
     }
 
@@ -272,7 +305,7 @@ class GeneralMatrix extends MatrixSIS {
     public void transpose() {
         final int numRow = this.numRow; // Protection against accidental changes.
         final int numCol = this.numCol;
-        final int errors = (numRow * numCol) % elements.length;
+        final int errors = (numRow * numCol) % elements.length; // Where error values start,
or 0 if none.
         for (int j=0; j<numRow; j++) {
             for (int i=0; i<j; i++) {
                 final int lo = j*numCol + i;
@@ -288,6 +321,8 @@ class GeneralMatrix extends MatrixSIS {
 
     /**
      * {@inheritDoc}
+     *
+     * <p>The current implementation discards the extended precision, if any.</p>
      */
     @Override
     public final void normalizeColumns() {
@@ -303,6 +338,7 @@ class GeneralMatrix extends MatrixSIS {
                 elements[j*numCol + i] /= m;
             }
         }
+        Arrays.fill(elements, numRow * numCol, elements.length, 0);
     }
 
     /**

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=1528428&r1=1528427&r2=1528428&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] Wed Oct  2 11:17:36 2013
@@ -110,7 +110,7 @@ final class NonSquareMatrix extends Gene
     public void transpose() {
         final short numRow = this.numRow; // Protection against accidental changes before
we are done.
         final short numCol = this.numCol;
-        final int   errors = (numRow * numCol) % elements.length;
+        final int   errors = (numRow * numCol) % elements.length; // Where error values start,
or 0 if none.
         final double[] copy = elements.clone();
         int k = 0;
         for (int j=0; j<numRow; j++) {



Mime
View raw message