sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1529257 - in /sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix: GeneralMatrix.java Matrix1.java Matrix2.java Matrix3.java Matrix4.java MatrixSIS.java package-info.java
Date Fri, 04 Oct 2013 18:49:07 GMT
Author: desruisseaux
Date: Fri Oct  4 18:49:07 2013
New Revision: 1529257

URL: http://svn.apache.org/r1529257
Log:
Slightly more efficient 'getElements' for internal usage, and a little bit more documentation.

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/Matrix1.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/package-info.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=1529257&r1=1529256&r2=1529257&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] Fri Oct  4 18:49:07 2013
@@ -152,9 +152,13 @@ class GeneralMatrix extends MatrixSIS {
      * @param elements Where to copy the elements.
      */
     private static void getElements(final Matrix matrix, final int numRow, final int numCol,
final double[] elements) {
-        for (int k=0,j=0; j<numRow; j++) {
-            for (int i=0; i<numCol; i++) {
-                elements[k++] = matrix.getElement(j, i);
+        if (matrix instanceof MatrixSIS) {
+            ((MatrixSIS) matrix).getElements(elements);
+        } else {
+            for (int k=0,j=0; j<numRow; j++) {
+                for (int i=0; i<numCol; i++) {
+                    elements[k++] = matrix.getElement(j, i);
+                }
             }
         }
     }
@@ -282,6 +286,15 @@ class GeneralMatrix extends MatrixSIS {
     }
 
     /**
+     * Copies the matrix elements in the given flat array. This method does not verify the
array length,
+     * since the destination array may contain room for {@link DoubleDouble#error} terms.
+     */
+    @Override
+    final void getElements(final double[] dest) {
+        System.arraycopy(elements, 0, dest, 0, numRow*numCol);
+    }
+
+    /**
      * {@inheritDoc}
      */
     @Override

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=1529257&r1=1529256&r2=1529257&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 18:49:07 2013
@@ -84,6 +84,9 @@ public final class Matrix1 extends Matri
      *
      * @param elements Elements of the matrix.
      * @throws IllegalArgumentException If the given array does not have the expected length.
+     *
+     * @see #setElements(double[])
+     * @see Matrices#create(int, int, double[])
      */
     public Matrix1(final double[] elements) throws IllegalArgumentException {
         setElements(elements);
@@ -191,7 +194,18 @@ public final class Matrix1 extends Matri
      */
     @Override
     public final double[] getElements() {
-        return new double[] {m00};
+        final double[] elements = new double[SIZE*SIZE];
+        getElements(elements);
+        return elements;
+    }
+
+    /**
+     * Copies the matrix elements in the given flat array.
+     * The array length shall be at least 1, may also be 2.
+     */
+    @Override
+    final void getElements(final double[] elements) {
+        elements[0] = m00;
     }
 
     /**

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=1529257&r1=1529256&r2=1529257&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] Fri Oct  4 18:49:07 2013
@@ -81,10 +81,8 @@ public final class Matrix2 extends Matri
     public Matrix2(final double m00, final double m01,
                    final double m10, final double m11)
     {
-        this.m00 = m00;
-        this.m01 = m01;
-        this.m10 = m10;
-        this.m11 = m11;
+        this.m00 = m00;    this.m01 = m01;
+        this.m10 = m10;    this.m11 = m11;
     }
 
     /**
@@ -93,6 +91,9 @@ public final class Matrix2 extends Matri
      *
      * @param elements Elements of the matrix. Column indices vary fastest.
      * @throws IllegalArgumentException If the given array does not have the expected length.
+     *
+     * @see #setElements(double[])
+     * @see Matrices#create(int, int, double[])
      */
     public Matrix2(final double[] elements) throws IllegalArgumentException {
         setElements(elements);
@@ -211,7 +212,19 @@ public final class Matrix2 extends Matri
      */
     @Override
     public final double[] getElements() {
-        return new double[] {m00, m01, m10, m11};
+        final double[] elements = new double[SIZE*SIZE];
+        getElements(elements);
+        return elements;
+    }
+
+    /**
+     * Copies the matrix elements in the given flat array.
+     * The array length shall be at least 4, may also be 8.
+     */
+    @Override
+    final void getElements(final double[] elements) {
+        elements[0] = m00;    elements[1] = m01;
+        elements[2] = m10;    elements[3] = m11;
     }
 
     /**
@@ -221,10 +234,8 @@ public final class Matrix2 extends Matri
     @Override
     public final void setElements(final double[] elements) {
         ensureLengthMatch(SIZE*SIZE, elements);
-        m00 = elements[0];
-        m01 = elements[1];
-        m10 = elements[2];
-        m11 = elements[3];
+        m00 = elements[0];    m01 = elements[1];
+        m10 = elements[2];    m11 = elements[3];
     }
 
     /**

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=1529257&r1=1529256&r2=1529257&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] Fri Oct  4 18:49:07 2013
@@ -90,19 +90,13 @@ public final class Matrix3 extends Matri
      * @param m21 The second matrix element in the third row.
      * @param m22 The third matrix element in the third row.
      */
-    public Matrix3(double m00, double m01, double m02,
-                   double m10, double m11, double m12,
-                   double m20, double m21, double m22)
+    public Matrix3(final double m00, final double m01, final double m02,
+                   final double m10, final double m11, final double m12,
+                   final double m20, final double m21, final double m22)
     {
-        this.m00 = m00;
-        this.m01 = m01;
-        this.m02 = m02;
-        this.m10 = m10;
-        this.m11 = m11;
-        this.m12 = m12;
-        this.m20 = m20;
-        this.m21 = m21;
-        this.m22 = m22;
+        this.m00 = m00;    this.m01 = m01;    this.m02 = m02;
+        this.m10 = m10;    this.m11 = m11;    this.m12 = m12;
+        this.m20 = m20;    this.m21 = m21;    this.m22 = m22;
     }
 
     /**
@@ -111,6 +105,9 @@ public final class Matrix3 extends Matri
      *
      * @param elements Elements of the matrix. Column indices vary fastest.
      * @throws IllegalArgumentException If the given array does not have the expected length.
+     *
+     * @see #setElements(double[])
+     * @see Matrices#create(int, int, double[])
      */
     public Matrix3(final double[] elements) throws IllegalArgumentException {
         setElements(elements);
@@ -240,11 +237,20 @@ public final class Matrix3 extends Matri
      */
     @Override
     public final double[] getElements() {
-        return new double[] {
-            m00, m01, m02,
-            m10, m11, m12,
-            m20, m21, m22
-        };
+        final double[] elements = new double[SIZE*SIZE];
+        getElements(elements);
+        return elements;
+    }
+
+    /**
+     * Copies the matrix elements in the given flat array.
+     * The array length shall be at least 9, may also be 18.
+     */
+    @Override
+    final void getElements(final double[] elements) {
+        elements[0] = m00;    elements[1] = m01;    elements[2] = m02;
+        elements[3] = m10;    elements[4] = m11;    elements[5] = m12;
+        elements[6] = m20;    elements[7] = m21;    elements[8] = m22;
     }
 
     /**
@@ -254,15 +260,9 @@ public final class Matrix3 extends Matri
     @Override
     public final void setElements(final double[] elements) {
         ensureLengthMatch(SIZE*SIZE, elements);
-        m00 = elements[0];
-        m01 = elements[1];
-        m02 = elements[2];
-        m10 = elements[3];
-        m11 = elements[4];
-        m12 = elements[5];
-        m20 = elements[6];
-        m21 = elements[7];
-        m22 = elements[8];
+        m00 = elements[0];    m01 = elements[1];    m02 = elements[2];
+        m10 = elements[3];    m11 = elements[4];    m12 = elements[5];
+        m20 = elements[6];    m21 = elements[7];    m22 = elements[8];
     }
 
     /**

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=1529257&r1=1529256&r2=1529257&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] Fri Oct  4 18:49:07 2013
@@ -105,27 +105,15 @@ public final class Matrix4 extends Matri
      * @param m32 The third matrix element in the forth row.
      * @param m33 The forth matrix element in the forth row.
      */
-    public Matrix4(double m00, double m01, double m02, double m03,
-                   double m10, double m11, double m12, double m13,
-                   double m20, double m21, double m22, double m23,
-                   double m30, double m31, double m32, double m33)
+    public Matrix4(final double m00, final double m01, final double m02, final double m03,
+                   final double m10, final double m11, final double m12, final double m13,
+                   final double m20, final double m21, final double m22, final double m23,
+                   final double m30, final double m31, final double m32, final double m33)
     {
-        this.m00 = m00;
-        this.m01 = m01;
-        this.m02 = m02;
-        this.m03 = m03;
-        this.m10 = m10;
-        this.m11 = m11;
-        this.m12 = m12;
-        this.m13 = m13;
-        this.m20 = m20;
-        this.m21 = m21;
-        this.m22 = m22;
-        this.m23 = m23;
-        this.m30 = m30;
-        this.m31 = m31;
-        this.m32 = m32;
-        this.m33 = m33;
+        this.m00 = m00;    this.m01 = m01;    this.m02 = m02;    this.m03 = m03;
+        this.m10 = m10;    this.m11 = m11;    this.m12 = m12;    this.m13 = m13;
+        this.m20 = m20;    this.m21 = m21;    this.m22 = m22;    this.m23 = m23;
+        this.m30 = m30;    this.m31 = m31;    this.m32 = m32;    this.m33 = m33;
     }
 
     /**
@@ -134,6 +122,9 @@ public final class Matrix4 extends Matri
      *
      * @param elements Elements of the matrix. Column indices vary fastest.
      * @throws IllegalArgumentException If the given array does not have the expected length.
+     *
+     * @see #setElements(double[])
+     * @see Matrices#create(int, int, double[])
      */
     public Matrix4(final double[] elements) throws IllegalArgumentException {
         setElements(elements);
@@ -147,7 +138,7 @@ public final class Matrix4 extends Matri
      * @param matrix The matrix to copy.
      * @throws IllegalArgumentException if the given matrix is not of the expected size.
      */
-    public Matrix4(final Matrix matrix) throws IllegalArgumentException {
+    Matrix4(final Matrix matrix) throws IllegalArgumentException {
         for (int j=0; j<SIZE; j++) {
             for (int i=0; i<SIZE; i++) {
                 setElement(j,i, matrix.getElement(j,i));
@@ -278,12 +269,21 @@ public final class Matrix4 extends Matri
      */
     @Override
     public final double[] getElements() {
-        return new double[] {
-            m00, m01, m02, m03,
-            m10, m11, m12, m13,
-            m20, m21, m22, m23,
-            m30, m31, m32, m33
-        };
+        final double[] elements = new double[SIZE*SIZE];
+        getElements(elements);
+        return elements;
+    }
+
+    /**
+     * Copies the matrix elements in the given flat array.
+     * The array length shall be at least 16, may also be 32.
+     */
+    @Override
+    final void getElements(final double[] elements) {
+        elements[ 0] = m00;    elements[ 1] = m01;    elements[ 2] = m02;    elements[ 3]
= m03;
+        elements[ 4] = m10;    elements[ 5] = m11;    elements[ 6] = m12;    elements[ 7]
= m13;
+        elements[ 8] = m20;    elements[ 9] = m21;    elements[10] = m22;    elements[11]
= m23;
+        elements[12] = m30;    elements[13] = m31;    elements[14] = m32;    elements[15]
= m33;
     }
 
     /**
@@ -293,22 +293,10 @@ public final class Matrix4 extends Matri
     @Override
     public final void setElements(final double[] elements) {
         ensureLengthMatch(SIZE*SIZE, elements);
-        m00 = elements[ 0];
-        m01 = elements[ 1];
-        m02 = elements[ 2];
-        m03 = elements[ 3];
-        m10 = elements[ 4];
-        m11 = elements[ 5];
-        m12 = elements[ 6];
-        m13 = elements[ 7];
-        m20 = elements[ 8];
-        m21 = elements[ 9];
-        m22 = elements[10];
-        m23 = elements[11];
-        m30 = elements[12];
-        m31 = elements[13];
-        m32 = elements[14];
-        m33 = elements[15];
+        m00 = elements[ 0];    m01 = elements[ 1];    m02 = elements[ 2];    m03 = elements[
3];
+        m10 = elements[ 4];    m11 = elements[ 5];    m12 = elements[ 6];    m13 = elements[
7];
+        m20 = elements[ 8];    m21 = elements[ 9];    m22 = elements[10];    m23 = elements[11];
+        m30 = elements[12];    m31 = elements[13];    m32 = elements[14];    m33 = elements[15];
     }
 
     /**

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=1529257&r1=1529256&r2=1529257&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 18:49:07 2013
@@ -133,6 +133,19 @@ public abstract class MatrixSIS implemen
     public abstract double[] getElements();
 
     /**
+     * Stores all matrix elements in the given flat array. This method does not verify the
array length.
+     * All subclasses in this {@code org.apache.sis.referencing.operation.matrix} package
override this
+     * method with a more efficient implementation.
+     *
+     * @param dest The destination array. May be longer than necessary (this happen when
the caller needs to
+     *             append {@link org.apache.sis.internal.util.DoubleDouble#error} values
after the elements).
+     */
+    void getElements(final double[] dest) {
+        final double[] elements = getElements();
+        System.arraycopy(elements, 0, dest, 0, elements.length);
+    }
+
+    /**
      * Sets all matrix elements from a flat, row-major (column indices vary fastest) array.
      * The array length shall be <code>{@linkplain #getNumRow()} * {@linkplain #getNumCol()}</code>.
      *

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/package-info.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/package-info.java?rev=1529257&r1=1529256&r2=1529257&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/package-info.java
(original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/package-info.java
Fri Oct  4 18:49:07 2013
@@ -43,6 +43,20 @@
  *
  * <p><center><img src="doc-files/AffineTransform.png"></center></p>
  *
+ * {@section Extended floating point precision}
+ * This package uses extended floating point precision for most arithmetic operations like
matrix multiplications and
+ * inversions. SIS needs extended precision because <cite>affine transforms</cite>
concatenations like conversion from
+ * degrees to radians, followed by some operations, followed by conversion back from radians
to degrees, are very frequent.
+ * Without extended precision, we often obtain values like 0.99999… where we would expect
an identity transform.
+ * The usual workaround - namely comparing the floating point values with a small <var>epsilon</var>
tolerance value -
+ * is dangerous in this particular case because <cite>datum shifts</cite>, when
expressed as a matrix from their
+ * {@linkplain org.apache.sis.referencing.datum.BursaWolfParameters Bursa-Wolf parameters},
are very close to the
+ * identity transform.
+ *
+ * <p>The current implementation uses
+ * <a href="http://en.wikipedia.org/wiki/Double-double_%28arithmetic%29#Double-double_arithmetic">double-double
+ * arithmetic</a>. However this may change in any future SIS version.</p>
+ *
  * {@section Related projects}
  * This package is <strong>not</strong> designed for large matrices, and is rooted
in
  * {@code org.apache.sis.referencing} for making clearer that this is not a general-purpose
library.



Mime
View raw message