sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] 03/03: Store localization grids using single precision instead of double precision for reducing memory consumption. We presume that single precision is sufficient because the values stored in the `offsets` array are differences, not absolute coordinates. The absolute coordinates will be computed by adding `double` values to those offsets.
Date Tue, 16 Apr 2019 12:51:11 GMT
This is an automated email from the ASF dual-hosted git repository.

desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git

commit 8b63089122c4957c7a4851a15de1330ebbaac869
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Tue Apr 16 14:48:31 2019 +0200

    Store localization grids using single precision instead of double precision for reducing
memory consumption.
    We presume that single precision is sufficient because the values stored in the `offsets`
array are differences,
    not absolute coordinates. The absolute coordinates will be computed by adding `double`
values to those offsets.
---
 .../operation/builder/LocalizationGridBuilder.java       | 16 ++++++++++------
 .../sis/referencing/operation/builder/ResidualGrid.java  |  8 +++++---
 .../operation/builder/LocalizationGridBuilderTest.java   |  6 ++++--
 .../referencing/operation/builder/ResidualGridTest.java  |  2 +-
 4 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/builder/LocalizationGridBuilder.java
b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/builder/LocalizationGridBuilder.java
index aca8b7e..206273e 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/builder/LocalizationGridBuilder.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/builder/LocalizationGridBuilder.java
@@ -131,7 +131,7 @@ public class LocalizationGridBuilder extends TransformBuilder {
      * precision has been specified. The {@code sourceToGrid} transform shall not be applied
on this value.
      * This default precision may change in any future SIS version.
      */
-    static final double DEFAULT_PRECISION = 1E-7;
+    private static final double DEFAULT_PRECISION = 1E-7;
 
     /**
      * The transform created by {@link #create(MathTransformFactory)}.
@@ -627,7 +627,7 @@ public class LocalizationGridBuilder extends TransformBuilder {
             } else {
                 final int      width    = linear.gridSize(0);
                 final int      height   = linear.gridSize(1);
-                final double[] residual = new double[SOURCE_DIMENSION * linear.gridLength];
+                final float[]  residual = new float [SOURCE_DIMENSION * linear.gridLength];
                 final double[] grid     = new double[SOURCE_DIMENSION * width];
                 double gridPrecision    = precision;
                 try {
@@ -659,10 +659,14 @@ public class LocalizationGridBuilder extends TransformBuilder {
                         tmp[0] = 0;
                         tmp[1] = y;
                         linear.getControlRow(tmp, grid);                                
   // Expected positions.
-                        coordToGrid.transform(grid, 0, residual, k, width);             
   // As grid coordinate.
-                        for (int x=0; x<width; x++) {
-                            isLinear &= (residual[k++] -= x) <= gridPrecision;
-                            isLinear &= (residual[k++] -= y) <= gridPrecision;
+                        coordToGrid.transform(grid, 0, grid, 0, width);                 
   // As grid coordinate.
+                        for (int i=0,x=0; x<width; x++) {
+                            final double dx = grid[i++] - x;
+                            final double dy = grid[i++] - y;
+                            isLinear &= (dx <= gridPrecision);
+                            isLinear &= (dy <= gridPrecision);
+                            residual[k++] = (float) dx;
+                            residual[k++] = (float) dy;
                         }
                     }
                 } catch (TransformException e) {
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/builder/ResidualGrid.java
b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/builder/ResidualGrid.java
index 4cf8672..46565c3 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/builder/ResidualGrid.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/builder/ResidualGrid.java
@@ -50,7 +50,7 @@ final class ResidualGrid extends DatumShiftGrid<Dimensionless,Dimensionless>
{
     /**
      * For cross-version compatibility.
      */
-    private static final long serialVersionUID = -713276314000661839L;
+    private static final long serialVersionUID = 5207799661806374259L;
 
     /**
      * Number of source dimensions of the residual grid.
@@ -111,8 +111,10 @@ final class ResidualGrid extends DatumShiftGrid<Dimensionless,Dimensionless>
{
     /**
      * The residual data, as translations to apply on the result of affine transform.
      * In this flat array, index of target dimension varies fastest, then column index, then
row index.
+     * Single precision instead of double is presumed sufficient because this array contains
only differences,
+     * not absolute positions. Absolute positions will be computed by adding {@code double} values
to those offsets.
      */
-    private final double[] offsets;
+    private final float[] offsets;
 
     /**
      * Conversion from translated coordinates (after the datum shift has been applied) to
"real world" coordinates.
@@ -139,7 +141,7 @@ final class ResidualGrid extends DatumShiftGrid<Dimensionless,Dimensionless>
{
      * @param precision     desired precision of inverse transformations in unit of grid
cells.
      */
     ResidualGrid(final LinearTransform sourceToGrid, final LinearTransform gridToTarget,
-            final int nx, final int ny, final double[] residuals, final double precision)
+            final int nx, final int ny, final float[] residuals, final double precision)
     {
         super(Units.UNITY, sourceToGrid, new int[] {nx, ny}, true, Units.UNITY);
         this.gridToTarget = gridToTarget;
diff --git a/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/builder/LocalizationGridBuilderTest.java
b/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/builder/LocalizationGridBuilderTest.java
index 158d283..803cefa 100644
--- a/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/builder/LocalizationGridBuilderTest.java
+++ b/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/builder/LocalizationGridBuilderTest.java
@@ -84,15 +84,17 @@ public final strictfp class LocalizationGridBuilderTest extends TransformTestCas
     public void testQuadratic() throws FactoryException, TransformException {
         final AffineTransform reference = new AffineTransform(20, -30, 5, -4, -20, 8);
         final LocalizationGridBuilder builder = builder(reference, 5, 4);
+        builder.setDesiredPrecision(1E-6);
         transform = builder.create(null);
 
-        tolerance = 1E-13;
+        tolerance = 2E-7;
         isInverseTransformSupported = false;
         verifyQuadratic();
         /*
          * The tolerance value specified here should be approximately equal to ResidualGrid.accuracy.
+         * That value was specified in the call to builder.setDesiredPrecision(1E-6).
          */
-        tolerance = LocalizationGridBuilder.DEFAULT_PRECISION;
+        tolerance = 1E-6;
         isInverseTransformSupported = true;
         verifyQuadratic();
     }
diff --git a/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/builder/ResidualGridTest.java
b/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/builder/ResidualGridTest.java
index a5ba367..189348d 100644
--- a/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/builder/ResidualGridTest.java
+++ b/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/builder/ResidualGridTest.java
@@ -47,7 +47,7 @@ public final strictfp class ResidualGridTest extends TestCase {
      * The grid has no "source to grid" or "grid to CRS" transformations.
      */
     public ResidualGridTest() {
-        grid = new ResidualGrid(MathTransforms.identity(2), MathTransforms.identity(2), 3,
4, new double[] {
+        grid = new ResidualGrid(MathTransforms.identity(2), MathTransforms.identity(2), 3,
4, new float[] {
                 0,2  ,  1,2  ,  2,1,
                 1,3  ,  2,2  ,  1,1,
                 0,4  ,  2,3  ,  3,2,


Mime
View raw message