Merge pull request #7 from apete/master
Reuse svd instance & compute values only when no vectors needed
diff --git a/src/main/java/com/yahoo/sketches/vector/decomposition/MatrixOpsImplOjAlgo.java b/src/main/java/com/yahoo/sketches/vector/decomposition/MatrixOpsImplOjAlgo.java
index a9218ff..57dfc3e 100644
--- a/src/main/java/com/yahoo/sketches/vector/decomposition/MatrixOpsImplOjAlgo.java
+++ b/src/main/java/com/yahoo/sketches/vector/decomposition/MatrixOpsImplOjAlgo.java
@@ -25,7 +25,9 @@
// work objects for Symmetric EVD
private Eigenvalue<Double> evd_;
-
+
+ // work object for full SVD
+ private SingularValue<Double> svd_;
transient private SparseStore<Double> S_; // to hold singular value matrix
@@ -138,14 +140,17 @@
}
private void computeFullSVD(final MatrixStore<Double> A, final boolean computeVectors) {
- final SingularValue<Double> svd = SingularValue.make(A);
- svd.compute(A);
-
- svd.getSingularValues(sv_);
+ if (svd_ == null) {
+ svd_ = SingularValue.make(A);
+ }
if (computeVectors) {
- svd.getQ2().transpose().supplyTo(Vt_);
+ svd_.decompose(A);
+ svd_.getQ2().transpose().supplyTo(Vt_);
+ } else {
+ svd_.computeValuesOnly(A);
}
+ svd_.getSingularValues(sv_);
}
private void computeSISVD(final MatrixStore<Double> A, final boolean computeVectors) {