@@ -22,7 +22,7 @@ TEST(Compute, CompareToExact) {
2222 irlba::Options opt;
2323 opt.exact_for_large_number = false ;
2424 irlba::SimpleMatrix<Eigen::VectorXd, Eigen::MatrixXd, decltype (&A)> wrapped (&A);
25- auto res = irlba::compute (wrapped, 5 , opt);
25+ auto res = irlba::compute (wrapped, rank , opt);
2626
2727 Eigen::JacobiSVD<decltype (A), Eigen::ComputeThinU | Eigen::ComputeThinV> svd (A);
2828 expect_equal_vectors (res.D , svd.singularValues ().head (rank), 1e-8 );
@@ -49,6 +49,35 @@ TEST(Compute, ChooseRequestedPlusExtraWorkOrSmaller) {
4949 EXPECT_EQ (irlba::choose_requested_plus_extra_work_or_smaller (10 , 20 , 35 ), 30 );
5050}
5151
52+ TEST (Compute, ZeroExtent) {
53+ irlba::Options opt;
54+ opt.cap_number = true ;
55+
56+ {
57+ auto A = create_random_matrix (0 , 10 );
58+ irlba::SimpleMatrix<Eigen::VectorXd, Eigen::MatrixXd, decltype (&A)> wrapped (&A);
59+ auto res = irlba::compute (wrapped, 5 , opt);
60+
61+ EXPECT_EQ (res.D .size (), 0 );
62+ EXPECT_EQ (res.U .rows (), 0 );
63+ EXPECT_EQ (res.U .cols (), 0 );
64+ EXPECT_EQ (res.V .rows (), 10 );
65+ EXPECT_EQ (res.V .cols (), 0 );
66+ }
67+
68+ {
69+ auto A = create_random_matrix (10 , 0 );
70+ irlba::SimpleMatrix<Eigen::VectorXd, Eigen::MatrixXd, decltype (&A)> wrapped (&A);
71+ auto res = irlba::compute (wrapped, 5 , opt);
72+
73+ EXPECT_EQ (res.D .size (), 0 );
74+ EXPECT_EQ (res.U .rows (), 10 );
75+ EXPECT_EQ (res.U .cols (), 0 );
76+ EXPECT_EQ (res.V .rows (), 0 );
77+ EXPECT_EQ (res.V .cols (), 0 );
78+ }
79+ }
80+
5281TEST (Compute, UpdateK) {
5382 auto ref_update_k = [](int k, const int requested_number, const int n_converged, const int work) -> int {
5483 if (k < requested_number + n_converged) {
@@ -214,17 +243,6 @@ TEST(Compute, Fails) {
214243 }
215244 EXPECT_TRUE (message.find (" must be less than" ) != std::string::npos);
216245
217- // Requested number of SVs + extra work is zero.
218- message.clear ();
219- try {
220- irlba::Options opt;
221- opt.extra_work = 0 ;
222- irlba::compute (wrapped, 0 , opt);
223- } catch (const std::exception& e) {
224- message = e.what ();
225- }
226- EXPECT_TRUE (message.find (" must be positive" ) != std::string::npos);
227-
228246 // Initialization vector is not of the right length.
229247 message.clear ();
230248 try {
0 commit comments