You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2013/10/05 18:41:15 UTC
svn commit: r1529481 -
/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Solver.java
Author: desruisseaux
Date: Sat Oct 5 16:41:14 2013
New Revision: 1529481
URL: http://svn.apache.org/r1529481
Log:
Minor simplification in the iterator over the flat matrix array.
Modified:
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Solver.java
Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Solver.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Solver.java?rev=1529481&r1=1529480&r2=1529481&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Solver.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Solver.java [UTF-8] Sat Oct 5 16:41:14 2013
@@ -193,56 +193,58 @@ final class Solver implements Matrix {
* Conservatively search for NaN values only if the matrix looks like an affine transform.
* If the matrix is affine, then we will assume that we can interpret the last column as
* translation terms and other columns as scale factors.
+ *
+ * Note: the iteration below skips the last row, since it is (0, 0, ..., 1).
*/
-searchNaN: for (int j=lastRowOrColumn; --j>=0;) { // Skip the last row, since it is (0, 0, ..., 1).
- for (int i=size; --i>=0;) { // Scan all columns, including the translation terms.
- if (Double.isNaN(LU[j*size + i])) {
- /*
- * Found a NaN value. First, if we are not in the translation column, ensure
- * that the column contains only zero values except on the current line.
- */
- int columnOfScale = -1;
- if (i != lastRowOrColumn) { // Enter only if this column is not for translations.
- columnOfScale = i; // The non-translation element is the scale factor.
- for (int k=lastRowOrColumn; --k>=0;) { // Scan all other rows in the current column.
- if (k != j && LU[k*size + i] != 0) {
- // Found a non-zero element in the current column.
- // We can not proceed - cancel everything.
- indexOfNaN = null;
- indexCount = 0;
- break searchNaN;
- }
+searchNaN: for (int flatIndex = (size - 1) * size; --flatIndex >= 0;) {
+ if (Double.isNaN(LU[flatIndex])) {
+ final int j = flatIndex / size;
+ final int i = flatIndex % size;
+ /*
+ * Found a NaN value. First, if we are not in the translation column, ensure
+ * that the column contains only zero values except on the current line.
+ */
+ int columnOfScale = -1;
+ if (i != lastRowOrColumn) { // Enter only if this column is not for translations.
+ columnOfScale = i; // The non-translation element is the scale factor.
+ for (int k=lastRowOrColumn; --k>=0;) { // Scan all other rows in the current column.
+ if (k != j && LU[k*size + i] != 0) {
+ // Found a non-zero element in the current column.
+ // We can not proceed - cancel everything.
+ indexOfNaN = null;
+ indexCount = 0;
+ break searchNaN;
}
}
- /*
- * Next, ensure that the row contains only zero elements except for
- * the scale factor and the offset (the element in the translation
- * column, which is not checked by the loop below).
- */
- for (int k=lastRowOrColumn; --k>=0;) {
- if (k != i && LU[j*size + k] != 0) {
- if (columnOfScale >= 0) {
- // If there is more than 1 non-zero element,
- // abandon the attempt to handle NaN values.
- indexOfNaN = null;
- indexCount = 0;
- break searchNaN;
- }
- columnOfScale = k;
+ }
+ /*
+ * Next, ensure that the row contains only zero elements except for
+ * the scale factor and the offset (the element in the translation
+ * column, which is not checked by the loop below).
+ */
+ for (int k=lastRowOrColumn; --k>=0;) {
+ if (k != i && LU[j*size + k] != 0) {
+ if (columnOfScale >= 0) {
+ // If there is more than 1 non-zero element,
+ // abandon the attempt to handle NaN values.
+ indexOfNaN = null;
+ indexCount = 0;
+ break searchNaN;
}
+ columnOfScale = k;
}
- /*
- * At this point, the NaN element has been determined as replaceable.
- * Remember its index; the replacement will be performed later.
- */
- if (indexOfNaN == null) {
- indexOfNaN = new int[lastRowOrColumn * (2*TUPLE_SIZE)]; // At most one scale and one offset per row.
- }
- indexOfNaN[indexCount++] = i;
- indexOfNaN[indexCount++] = j;
- indexOfNaN[indexCount++] = columnOfScale; // May be -1 (while uncommon)
- assert (indexCount % TUPLE_SIZE) == 0;
}
+ /*
+ * At this point, the NaN element has been determined as replaceable.
+ * Remember its index; the replacement will be performed later.
+ */
+ if (indexOfNaN == null) {
+ indexOfNaN = new int[lastRowOrColumn * (2*TUPLE_SIZE)]; // At most one scale and one offset per row.
+ }
+ indexOfNaN[indexCount++] = i;
+ indexOfNaN[indexCount++] = j;
+ indexOfNaN[indexCount++] = columnOfScale; // May be -1 (while uncommon)
+ assert (indexCount % TUPLE_SIZE) == 0;
}
}
/*