fix groupId in pom, some cleanup based on feedback
diff --git a/pom.xml b/pom.xml
index cca9231..0a2e6ae 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
- <groupId>sketches-vector</groupId>
+ <groupId>com.yahoo.datasketches</groupId>
<artifactId>sketches-vector</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
diff --git a/src/main/java/com/yahoo/sketches/decomposition/FrequentDirections.java b/src/main/java/com/yahoo/sketches/decomposition/FrequentDirections.java
index fc532ce..3ffe9cd 100644
--- a/src/main/java/com/yahoo/sketches/decomposition/FrequentDirections.java
+++ b/src/main/java/com/yahoo/sketches/decomposition/FrequentDirections.java
@@ -2,6 +2,7 @@
import static com.yahoo.memory.UnsafeUtil.LS;
import static com.yahoo.sketches.decomposition.PreambleUtil.EMPTY_FLAG_MASK;
+import static com.yahoo.sketches.decomposition.PreambleUtil.SER_VER;
import static com.yahoo.sketches.decomposition.PreambleUtil.extractFamilyID;
import static com.yahoo.sketches.decomposition.PreambleUtil.extractFlags;
import static com.yahoo.sketches.decomposition.PreambleUtil.extractK;
@@ -73,7 +74,7 @@
public static FrequentDirections heapify(final Memory srcMem) {
final int preLongs = getAndCheckPreLongs(srcMem);
final int serVer = extractSerVer(srcMem);
- if (serVer != PreambleUtil.SER_VER) {
+ if (serVer != SER_VER) {
throw new IllegalArgumentException("Invalid serialization version: " + serVer);
}
@@ -152,8 +153,8 @@
}
if (vector.length != d_) {
- throw new IllegalArgumentException("Input vector has too few dimensions. Expected " + d_
- + "; found " + vector.length);
+ throw new IllegalArgumentException("Input vector has wrong number of dimensions. Expected "
+ + d_ + "; found " + vector.length);
}
if (nextZeroRow_ == l_) {
@@ -202,7 +203,7 @@
/**
* Checks if the sketch is empty, specifically whether it has processed any input data.
- * @return True if hte sketch has not yet processed any input
+ * @return True if the sketch has not yet processed any input
*/
public boolean isEmpty() {
return n_ == 0;
@@ -240,7 +241,7 @@
* during the algorithm.
* @param compensative If true, adjusts for mass subtracted during the algorithm, otherwise
* uses raw singular values.
- * @return As array of singular values.
+ * @return An array of singular values.
*/
public double[] getSingularValues(final boolean compensative) {
final SingularValue<Double> svd = SingularValue.make(B_);
@@ -263,7 +264,7 @@
}
/**
- * Returns an orthonormal projection Matrix that can be use to project input vectors into the
+ * Returns an orthonormal projection Matrix that can be used to project input vectors into the
* k-dimensional space represented by the sketch.
* @return An orthonormal Matrix object
*/
@@ -305,7 +306,7 @@
reduceRank();
}
- final PrimitiveDenseStore result;
+ final PrimitiveDenseStore result = PrimitiveDenseStore.FACTORY.makeZero(nextZeroRow_, d_);
if (compensative) {
// in the event we just called reduceRank(), the high rows are already zeroed out so no need
@@ -323,11 +324,9 @@
S_.set(i, i, 0.0);
}
- //result = PrimitiveDenseStore.FACTORY.makeZero(l_, d_);
- result = PrimitiveDenseStore.FACTORY.makeZero(nextZeroRow_, d_);
S_.multiply(svd.getQ2().transpose(), result);
} else {
- result = PrimitiveDenseStore.FACTORY.makeZero(nextZeroRow_, d_);
+ // there's gotta be a better way to copy rows than this
for (int i = 0; i < nextZeroRow_; ++i) {
int j = 0;
for (double d : B_.sliceRow(i)) {
@@ -362,12 +361,11 @@
* Returns a serialized representation of the sketch.
* <p>Note: If compress is true, will modify sketch state if the sketch would store more than k
* rows by applying SVD to compress the sketch to examply k rows.</p>
- * @param compress If true, compresses teh sketch to no more than k rows.
+ * @param compress If true, compresses the sketch to no more than k rows.
* @return A serialized representation of the sketch.
*/
public byte[] toByteArray(final boolean compress) {
final boolean empty = isEmpty();
- final int serVer = 1;
final int familyId = MatrixFamily.FREQUENTDIRECTIONS.getID();
final Matrix wrapB = Matrix.wrap(B_);
@@ -390,7 +388,7 @@
final long memAddr = memOut.getCumulativeOffset(0L);
insertPreLongs(memObj, memAddr, preLongs);
- insertSerVer(memObj, memAddr, serVer);
+ insertSerVer(memObj, memAddr, SER_VER);
insertFamilyID(memObj, memAddr, familyId);
insertFlags(memObj, memAddr, (empty ? EMPTY_FLAG_MASK : 0));
insertK(memObj, memAddr, k_);
@@ -511,8 +509,6 @@
double getSvAdjustment() { return svAdjustment_; }
private void reduceRank() {
- //++numReduce;
-
final SingularValue<Double> svd = SingularValue.make(B_);
svd.compute(B_);
svd.getSingularValues(sv_);
@@ -543,35 +539,4 @@
S_.multiply(svd.getQ2().transpose()).supplyTo(B_);
}
-
- /*
- private static double computeFrobNorm(final MatrixStore<Double> M) {
- double sum = 0.0;
- for (double d : M) {
- sum += d * d;
- }
- return Math.sqrt(sum);
- }
-
- private static double computeFrobNorm(final MatrixStore<Double> M, final int k) {
- double sum = 0.0;
- for (int i = 0; i < k; ++i) {
- for (double d : M.sliceRow(i)) {
- sum += d * d;
- }
- }
- return Math.sqrt(sum);
- }
-
- private static MatrixStore<Double> getKRows(final MatrixStore<Double> M, final int k) {
- PrimitiveDenseStore result = PrimitiveDenseStore.FACTORY.makeZero(k, M.countColumns());
- for (int i = 0; i < k; ++i) {
- int j = 0;
- for (double d : M.sliceRow(i)) {
- result.set(i, j++, d);
- }
- }
- return result;
- }
- */
}
diff --git a/src/main/java/com/yahoo/sketches/matrix/MatrixImplOjAlgo.java b/src/main/java/com/yahoo/sketches/matrix/MatrixImplOjAlgo.java
index 9aad941..a585b1a 100644
--- a/src/main/java/com/yahoo/sketches/matrix/MatrixImplOjAlgo.java
+++ b/src/main/java/com/yahoo/sketches/matrix/MatrixImplOjAlgo.java
@@ -130,9 +130,6 @@
assert numElements < mtx_.count();
- //final boolean isEmpty = (numRows == 0) || (numColumns == 0);
- //final int flags = COMPACT_FLAG_MASK | (isEmpty ? EMPTY_FLAG_MASK : 0);
-
final int outBytes = (int) ((preLongs * Long.BYTES) + (numElements * Double.BYTES));
final byte[] outByteArr = new byte[outBytes];
final WritableMemory memOut = WritableMemory.wrap(outByteArr);