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 a00c5b8291f42b60df1f5605ff98650d5c57a3ff
Author: Martin Desruisseaux <martin.desruisse...@geomatys.com>
AuthorDate: Fri Sep 24 11:00:01 2021 +0200

    Remove rounding errors that are below 1 ULP.
---
 .../apache/sis/referencing/operation/matrix/MatrixSIS.java | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git 
a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/MatrixSIS.java
 
b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/MatrixSIS.java
index 5500dda..4efac16 100644
--- 
a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/MatrixSIS.java
+++ 
b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/MatrixSIS.java
@@ -441,11 +441,25 @@ public abstract class MatrixSIS implements Matrix, 
LenientComparable, Cloneable,
             }
             sum.sqrt();
             if (!sum.isZero()) {
+                int rowOfOne = -1;
                 for (int j=0; j<numRow; j++) {
                     get(j, i, tmp);
                     dot.setFrom(sum);
                     dot.inverseDivide(tmp);
                     set(j, i, dot);
+                    if (Math.abs(dot.doubleValue()) == 1) {
+                        rowOfOne = j;
+                    }
+                }
+                /*
+                 * If a value is exactly 1, then all other values should be 
exactly zero.
+                 * We observe that the other values are sometime close to 0.5 
ULP of 1.
+                 * Forcing those values to 0 can help the caller to apply 
optimizations.
+                 */
+                if (rowOfOne >= 0) {
+                    for (int j=0; j<numRow; j++) {
+                        setElement(j, i, Math.copySign((j == rowOfOne) ? 1 : 
0, getElement(j, i)));
+                    }
                 }
                 magnitudes.setNumber(0, i, sum);
             }

Reply via email to