Skip to content

Commit 2ce0b2a

Browse files
committed
Switch to Eigen's BDCSVD for faster SVDs when number is large.
1 parent e03abc1 commit 2ce0b2a

2 files changed

Lines changed: 5 additions & 6 deletions

File tree

include/irlba/compute.hpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,9 @@ namespace irlba {
2424
/**
2525
* @cond
2626
*/
27-
template<typename EigenMatrix_>
28-
using JacobiSVD = Eigen::JacobiSVD<EigenMatrix_, Eigen::ComputeThinU | Eigen::ComputeThinV>;
29-
3027
template<class Matrix_, class EigenMatrix_, class EigenVector_>
3128
void exact(const Matrix_& matrix, const Eigen::Index requested_number, EigenMatrix_& outU, EigenMatrix_& outV, EigenVector_& outD) {
32-
JacobiSVD<EigenMatrix_> svd(matrix.rows(), matrix.cols());
29+
Eigen::BDCSVD<EigenMatrix_, Eigen::ComputeThinU | Eigen::ComputeThinV> svd(matrix.rows(), matrix.cols());
3330

3431
auto realizer = matrix.new_known_realize_workspace();
3532
EigenMatrix_ buffer;
@@ -235,7 +232,9 @@ Metrics compute(
235232
bool converged = false;
236233
int iter = 0, mult = 0;
237234
Eigen::Index k = 0;
238-
JacobiSVD<EigenMatrix_> svd(work, work);
235+
236+
// No need for QR preconditioning when we're dealing with a square matrix.
237+
Eigen::BDCSVD<EigenMatrix_, Eigen::NoQRPreconditioner | Eigen::ComputeFullU | Eigen::ComputeFullV> svd(work, work);
239238

240239
LanczosWorkspace<EigenVector_, Matrix_> lpwork(matrix);
241240

tests/src/compute.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ TEST(Compute, LargeExact) {
208208
irlba::Options opt;
209209
auto res = irlba::compute(wrapped, 15, opt);
210210

211-
Eigen::JacobiSVD<decltype(mat), Eigen::ComputeThinU | Eigen::ComputeThinV> svd(mat);
211+
Eigen::BDCSVD<decltype(mat), Eigen::ComputeThinU | Eigen::ComputeThinV> svd(mat);
212212
EXPECT_EQ(svd.singularValues().head(15), res.D);
213213
EXPECT_EQ(svd.matrixU().leftCols(15), res.U);
214214
EXPECT_EQ(svd.matrixV().leftCols(15), res.V);

0 commit comments

Comments
 (0)