sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1736900 - in /sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis: internal/referencing/j2d/ referencing/operation/matrix/
Date Mon, 28 Mar 2016 15:38:54 GMT
Author: desruisseaux
Date: Mon Mar 28 15:38:54 2016
New Revision: 1736900

URL: http://svn.apache.org/viewvc?rev=1736900&view=rev
Log:
Fix a lost of precision in UnmodifiableMatrix.
Opportunistic formatting fixes while debugging.

Modified:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/j2d/AffineTransform2D.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/GeneralMatrix.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Solver.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/UnmodifiableMatrix.java

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/j2d/AffineTransform2D.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/j2d/AffineTransform2D.java?rev=1736900&r1=1736899&r2=1736900&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/j2d/AffineTransform2D.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/j2d/AffineTransform2D.java
[UTF-8] Mon Mar 28 15:38:54 2016
@@ -312,7 +312,7 @@ public class AffineTransform2D extends I
                     final AffineTransform2D work = new AffineTransform2D(
                             ((ExtendedPrecisionMatrix) Matrices.inverse(matrix)).getExtendedElements());
                     work.inverse = this;
-                    inverse = work; // Set only on success.
+                    inverse = work;                 // Set only on success.
                 }
             }
         }
@@ -332,7 +332,7 @@ public class AffineTransform2D extends I
      */
     @Override
     public boolean equals(final Object object, final ComparisonMode mode) {
-        if (object == this) { // Slight optimization
+        if (object == this) {                       // Slight optimization
             return true;
         }
         if (mode == ComparisonMode.STRICT) {

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/GeneralMatrix.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/GeneralMatrix.java?rev=1736900&r1=1736899&r2=1736900&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/GeneralMatrix.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/GeneralMatrix.java
[UTF-8] Mon Mar 28 15:38:54 2016
@@ -594,7 +594,7 @@ class GeneralMatrix extends MatrixSIS im
          */
         final double[] eltA   = getExtendedElements(A, numRow, nc, false);
         final double[] eltB   = getExtendedElements(B, nc, numCol, false);
-        final int errorOffset = numRow * numCol; // Where error terms start.
+        final int errorOffset = numRow * numCol;            // Where error terms start.
         final int errA        = numRow * nc;
         final int errB        = nc * numCol;
         /*

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Solver.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Solver.java?rev=1736900&r1=1736899&r2=1736900&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Solver.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Solver.java
[UTF-8] Mon Mar 28 15:38:54 2016
@@ -38,7 +38,7 @@ import org.apache.sis.util.ArraysExt;
  * @module
  */
 @SuppressWarnings("CloneInNonCloneableClass")
-final class Solver implements Matrix { // Not Cloneable, despite the clone() method.
+final class Solver implements Matrix {                          // Not Cloneable, despite
the clone() method.
     /**
      * The size of the (i, j, s) tuples used internally by {@link #solve(Matrix, Matrix,
double[], int, int)}
      * for storing information about the NaN values.
@@ -143,7 +143,7 @@ final class Solver implements Matrix { /
         if (Y instanceof GeneralMatrix) {
             eltY = ((GeneralMatrix) Y).elements;
             if (eltY.length == size * innerSize) {
-                eltY = null; // Matrix does not contains error terms.
+                eltY = null;                            // Matrix does not contains error
terms.
             }
         }
         return solve(X, Y, eltY, size, innerSize, true);
@@ -248,7 +248,7 @@ searchNaN:  for (int flatIndex = (size -
                     }
                     indexOfNaN[indexCount++] = i;
                     indexOfNaN[indexCount++] = j;
-                    indexOfNaN[indexCount++] = columnOfScale; // May be -1 (while uncommon)
+                    indexOfNaN[indexCount++] = columnOfScale;                   // May be
-1 (while uncommon)
                     assert (indexCount % TUPLE_SIZE) == 0;
                 }
             }
@@ -262,7 +262,7 @@ searchNaN:  for (int flatIndex = (size -
                 final int j = indexOfNaN[k+1];
                 final int flatIndex = j*size + i;
                 LU[flatIndex] = (i == lastRowOrColumn) ? 0 : 1;
-                LU[flatIndex + size*size] = 0; // Error term (see 'errorLU') in next method.
+                LU[flatIndex + size*size] = 0;                      // Error term (see 'errorLU')
in next method.
             }
         }
         /*
@@ -280,9 +280,9 @@ searchNaN:  for (int flatIndex = (size -
             final int s = indexOfNaN[k++];
             if (i != lastRowOrColumn) {
                 // Found a scale factor to set to NaN.
-                matrix.setElement(i, j, Double.NaN); // Note that i,j indices are interchanged.
+                matrix.setElement(i, j, Double.NaN);                      // Note that i,j
indices are interchanged.
                 if (matrix.getElement(i, lastRowOrColumn) != 0) {
-                    matrix.setElement(i, lastRowOrColumn, Double.NaN); // = -offset/scale,
so 0 stay 0.
+                    matrix.setElement(i, lastRowOrColumn, Double.NaN);    // = -offset/scale,
so 0 stay 0.
                 }
             } else if (s >= 0) {
                 // Found a translation factory to set to NaN.
@@ -323,17 +323,17 @@ searchNaN:  for (int flatIndex = (size -
         for (int j=0; j<size; j++) {
            pivot[j] = j;
         }
-        final double[]  column = new double[size * 2]; // [0 … size-1] : column values;
[size … 2*size-1] : error terms.
-        final DoubleDouble acc = new DoubleDouble();   // Temporary variable for sum ("accumulator")
and subtraction.
-        final DoubleDouble rat = new DoubleDouble();   // Temporary variable for products
and ratios.
+        final double[]  column = new double[size * 2];  // [0 … size-1] : column values;
[size … 2*size-1] : error terms.
+        final DoubleDouble acc = new DoubleDouble();    // Temporary variable for sum ("accumulator")
and subtraction.
+        final DoubleDouble rat = new DoubleDouble();    // Temporary variable for products
and ratios.
         for (int i=0; i<size; i++) {
             /*
              * Make a copy of the i-th column.
              */
             for (int j=0; j<size; j++) {
                 final int k = j*size + i;
-                column[j]        = LU[k];            // Value
-                column[j + size] = LU[k + errorLU];  // Error
+                column[j]        = LU[k];               // Value
+                column[j + size] = LU[k + errorLU];     // Error
             }
             /*
              * Apply previous transformations. This part is equivalent to the following code,
@@ -372,7 +372,7 @@ searchNaN:  for (int flatIndex = (size -
             if (p != i) {
                 final int pRow = p*size;
                 final int iRow = i*size;
-                for (int k=0; k<size; k++) { // Swap two full rows.
+                for (int k=0; k<size; k++) {                                // Swap two
full rows.
                     DoubleDouble.swap(LU, pRow + k, iRow + k, errorLU);
                 }
                 ArraysExt.swap(pivot, p, i);
@@ -435,10 +435,10 @@ searchNaN:  for (int flatIndex = (size -
          *     elements[loRowOffset + i] -= (elements[rowOffset + i] * LU[luRowOffset + k]);
          */
         for (int k=0; k<size; k++) {
-            final int rowOffset = k*innerSize;          // Offset of row computed by current
iteration.
+            final int rowOffset = k*innerSize;              // Offset of row computed by
current iteration.
             for (int j=k; ++j < size;) {
-                final int loRowOffset = j*innerSize;    // Offset of some row after the current
row.
-                final int luRowOffset = j*size;         // Offset of the corresponding row
in the LU matrix.
+                final int loRowOffset = j*innerSize;        // Offset of some row after the
current row.
+                final int luRowOffset = j*size;             // Offset of the corresponding
row in the LU matrix.
                 for (int i=0; i<innerSize; i++) {
                     acc.setFrom (elements, loRowOffset + i, errorOffset);
                     rat.setFrom (elements, rowOffset   + i, errorOffset);

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/UnmodifiableMatrix.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/UnmodifiableMatrix.java?rev=1736900&r1=1736899&r2=1736900&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/UnmodifiableMatrix.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/UnmodifiableMatrix.java
[UTF-8] Mon Mar 28 15:38:54 2016
@@ -17,6 +17,7 @@
 package org.apache.sis.referencing.operation.matrix;
 
 import org.opengis.referencing.operation.Matrix;
+import org.apache.sis.internal.referencing.ExtendedPrecisionMatrix;
 import org.apache.sis.util.resources.Errors;
 
 
@@ -26,10 +27,10 @@ import org.apache.sis.util.resources.Err
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.6
- * @version 0.6
+ * @version 0.7
  * @module
  */
-final class UnmodifiableMatrix extends MatrixSIS {
+final class UnmodifiableMatrix extends MatrixSIS implements ExtendedPrecisionMatrix {
     /**
      * For cross-version compatibility.
      */
@@ -91,6 +92,18 @@ final class UnmodifiableMatrix extends M
         }
     }
 
+    /**
+     * Returns elements together with their error terms if available, or just the elements
otherwise.
+     */
+    @Override
+    public double[] getExtendedElements() {
+        if (matrix instanceof ExtendedPrecisionMatrix) {
+            return ((ExtendedPrecisionMatrix) matrix).getExtendedElements();
+        } else {
+            return getElements();
+        }
+    }
+
     /**
      * Returns the exception to throw when a setter method is invoked.
      */



Mime
View raw message