@@ -246,6 +246,9 @@ class RowMatrix(
246246 * Then we compute U via easy matrix multiplication as U = A * (V * S-1).
247247 * Note that this approach requires `O(nnz(A))` time.
248248 *
249+ * When the requested eigenvalues k = n, a non-sparse implementation will be used, which requires
250+ * `n^2` doubles to fit in memory and `O(n^3)` time on the master node.
251+ *
249252 * At most k largest non-zero singular values and associated vectors are returned.
250253 * If there are k such values, then the dimensions of the return will be:
251254 *
@@ -269,8 +272,16 @@ class RowMatrix(
269272 val n = numCols().toInt
270273 require(k > 0 && k <= n, s " Request up to n singular values k= $k n= $n. " )
271274
272- val (sigmaSquares : BDV [Double ], u : BDM [Double ]) =
275+ val (sigmaSquares : BDV [Double ], u : BDM [Double ]) = if (k < n) {
273276 EigenValueDecomposition .symmetricEigs(multiplyGramianMatrix, n, k, tol)
277+ } else {
278+ logWarning(s " Request full SVD (k = n = $k), while ARPACK requires k strictly less than n. " +
279+ s " Using non-sparse implementation. " )
280+ val G = computeGramianMatrix()
281+ val (uFull : BDM [Double ], sigmaSquaresFull : BDV [Double ], vFull : BDM [Double ]) =
282+ brzSvd(G .toBreeze.asInstanceOf [BDM [Double ]])
283+ (sigmaSquaresFull, uFull)
284+ }
274285 val sigmas : BDV [Double ] = brzSqrt(sigmaSquares)
275286
276287 // Determine effective rank.
@@ -508,4 +519,4 @@ object RowMatrix {
508519
509520 Matrices .dense(n, n, G .data)
510521 }
511- }
522+ }
0 commit comments