This is an automated email from the ASF dual-hosted git repository.

leerho pushed a commit to branch LicenseSwap2
in repository 
https://gitbox.apache.org/repos/asf/incubator-datasketches-vector.git


The following commit(s) were added to refs/heads/LicenseSwap2 by this push:
     new 00ddab0  Code cleanup.
00ddab0 is described below

commit 00ddab0ce372a535d853cd31e34e77ab0cc249e0
Author: Lee Rhodes <[email protected]>
AuthorDate: Thu Oct 17 13:59:07 2019 -0700

    Code cleanup.
---
 .../apache/datasketches/vector/MatrixFamily.java   |  5 +++-
 .../vector/decomposition/MatrixOps.java            | 28 +++++++++++++++++++---
 .../vector/decomposition/MatrixOpsImplOjAlgo.java  | 17 +++++++------
 .../datasketches/vector/decomposition/SVDAlgo.java | 23 ++++++++++++++++++
 .../apache/datasketches/vector/matrix/Matrix.java  |  8 +++++--
 .../datasketches/vector/matrix/MatrixBuilder.java  |  3 +++
 .../vector/matrix/MatrixImplOjAlgo.java            |  3 +++
 .../datasketches/vector/matrix/MatrixType.java     | 14 +++++++++++
 .../decomposition/FrequentDirectionsTest.java      |  8 ++++---
 .../vector/decomposition/MatrixOpsTest.java        |  7 +++---
 .../vector/matrix/MatrixBuilderTest.java           |  1 +
 .../vector/matrix/MatrixImplOjAlgoTest.java        |  2 ++
 .../datasketches/vector/matrix/MatrixTest.java     |  1 +
 13 files changed, 99 insertions(+), 21 deletions(-)

diff --git a/src/main/java/org/apache/datasketches/vector/MatrixFamily.java 
b/src/main/java/org/apache/datasketches/vector/MatrixFamily.java
index dec7952..9c1d141 100644
--- a/src/main/java/org/apache/datasketches/vector/MatrixFamily.java
+++ b/src/main/java/org/apache/datasketches/vector/MatrixFamily.java
@@ -41,6 +41,9 @@ public enum MatrixFamily {
    * matrix.
    */
   MATRIX(128, "Matrix", 2, 3),
+  /**
+   * Select Frequent Directions Family
+   */
   FREQUENTDIRECTIONS(129, "FrequentDirections", 2, 4);
 
 
@@ -80,7 +83,7 @@ public enum MatrixFamily {
   public void checkFamilyID(final int id) {
     if (id != id_) {
       throw new IllegalArgumentException(
-              "Possible Corruption: This Family " + this.toString()
+              "Possible Corruption: This Family " + toString()
                       + " does not match the ID of the given Family: " + 
idToFamily(id).toString());
     }
   }
diff --git 
a/src/main/java/org/apache/datasketches/vector/decomposition/MatrixOps.java 
b/src/main/java/org/apache/datasketches/vector/decomposition/MatrixOps.java
index 845ad46..7c5e57c 100644
--- a/src/main/java/org/apache/datasketches/vector/decomposition/MatrixOps.java
+++ b/src/main/java/org/apache/datasketches/vector/decomposition/MatrixOps.java
@@ -17,15 +17,37 @@
  * under the License.
  */
 
+//License header from the SVD.java file:
+/*
+ * Copyright (C) 2003-2006 Bjørn-Ove Heimsund
+ *
+ * This file is part of MTJ.
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by the
+ * Free Software Foundation; either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
 package org.apache.datasketches.vector.decomposition;
 
 import org.apache.datasketches.vector.matrix.Matrix;
 
 /**
- * Computes singular value decompositions and related Matrix operations needed 
by Frequent Directions. May
- * return as many singular values as exist, but other operations will limit 
output to k dimensions.
+ * Computes singular value decompositions and related Matrix operations needed 
by Frequent Directions.
+ * May return as many singular values as exist, but other operations will 
limit output to k dimensions.
  */
-// Directly derived from LGPL'd Matrix Toolkit for Java:
+// Directly derived from LGPL'd Matrix Toolkit for Java (MTL):
 // 
https://github.com/fommil/matrix-toolkits-java/blob/master/src/main/java/no/uib/cipr/matrix/SVD.java
 abstract class MatrixOps {
 
diff --git 
a/src/main/java/org/apache/datasketches/vector/decomposition/MatrixOpsImplOjAlgo.java
 
b/src/main/java/org/apache/datasketches/vector/decomposition/MatrixOpsImplOjAlgo.java
index 401d00b..4c1f8d1 100644
--- 
a/src/main/java/org/apache/datasketches/vector/decomposition/MatrixOpsImplOjAlgo.java
+++ 
b/src/main/java/org/apache/datasketches/vector/decomposition/MatrixOpsImplOjAlgo.java
@@ -30,7 +30,6 @@ import org.ojalgo.matrix.store.SparseStore;
 import org.ojalgo.random.Normal;
 
 import org.apache.datasketches.vector.matrix.Matrix;
-import org.apache.datasketches.vector.matrix.MatrixImplOjAlgo;
 import org.apache.datasketches.vector.matrix.MatrixType;
 
 class MatrixOpsImplOjAlgo extends MatrixOps {
@@ -44,7 +43,7 @@ class MatrixOpsImplOjAlgo extends MatrixOps {
 
   // work objects for Symmetric EVD
   private Eigenvalue<Double> evd_;
-  
+
   // work object for full SVD
   private SingularValue<Double> svd_;
 
@@ -68,7 +67,7 @@ class MatrixOpsImplOjAlgo extends MatrixOps {
       throw new IllegalArgumentException("A.numColumns() != d_");
     }
 
-    if (computeVectors && Vt_ == null) {
+    if (computeVectors && (Vt_ == null)) {
       Vt_ = PrimitiveDenseStore.FACTORY.makeZero(n_, d_);
       S_ = SparseStore.makePrimitive(sv_.length, sv_.length);
     }
@@ -98,7 +97,7 @@ class MatrixOpsImplOjAlgo extends MatrixOps {
 
   @Override
   Matrix getVt() {
-    return MatrixImplOjAlgo.wrap(Vt_);
+    return Matrix.wrap(Vt_);
   }
 
   @Override
@@ -111,9 +110,9 @@ class MatrixOpsImplOjAlgo extends MatrixOps {
       double medianSVSq = sv_[k_ - 1]; // (l_/2)th item, not yet squared
       medianSVSq *= medianSVSq;
       svAdjustment += medianSVSq; // always track, even if not using 
compensative mode
-      for (int i = 0; i < k_ - 1; ++i) {
+      for (int i = 0; i < (k_ - 1); ++i) {
         final double val = sv_[i];
-        final double adjSqSV = val * val - medianSVSq;
+        final double adjSqSV = (val * val) - medianSVSq;
         S_.set(i, i, adjSqSV < 0 ? 0.0 : Math.sqrt(adjSqSV)); // just to be 
safe
       }
       for (int i = k_ - 1; i < S_.countColumns(); ++i) {
@@ -144,9 +143,9 @@ class MatrixOpsImplOjAlgo extends MatrixOps {
             = PrimitiveDenseStore.FACTORY.copy((PrimitiveDenseStore) 
A.getRawObject());
     svd(Matrix.wrap(result), true);
 
-    for (int i = 0; i < k_ - 1; ++i) {
+    for (int i = 0; i < (k_ - 1); ++i) {
       final double val = sv_[i];
-      final double adjSV = Math.sqrt(val * val + svAdjustment);
+      final double adjSV = Math.sqrt((val * val) + svAdjustment);
       S_.set(i, i, adjSV);
     }
     for (int i = k_ - 1; i < S_.countColumns(); ++i) {
@@ -223,7 +222,7 @@ class MatrixOpsImplOjAlgo extends MatrixOps {
     for (int i = 0; i < ev.length; ++i) {
       final double val = Math.sqrt(ev[i]);
       sv_[i] = val;
-      if (computeVectors && val > 0) { S_.set(i, i, 1 / val); }
+      if (computeVectors && (val > 0)) { S_.set(i, i, 1 / val); }
     }
 
     if (computeVectors) {
diff --git 
a/src/main/java/org/apache/datasketches/vector/decomposition/SVDAlgo.java 
b/src/main/java/org/apache/datasketches/vector/decomposition/SVDAlgo.java
index 87d2bd2..25db3c6 100644
--- a/src/main/java/org/apache/datasketches/vector/decomposition/SVDAlgo.java
+++ b/src/main/java/org/apache/datasketches/vector/decomposition/SVDAlgo.java
@@ -31,8 +31,23 @@ package org.apache.datasketches.vector.decomposition;
  * </ul>
  */
 public enum SVDAlgo {
+
+  /**
+   * The matrix library's default SVD implementation.
+   */
   FULL(1, "Full"),
+
+  /**
+   * Simultaneous iteration, an approximate method likely to be more efficient 
only with sparse
+   * matrices or when <em>k</em> is significantly smaller than the number of 
rows in the sketch.
+   */
   SISVD(2, "SISVD"),
+
+  /**
+   * Takes advantage of matrix dimensionality, first computing eigenvalues of 
AA^T, then computes
+   *   intended results. Squaring A alters condition number and may cause 
numeric stability issues,
+   *   but unlikely an issue for Frequent Directions since discarding the 
smaller singular values/vectors.
+   */
   SYM(3, "Symmetrized");
 
   private int id_;
@@ -43,8 +58,16 @@ public enum SVDAlgo {
     name_ = name;
   }
 
+  /**
+   * Returns the ID.
+   * @return the ID.
+   */
   public int getId() { return id_; }
 
+  /**
+   * Gets the name
+   * @return the name
+   */
   public String getName() { return name_; }
 
   @Override
diff --git a/src/main/java/org/apache/datasketches/vector/matrix/Matrix.java 
b/src/main/java/org/apache/datasketches/vector/matrix/Matrix.java
index 947bb1e..284eee6 100644
--- a/src/main/java/org/apache/datasketches/vector/matrix/Matrix.java
+++ b/src/main/java/org/apache/datasketches/vector/matrix/Matrix.java
@@ -177,9 +177,9 @@ public abstract class Matrix {
     final int nRows = Math.min(rows, numRows_);
     final int nCols = Math.min(cols, numCols_);
 
-    if (nRows < 1 || nCols < 1) {
+    if ((nRows < 1) || (nCols < 1)) {
       return MatrixFamily.MATRIX.getMinPreLongs() * Long.BYTES;
-    } else if (nRows == numRows_ && nCols == numCols_) {
+    } else if ((nRows == numRows_) && (nCols == numCols_)) {
       return getSizeBytes();
     }
 
@@ -226,5 +226,9 @@ public abstract class Matrix {
     return sb.toString();
   }
 
+  /**
+   * Gets the matrix type
+   * @return the matrix type
+   */
   public abstract MatrixType getMatrixType();
 }
diff --git 
a/src/main/java/org/apache/datasketches/vector/matrix/MatrixBuilder.java 
b/src/main/java/org/apache/datasketches/vector/matrix/MatrixBuilder.java
index 059fc91..a9ada47 100644
--- a/src/main/java/org/apache/datasketches/vector/matrix/MatrixBuilder.java
+++ b/src/main/java/org/apache/datasketches/vector/matrix/MatrixBuilder.java
@@ -26,6 +26,9 @@ public class MatrixBuilder {
 
   private MatrixType type_ = MatrixType.OJALGO; // default type
 
+  /**
+   * Default no-op constructor.
+   */
   public MatrixBuilder() {}
 
   /**
diff --git 
a/src/main/java/org/apache/datasketches/vector/matrix/MatrixImplOjAlgo.java 
b/src/main/java/org/apache/datasketches/vector/matrix/MatrixImplOjAlgo.java
index 4bcc8f1..590ddcb 100644
--- a/src/main/java/org/apache/datasketches/vector/matrix/MatrixImplOjAlgo.java
+++ b/src/main/java/org/apache/datasketches/vector/matrix/MatrixImplOjAlgo.java
@@ -35,6 +35,9 @@ import org.apache.datasketches.memory.Memory;
 import org.apache.datasketches.memory.WritableMemory;
 import org.apache.datasketches.vector.MatrixFamily;
 
+/**
+ * Implements the OJ-Algo Matrix operations.
+ */
 public final class MatrixImplOjAlgo extends Matrix {
   private PrimitiveDenseStore mtx_;
 
diff --git 
a/src/main/java/org/apache/datasketches/vector/matrix/MatrixType.java 
b/src/main/java/org/apache/datasketches/vector/matrix/MatrixType.java
index f24acfa..8f2564e 100644
--- a/src/main/java/org/apache/datasketches/vector/matrix/MatrixType.java
+++ b/src/main/java/org/apache/datasketches/vector/matrix/MatrixType.java
@@ -19,7 +19,13 @@
 
 package org.apache.datasketches.vector.matrix;
 
+/**
+ * The MatrixType enum
+ */
 public enum MatrixType {
+  /**
+   * Select the ojAlgo
+   */
   OJALGO(1, "ojAlgo");
 
   private int id_;
@@ -30,8 +36,16 @@ public enum MatrixType {
     name_ = name;
   }
 
+  /**
+   * Gets the ID
+   * @return the ID
+   */
   public int getId() { return id_; }
 
+  /**
+   * Gets the name
+   * @return the name
+   */
   public String getName() { return name_; }
 
   @Override
diff --git 
a/src/test/java/org/apache/datasketches/vector/decomposition/FrequentDirectionsTest.java
 
b/src/test/java/org/apache/datasketches/vector/decomposition/FrequentDirectionsTest.java
index df4e6d5..e14e757 100644
--- 
a/src/test/java/org/apache/datasketches/vector/decomposition/FrequentDirectionsTest.java
+++ 
b/src/test/java/org/apache/datasketches/vector/decomposition/FrequentDirectionsTest.java
@@ -34,7 +34,9 @@ import org.apache.datasketches.memory.WritableMemory;
 import org.apache.datasketches.vector.MatrixFamily;
 import org.apache.datasketches.vector.matrix.Matrix;
 
+@SuppressWarnings("javadoc")
 public class FrequentDirectionsTest {
+
   @Test
   public void instantiateFD() {
     final int k = 32;
@@ -94,7 +96,7 @@ public class FrequentDirectionsTest {
     runUpdateTest(fd);
   }
 
-  private void runUpdateTest(final FrequentDirections fd) {
+  private static void runUpdateTest(final FrequentDirections fd) {
     final int k = fd.getK();
     final int d = fd.getD();
 
@@ -165,7 +167,7 @@ public class FrequentDirectionsTest {
     assertEquals(fd2.getN(), initialRows);
 
     fd1.update(fd2);
-    final int expectedRows = ((2 * initialRows) % k) + k - 1; // assumes 2 * 
initialRows > k
+    final int expectedRows = (((2 * initialRows) % k) + k) - 1; // assumes 2 * 
initialRows > k
     assertEquals(fd1.getNumRows(), expectedRows);
     assertEquals(fd1.getN(), 2 * initialRows);
 
@@ -196,7 +198,7 @@ public class FrequentDirectionsTest {
     runCompensativeResultTest(fd);
   }
 
-  private void runCompensativeResultTest(final FrequentDirections fd) {
+  private static void runCompensativeResultTest(final FrequentDirections fd) {
     final int d = fd.getD();
     final int k = fd.getK();
 
diff --git 
a/src/test/java/org/apache/datasketches/vector/decomposition/MatrixOpsTest.java 
b/src/test/java/org/apache/datasketches/vector/decomposition/MatrixOpsTest.java
index d438d5c..2288c07 100644
--- 
a/src/test/java/org/apache/datasketches/vector/decomposition/MatrixOpsTest.java
+++ 
b/src/test/java/org/apache/datasketches/vector/decomposition/MatrixOpsTest.java
@@ -28,6 +28,7 @@ import org.apache.datasketches.vector.matrix.Matrix;
 import org.apache.datasketches.vector.matrix.MatrixBuilder;
 import org.apache.datasketches.vector.matrix.MatrixType;
 
+@SuppressWarnings("javadoc")
 public class MatrixOpsTest {
 
   @Test
@@ -70,7 +71,7 @@ public class MatrixOpsTest {
     final Matrix A = generateIncreasingEye(d, 2 * k);
     final MatrixOps mo = MatrixOps.newInstance(A, SVDAlgo.FULL, k);
 
-    Matrix B = generateIncreasingEye(d, 2 * k + 1);
+    Matrix B = generateIncreasingEye(d, (2 * k) + 1);
     try {
       mo.svd(B, true);
       fail();
@@ -88,7 +89,7 @@ public class MatrixOpsTest {
 
   }
 
-  private void compareSingularValues(final double[] A, final double[] B, final 
int n) {
+  private static void compareSingularValues(final double[] A, final double[] 
B, final int n) {
     assertEquals(A.length, B.length);
 
     for (int i = 0; i < n; ++i) {
@@ -97,7 +98,7 @@ public class MatrixOpsTest {
   }
 
 
-  private void compareMatrixElementMagnitudes(final Matrix A, final Matrix B, 
final int n) {
+  private static void compareMatrixElementMagnitudes(final Matrix A, final 
Matrix B, final int n) {
     assertEquals(A.getNumColumns(), B.getNumColumns());
     assertEquals(A.getNumRows(), B.getNumRows());
 
diff --git 
a/src/test/java/org/apache/datasketches/vector/matrix/MatrixBuilderTest.java 
b/src/test/java/org/apache/datasketches/vector/matrix/MatrixBuilderTest.java
index 24feb17..2de3326 100644
--- a/src/test/java/org/apache/datasketches/vector/matrix/MatrixBuilderTest.java
+++ b/src/test/java/org/apache/datasketches/vector/matrix/MatrixBuilderTest.java
@@ -24,6 +24,7 @@ import static org.testng.Assert.assertNotNull;
 
 import org.testng.annotations.Test;
 
+@SuppressWarnings("javadoc")
 public class MatrixBuilderTest {
   @Test
   public void checkBuild() {
diff --git 
a/src/test/java/org/apache/datasketches/vector/matrix/MatrixImplOjAlgoTest.java 
b/src/test/java/org/apache/datasketches/vector/matrix/MatrixImplOjAlgoTest.java
index c1310d3..ab76ea5 100644
--- 
a/src/test/java/org/apache/datasketches/vector/matrix/MatrixImplOjAlgoTest.java
+++ 
b/src/test/java/org/apache/datasketches/vector/matrix/MatrixImplOjAlgoTest.java
@@ -28,7 +28,9 @@ import org.testng.annotations.Test;
 import org.apache.datasketches.memory.Memory;
 import org.apache.datasketches.memory.WritableMemory;
 
+@SuppressWarnings("javadoc")
 public class MatrixImplOjAlgoTest {
+
   @Test
   public void checkInstantiation() {
     final int nRows = 10;
diff --git 
a/src/test/java/org/apache/datasketches/vector/matrix/MatrixTest.java 
b/src/test/java/org/apache/datasketches/vector/matrix/MatrixTest.java
index ca34bc0..3943ab7 100644
--- a/src/test/java/org/apache/datasketches/vector/matrix/MatrixTest.java
+++ b/src/test/java/org/apache/datasketches/vector/matrix/MatrixTest.java
@@ -31,6 +31,7 @@ import org.apache.datasketches.memory.Memory;
 import org.apache.datasketches.memory.WritableMemory;
 import org.apache.datasketches.vector.MatrixFamily;
 
+@SuppressWarnings("javadoc")
 public class MatrixTest {
 
   @Test


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to