bdcsvd.cpp File Reference
#include "main.h"
#include <Eigen/SVD>
#include "svd_common.h"

Macros

#define EIGEN_STACK_ALLOCATION_LIMIT   0
 
#define EIGEN_RUNTIME_NO_MALLOC
 
#define SVD_DEFAULT(M)   BDCSVD<M>
 
#define SVD_FOR_MIN_NORM(M)   BDCSVD<M>
 
#define SVD_STATIC_OPTIONS(M, O)   BDCSVD<M, O>
 

Functions

template<typename MatrixType >
void bdcsvd_method ()
 
template<typename MatrixType >
void compare_bdc_jacobi (const MatrixType &a=MatrixType(), int algoswap=16, bool random=true)
 
void compare_bdc_jacobi_instance (bool structure_as_m, int algoswap=16)
 
template<typename MatrixType >
void bdcsvd_thin_options (const MatrixType &input=MatrixType())
 
template<typename MatrixType >
void bdcsvd_full_options (const MatrixType &input=MatrixType())
 
template<typename MatrixType >
void bdcsvd_verify_assert (const MatrixType &input=MatrixType())
 
template<typename MatrixType >
void bdcsvd_check_convergence (const MatrixType &input)
 
 EIGEN_DECLARE_TEST (bdcsvd)
 

Macro Definition Documentation

◆ EIGEN_RUNTIME_NO_MALLOC

#define EIGEN_RUNTIME_NO_MALLOC

◆ EIGEN_STACK_ALLOCATION_LIMIT

#define EIGEN_STACK_ALLOCATION_LIMIT   0

◆ SVD_DEFAULT

#define SVD_DEFAULT (   M)    BDCSVD<M>

◆ SVD_FOR_MIN_NORM

#define SVD_FOR_MIN_NORM (   M)    BDCSVD<M>

◆ SVD_STATIC_OPTIONS

#define SVD_STATIC_OPTIONS (   M,
  O 
)    BDCSVD<M, O>

Function Documentation

◆ bdcsvd_check_convergence()

template<typename MatrixType >
void bdcsvd_check_convergence ( const MatrixType input)
81  {
83  VERIFY(svd.info() == Eigen::Success);
84  MatrixType D = svd.matrixU() * svd.singularValues().asDiagonal() * svd.matrixV().transpose();
85  VERIFY_IS_APPROX(input, D);
86 }
dominoes D
Definition: Domino.cpp:55
cout<< "Here is the matrix m:"<< endl<< m<< endl;JacobiSVD< MatrixXf, ComputeThinU|ComputeThinV > svd(m)
MatrixXf MatrixType
Definition: benchmark-blocking-sizes.cpp:52
class Bidiagonal Divide and Conquer SVD
Definition: BDCSVD.h:85
@ Success
Definition: Constants.h:440
#define VERIFY_IS_APPROX(a, b)
Definition: integer_types.cpp:13
#define VERIFY(a)
Definition: main.h:362

References D, Eigen::Success, svd(), VERIFY, and VERIFY_IS_APPROX.

◆ bdcsvd_full_options()

template<typename MatrixType >
void bdcsvd_full_options ( const MatrixType input = MatrixType())
70  {
71  svd_option_checks_full_only<MatrixType, 0>(input);
72 }

Referenced by EIGEN_DECLARE_TEST().

◆ bdcsvd_method()

template<typename MatrixType >
void bdcsvd_method ( )
26  {
27  enum { Size = MatrixType::RowsAtCompileTime };
28  typedef typename MatrixType::RealScalar RealScalar;
29  typedef Matrix<RealScalar, Size, 1> RealVecType;
30  MatrixType m = MatrixType::Identity();
31  VERIFY_IS_APPROX(m.bdcSvd().singularValues(), RealVecType::Ones());
32  VERIFY_RAISES_ASSERT(m.bdcSvd().matrixU());
33  VERIFY_RAISES_ASSERT(m.bdcSvd().matrixV());
34 }
NumTraits< Scalar >::Real RealScalar
Definition: bench_gemm.cpp:46
The matrix class, also used for vectors and row-vectors.
Definition: Eigen/Eigen/src/Core/Matrix.h:186
int * m
Definition: level2_cplx_impl.h:294
#define VERIFY_RAISES_ASSERT(a)
Definition: main.h:329

References m, VERIFY_IS_APPROX, and VERIFY_RAISES_ASSERT.

◆ bdcsvd_thin_options()

template<typename MatrixType >
void bdcsvd_thin_options ( const MatrixType input = MatrixType())
65  {
66  svd_thin_option_checks<MatrixType, 0>(input);
67 }

Referenced by EIGEN_DECLARE_TEST().

◆ bdcsvd_verify_assert()

template<typename MatrixType >
void bdcsvd_verify_assert ( const MatrixType input = MatrixType())
75  {
76  svd_verify_assert<MatrixType>(input);
77  svd_verify_constructor_options_assert<BDCSVD<MatrixType>>(input);
78 }

Referenced by EIGEN_DECLARE_TEST().

◆ compare_bdc_jacobi()

template<typename MatrixType >
void compare_bdc_jacobi ( const MatrixType a = MatrixType(),
int  algoswap = 16,
bool  random = true 
)
38  {
39  MatrixType m = random ? MatrixType::Random(a.rows(), a.cols()) : a;
40 
41  BDCSVD<MatrixType> bdc_svd(m.rows(), m.cols());
42  bdc_svd.setSwitchSize(algoswap);
43  bdc_svd.compute(m);
44 
45  JacobiSVD<MatrixType> jacobi_svd(m);
46  VERIFY_IS_APPROX(bdc_svd.singularValues(), jacobi_svd.singularValues());
47 }
Two-sided Jacobi SVD decomposition of a rectangular matrix.
Definition: JacobiSVD.h:500
const Scalar * a
Definition: level2_cplx_impl.h:32

References a, Eigen::BDCSVD< MatrixType_, Options_ >::compute(), m, Eigen::BDCSVD< MatrixType_, Options_ >::setSwitchSize(), Eigen::SVDBase< Derived >::singularValues(), and VERIFY_IS_APPROX.

Referenced by compare_bdc_jacobi_instance().

◆ compare_bdc_jacobi_instance()

void compare_bdc_jacobi_instance ( bool  structure_as_m,
int  algoswap = 16 
)
50  {
51  MatrixXd m(4, 3);
52  if (structure_as_m) {
53  // The first 3 rows are the reduced form of Matrix 1 as shown below, and it
54  // has nonzero elements in the first column and diagonals only.
55  m << 1.056293, 0, 0, -0.336468, 0.907359, 0, -1.566245, 0, 0.149150, -0.1, 0, 0;
56  } else {
57  // Matrix 1.
58  m << 0.882336, 18.3914, -26.7921, -5.58135, 17.1931, -24.0892, -20.794, 8.68496, -4.83103, -8.4981, -10.5451,
59  23.9072;
60  }
61  compare_bdc_jacobi(m, algoswap, false);
62 }
void compare_bdc_jacobi(const MatrixType &a=MatrixType(), int algoswap=16, bool random=true)
Definition: bdcsvd.cpp:38

References compare_bdc_jacobi(), and m.

Referenced by EIGEN_DECLARE_TEST().

◆ EIGEN_DECLARE_TEST()

EIGEN_DECLARE_TEST ( bdcsvd  )
88  {
89  CALL_SUBTEST_1((bdcsvd_verify_assert<Matrix3f>()));
90  CALL_SUBTEST_2((bdcsvd_verify_assert<Matrix4d>()));
93  CALL_SUBTEST_5((bdcsvd_verify_assert<Matrix<std::complex<double>, 6, 9>>()));
94 
95  CALL_SUBTEST_6((svd_all_trivial_2x2(bdcsvd_thin_options<Matrix2cd>)));
96  CALL_SUBTEST_7((svd_all_trivial_2x2(bdcsvd_full_options<Matrix2cd>)));
97  CALL_SUBTEST_8((svd_all_trivial_2x2(bdcsvd_thin_options<Matrix2d>)));
98  CALL_SUBTEST_9((svd_all_trivial_2x2(bdcsvd_full_options<Matrix2d>)));
99 
100  for (int i = 0; i < g_repeat; i++) {
101  int r = internal::random<int>(1, EIGEN_TEST_MAX_SIZE / 2), c = internal::random<int>(1, EIGEN_TEST_MAX_SIZE / 2);
102 
105 
106  CALL_SUBTEST_10((compare_bdc_jacobi<MatrixXf>(MatrixXf(r, c))));
107  CALL_SUBTEST_11((compare_bdc_jacobi<MatrixXd>(MatrixXd(r, c))));
108  CALL_SUBTEST_12((compare_bdc_jacobi<MatrixXcd>(MatrixXcd(r, c))));
109  // Test on inf/nan matrix
110  CALL_SUBTEST_13((svd_inf_nan<MatrixXf>()));
111  CALL_SUBTEST_14((svd_inf_nan<MatrixXd>()));
112 
113  // Verify some computations using all combinations of the Options template parameter.
114  CALL_SUBTEST_15((bdcsvd_thin_options<Matrix3f>()));
115  CALL_SUBTEST_16((bdcsvd_full_options<Matrix3f>()));
118  CALL_SUBTEST_19((bdcsvd_thin_options<MatrixXd>(MatrixXd(20, 17))));
119  CALL_SUBTEST_20((bdcsvd_full_options<MatrixXd>(MatrixXd(20, 17))));
120  CALL_SUBTEST_21((bdcsvd_thin_options<MatrixXd>(MatrixXd(17, 20))));
121  CALL_SUBTEST_22((bdcsvd_full_options<MatrixXd>(MatrixXd(17, 20))));
126  CALL_SUBTEST_27((bdcsvd_thin_options<MatrixXf>(MatrixXf(r, c))));
127  CALL_SUBTEST_28((bdcsvd_full_options<MatrixXf>(MatrixXf(r, c))));
128  CALL_SUBTEST_29((bdcsvd_thin_options<MatrixXcd>(MatrixXcd(r, c))));
129  CALL_SUBTEST_30((bdcsvd_full_options<MatrixXcd>(MatrixXcd(r, c))));
130  CALL_SUBTEST_31((bdcsvd_thin_options<MatrixXd>(MatrixXd(r, c))));
131  CALL_SUBTEST_32((bdcsvd_full_options<MatrixXd>(MatrixXd(r, c))));
142  r, c)));
145  c)));
148  r, c)));
151  c)));
152  }
153 
154  // test matrixbase method
155  CALL_SUBTEST_41((bdcsvd_method<Matrix2cd>()));
156  CALL_SUBTEST_42((bdcsvd_method<Matrix3f>()));
157 
158  // Test problem size constructors
160 
161  // Check that preallocation avoids subsequent mallocs
162  // Disabled because not supported by BDCSVD
163  // CALL_SUBTEST_9( svd_preallocate<void>() );
164 
165  CALL_SUBTEST_44(svd_underoverflow<void>());
166 
167  // Without total deflation issues.
170 
171  // With total deflation issues before, when it shouldn't be triggered.
174 
175  // Convergence for large constant matrix (https://gitlab.com/libeigen/eigen/-/issues/2491)
176  CALL_SUBTEST_49(bdcsvd_check_convergence<MatrixXf>(MatrixXf::Constant(500, 500, 1)));
177 }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
void compare_bdc_jacobi_instance(bool structure_as_m, int algoswap=16)
Definition: bdcsvd.cpp:50
void bdcsvd_thin_options(const MatrixType &input=MatrixType())
Definition: bdcsvd.cpp:65
void bdcsvd_full_options(const MatrixType &input=MatrixType())
Definition: bdcsvd.cpp:70
void bdcsvd_verify_assert(const MatrixType &input=MatrixType())
Definition: bdcsvd.cpp:75
#define EIGEN_TEST_MAX_SIZE
Definition: boostmultiprec.cpp:16
@ HouseholderQRPreconditioner
Definition: Constants.h:425
@ ColPivHouseholderQRPreconditioner
Definition: Constants.h:421
#define TEST_SET_BUT_UNUSED_VARIABLE(X)
Definition: main.h:139
static int g_repeat
Definition: main.h:191
r
Definition: UniformPSDSelfTest.py:20
int c
Definition: calibrate.py:100
#define CALL_SUBTEST_21(FUNC)
Definition: split_test_helper.h:124
#define CALL_SUBTEST_32(FUNC)
Definition: split_test_helper.h:190
#define CALL_SUBTEST_33(FUNC)
Definition: split_test_helper.h:196
#define CALL_SUBTEST_6(FUNC)
Definition: split_test_helper.h:34
#define CALL_SUBTEST_34(FUNC)
Definition: split_test_helper.h:202
#define CALL_SUBTEST_47(FUNC)
Definition: split_test_helper.h:280
#define CALL_SUBTEST_3(FUNC)
Definition: split_test_helper.h:16
#define CALL_SUBTEST_35(FUNC)
Definition: split_test_helper.h:208
#define CALL_SUBTEST_26(FUNC)
Definition: split_test_helper.h:154
#define CALL_SUBTEST_42(FUNC)
Definition: split_test_helper.h:250
#define CALL_SUBTEST_31(FUNC)
Definition: split_test_helper.h:184
#define CALL_SUBTEST_46(FUNC)
Definition: split_test_helper.h:274
#define CALL_SUBTEST_16(FUNC)
Definition: split_test_helper.h:94
#define CALL_SUBTEST_18(FUNC)
Definition: split_test_helper.h:106
#define CALL_SUBTEST_1(FUNC)
Definition: split_test_helper.h:4
#define CALL_SUBTEST_45(FUNC)
Definition: split_test_helper.h:268
#define CALL_SUBTEST_40(FUNC)
Definition: split_test_helper.h:238
#define CALL_SUBTEST_20(FUNC)
Definition: split_test_helper.h:118
#define CALL_SUBTEST_13(FUNC)
Definition: split_test_helper.h:76
#define CALL_SUBTEST_14(FUNC)
Definition: split_test_helper.h:82
#define CALL_SUBTEST_8(FUNC)
Definition: split_test_helper.h:46
#define CALL_SUBTEST_24(FUNC)
Definition: split_test_helper.h:142
#define CALL_SUBTEST_5(FUNC)
Definition: split_test_helper.h:28
#define CALL_SUBTEST_11(FUNC)
Definition: split_test_helper.h:64
#define CALL_SUBTEST_12(FUNC)
Definition: split_test_helper.h:70
#define CALL_SUBTEST_2(FUNC)
Definition: split_test_helper.h:10
#define CALL_SUBTEST_49(FUNC)
Definition: split_test_helper.h:292
#define CALL_SUBTEST_38(FUNC)
Definition: split_test_helper.h:226
#define CALL_SUBTEST_27(FUNC)
Definition: split_test_helper.h:160
#define CALL_SUBTEST_44(FUNC)
Definition: split_test_helper.h:262
#define CALL_SUBTEST_7(FUNC)
Definition: split_test_helper.h:40
#define CALL_SUBTEST_23(FUNC)
Definition: split_test_helper.h:136
#define CALL_SUBTEST_15(FUNC)
Definition: split_test_helper.h:88
#define CALL_SUBTEST_37(FUNC)
Definition: split_test_helper.h:220
#define CALL_SUBTEST_4(FUNC)
Definition: split_test_helper.h:22
#define CALL_SUBTEST_30(FUNC)
Definition: split_test_helper.h:178
#define CALL_SUBTEST_29(FUNC)
Definition: split_test_helper.h:172
#define CALL_SUBTEST_17(FUNC)
Definition: split_test_helper.h:100
#define CALL_SUBTEST_39(FUNC)
Definition: split_test_helper.h:232
#define CALL_SUBTEST_25(FUNC)
Definition: split_test_helper.h:148
#define CALL_SUBTEST_43(FUNC)
Definition: split_test_helper.h:256
#define CALL_SUBTEST_28(FUNC)
Definition: split_test_helper.h:166
#define CALL_SUBTEST_9(FUNC)
Definition: split_test_helper.h:52
#define CALL_SUBTEST_10(FUNC)
Definition: split_test_helper.h:58
#define CALL_SUBTEST_48(FUNC)
Definition: split_test_helper.h:286
#define CALL_SUBTEST_19(FUNC)
Definition: split_test_helper.h:112
#define CALL_SUBTEST_22(FUNC)
Definition: split_test_helper.h:130
#define CALL_SUBTEST_41(FUNC)
Definition: split_test_helper.h:244
#define CALL_SUBTEST_36(FUNC)
Definition: split_test_helper.h:214
void svd_all_trivial_2x2(void(*cb)(const MatrixType &))
Definition: svd_common.h:331
void svd_check_max_size_matrix(int initialRows, int initialCols)
Definition: svd_common.h:501

References bdcsvd_full_options(), bdcsvd_thin_options(), bdcsvd_verify_assert(), calibrate::c, CALL_SUBTEST_1, CALL_SUBTEST_10, CALL_SUBTEST_11, CALL_SUBTEST_12, CALL_SUBTEST_13, CALL_SUBTEST_14, CALL_SUBTEST_15, CALL_SUBTEST_16, CALL_SUBTEST_17, CALL_SUBTEST_18, CALL_SUBTEST_19, CALL_SUBTEST_2, CALL_SUBTEST_20, CALL_SUBTEST_21, CALL_SUBTEST_22, CALL_SUBTEST_23, CALL_SUBTEST_24, CALL_SUBTEST_25, CALL_SUBTEST_26, CALL_SUBTEST_27, CALL_SUBTEST_28, CALL_SUBTEST_29, CALL_SUBTEST_3, CALL_SUBTEST_30, CALL_SUBTEST_31, CALL_SUBTEST_32, CALL_SUBTEST_33, CALL_SUBTEST_34, CALL_SUBTEST_35, CALL_SUBTEST_36, CALL_SUBTEST_37, CALL_SUBTEST_38, CALL_SUBTEST_39, CALL_SUBTEST_4, CALL_SUBTEST_40, CALL_SUBTEST_41, CALL_SUBTEST_42, CALL_SUBTEST_43, CALL_SUBTEST_44, CALL_SUBTEST_45, CALL_SUBTEST_46, CALL_SUBTEST_47, CALL_SUBTEST_48, CALL_SUBTEST_49, CALL_SUBTEST_5, CALL_SUBTEST_6, CALL_SUBTEST_7, CALL_SUBTEST_8, CALL_SUBTEST_9, Eigen::ColPivHouseholderQRPreconditioner, compare_bdc_jacobi_instance(), EIGEN_TEST_MAX_SIZE, Eigen::g_repeat, Eigen::HouseholderQRPreconditioner, i, UniformPSDSelfTest::r, svd_all_trivial_2x2(), svd_check_max_size_matrix(), and TEST_SET_BUT_UNUSED_VARIABLE.