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

Classes

class  Foo::Bar
 

Namespaces

 Foo
 

Macros

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

Functions

template<typename MatrixType >
void jacobisvd_method ()
 
template<typename MatrixType >
void jacobisvd_thin_options (const MatrixType &input=MatrixType())
 
template<typename MatrixType >
void jacobisvd_full_options (const MatrixType &input=MatrixType())
 
template<typename MatrixType >
void jacobisvd_verify_assert (const MatrixType &input=MatrixType())
 
template<typename MatrixType >
void jacobisvd_verify_inputs (const MatrixType &input=MatrixType())
 
bool Foo::operator< (const Bar &, const Bar &)
 
void msvc_workaround ()
 
 EIGEN_DECLARE_TEST (jacobisvd)
 

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)    JacobiSVD<M>

◆ SVD_FOR_MIN_NORM

#define SVD_FOR_MIN_NORM (   M)    JacobiSVD<M, ColPivHouseholderQRPreconditioner>

◆ SVD_STATIC_OPTIONS

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

Function Documentation

◆ EIGEN_DECLARE_TEST()

EIGEN_DECLARE_TEST ( jacobisvd  )
115  {
116  CALL_SUBTEST_1((jacobisvd_verify_inputs<Matrix4d>()));
118  CALL_SUBTEST_3((jacobisvd_verify_inputs<Matrix<std::complex<double>, 7, 5>>()));
119 
120  CALL_SUBTEST_4((jacobisvd_verify_assert<Matrix3f>()));
121  CALL_SUBTEST_5((jacobisvd_verify_assert<Matrix4d>()));
124  CALL_SUBTEST_8((jacobisvd_verify_assert<MatrixXf>(MatrixXf(10, 12))));
125  CALL_SUBTEST_9((jacobisvd_verify_assert<MatrixXcd>(MatrixXcd(7, 5))));
126 
127  CALL_SUBTEST_10(svd_all_trivial_2x2(jacobisvd_thin_options<Matrix2cd>));
128  CALL_SUBTEST_11(svd_all_trivial_2x2(jacobisvd_thin_options<Matrix2d>));
129 
130  for (int i = 0; i < g_repeat; i++) {
131  int r = internal::random<int>(1, 30), c = internal::random<int>(1, 30);
132 
135 
136  CALL_SUBTEST_12((jacobisvd_thin_options<Matrix3f>()));
137  CALL_SUBTEST_13((jacobisvd_full_options<Matrix3f>()));
138  CALL_SUBTEST_14((jacobisvd_thin_options<Matrix4d>()));
139  CALL_SUBTEST_15((jacobisvd_full_options<Matrix4d>()));
150  CALL_SUBTEST_26((jacobisvd_thin_options<MatrixXf>(MatrixXf(r, c))));
151  CALL_SUBTEST_27((jacobisvd_full_options<MatrixXf>(MatrixXf(r, c))));
152  CALL_SUBTEST_28((jacobisvd_thin_options<MatrixXcd>(MatrixXcd(r, c))));
153  CALL_SUBTEST_29((jacobisvd_full_options<MatrixXcd>(MatrixXcd(r, c))));
154  CALL_SUBTEST_30((jacobisvd_thin_options<MatrixXd>(MatrixXd(r, c))));
155  CALL_SUBTEST_31((jacobisvd_full_options<MatrixXd>(MatrixXd(r, c))));
160 
161  MatrixXcd noQRTest = MatrixXcd(r, r);
162  svd_fill_random(noQRTest);
163  CALL_SUBTEST_36((svd_thin_option_checks<MatrixXcd, NoQRPreconditioner>(noQRTest)));
164  CALL_SUBTEST_36((svd_option_checks_full_only<MatrixXcd, NoQRPreconditioner>(noQRTest)));
165 
168  r, c)));
171  c)));
174  r, c)));
177  c)));
178 
179  // Test on inf/nan matrix
180  CALL_SUBTEST_41((svd_inf_nan<MatrixXf>()));
181  CALL_SUBTEST_42((svd_inf_nan<MatrixXd>()));
182 
187  }
188 
189  CALL_SUBTEST_47((jacobisvd_thin_options<MatrixXd>(
190  MatrixXd(internal::random<int>(EIGEN_TEST_MAX_SIZE / 4, EIGEN_TEST_MAX_SIZE / 2),
191  internal::random<int>(EIGEN_TEST_MAX_SIZE / 4, EIGEN_TEST_MAX_SIZE / 2)))));
192  CALL_SUBTEST_48((jacobisvd_full_options<MatrixXd>(
193  MatrixXd(internal::random<int>(EIGEN_TEST_MAX_SIZE / 4, EIGEN_TEST_MAX_SIZE / 2),
194  internal::random<int>(EIGEN_TEST_MAX_SIZE / 4, EIGEN_TEST_MAX_SIZE / 2)))));
195  CALL_SUBTEST_49((jacobisvd_thin_options<MatrixXcd>(
196  MatrixXcd(internal::random<int>(EIGEN_TEST_MAX_SIZE / 4, EIGEN_TEST_MAX_SIZE / 3),
197  internal::random<int>(EIGEN_TEST_MAX_SIZE / 4, EIGEN_TEST_MAX_SIZE / 3)))));
198  CALL_SUBTEST_50((jacobisvd_full_options<MatrixXcd>(
199  MatrixXcd(internal::random<int>(EIGEN_TEST_MAX_SIZE / 4, EIGEN_TEST_MAX_SIZE / 3),
200  internal::random<int>(EIGEN_TEST_MAX_SIZE / 4, EIGEN_TEST_MAX_SIZE / 3)))));
201 
202  // test matrixbase method
203  CALL_SUBTEST_51((jacobisvd_method<Matrix2cd>()));
204  CALL_SUBTEST_52((jacobisvd_method<Matrix3f>()));
205 
206  // Test problem size constructors
208 
209  // Check that preallocation avoids subsequent mallocs
210  CALL_SUBTEST_54(svd_preallocate<void>());
211 
212  CALL_SUBTEST_55(svd_underoverflow<void>());
213 
214  msvc_workaround();
215 }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
#define EIGEN_TEST_MAX_SIZE
Definition: boostmultiprec.cpp:16
Two-sided Jacobi SVD decomposition of a rectangular matrix.
Definition: JacobiSVD.h:500
The matrix class, also used for vectors and row-vectors.
Definition: Eigen/Eigen/src/Core/Matrix.h:186
@ HouseholderQRPreconditioner
Definition: Constants.h:425
@ ColPivHouseholderQRPreconditioner
Definition: Constants.h:421
void jacobisvd_verify_inputs(const MatrixType &input=MatrixType())
Definition: jacobisvd.cpp:74
void jacobisvd_thin_options(const MatrixType &input=MatrixType())
Definition: jacobisvd.cpp:37
void jacobisvd_full_options(const MatrixType &input=MatrixType())
Definition: jacobisvd.cpp:47
void jacobisvd_verify_assert(const MatrixType &input=MatrixType())
Definition: jacobisvd.cpp:59
void msvc_workaround()
Definition: jacobisvd.cpp:108
#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_54(FUNC)
Definition: split_test_helper.h:322
#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_50(FUNC)
Definition: split_test_helper.h:298
#define CALL_SUBTEST_53(FUNC)
Definition: split_test_helper.h:316
#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_55(FUNC)
Definition: split_test_helper.h:328
#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_51(FUNC)
Definition: split_test_helper.h:304
#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_52(FUNC)
Definition: split_test_helper.h:310
#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
void svd_fill_random(MatrixType &m, int Option=0)
Definition: svd_fill.h:27

References 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_50, CALL_SUBTEST_51, CALL_SUBTEST_52, CALL_SUBTEST_53, CALL_SUBTEST_54, CALL_SUBTEST_55, CALL_SUBTEST_6, CALL_SUBTEST_7, CALL_SUBTEST_8, CALL_SUBTEST_9, Eigen::ColPivHouseholderQRPreconditioner, EIGEN_TEST_MAX_SIZE, Eigen::g_repeat, Eigen::HouseholderQRPreconditioner, i, jacobisvd_full_options(), jacobisvd_thin_options(), jacobisvd_verify_assert(), jacobisvd_verify_inputs(), msvc_workaround(), UniformPSDSelfTest::r, svd_all_trivial_2x2(), svd_check_max_size_matrix(), svd_fill_random(), and TEST_SET_BUT_UNUSED_VARIABLE.

◆ jacobisvd_full_options()

template<typename MatrixType >
void jacobisvd_full_options ( const MatrixType input = MatrixType())
47  {
48  MatrixType m(input.rows(), input.cols());
50 
51  svd_option_checks_full_only<MatrixType, 0>(m);
52  svd_option_checks_full_only<MatrixType, ColPivHouseholderQRPreconditioner>(m);
53  svd_option_checks_full_only<MatrixType, HouseholderQRPreconditioner>(m);
54  svd_option_checks_full_only<MatrixType, FullPivHouseholderQRPreconditioner>(
55  m); // FullPiv only used when computing full unitaries
56 }
MatrixXf MatrixType
Definition: benchmark-blocking-sizes.cpp:52
int * m
Definition: level2_cplx_impl.h:294

References m, and svd_fill_random().

Referenced by EIGEN_DECLARE_TEST().

◆ jacobisvd_method()

template<typename MatrixType >
void jacobisvd_method ( )
23  {
24  enum { Size = MatrixType::RowsAtCompileTime };
25  typedef typename MatrixType::RealScalar RealScalar;
26  typedef Matrix<RealScalar, Size, 1> RealVecType;
27  MatrixType m = MatrixType::Identity();
28  VERIFY_IS_APPROX(m.jacobiSvd().singularValues(), RealVecType::Ones());
29  VERIFY_RAISES_ASSERT(m.jacobiSvd().matrixU());
30  VERIFY_RAISES_ASSERT(m.jacobiSvd().matrixV());
31  VERIFY_IS_APPROX(m.template jacobiSvd<ComputeFullU | ComputeFullV>().solve(m), m);
32  VERIFY_IS_APPROX(m.template jacobiSvd<ComputeFullU | ComputeFullV>().transpose().solve(m), m);
33  VERIFY_IS_APPROX(m.template jacobiSvd<ComputeFullU | ComputeFullV>().adjoint().solve(m), m);
34 }
NumTraits< Scalar >::Real RealScalar
Definition: bench_gemm.cpp:46
#define VERIFY_IS_APPROX(a, b)
Definition: integer_types.cpp:13
#define VERIFY_RAISES_ASSERT(a)
Definition: main.h:329

References m, VERIFY_IS_APPROX, and VERIFY_RAISES_ASSERT.

◆ jacobisvd_thin_options()

template<typename MatrixType >
void jacobisvd_thin_options ( const MatrixType input = MatrixType())
37  {
38  MatrixType m(input.rows(), input.cols());
40 
41  svd_thin_option_checks<MatrixType, 0>(m);
42  svd_thin_option_checks<MatrixType, ColPivHouseholderQRPreconditioner>(m);
43  svd_thin_option_checks<MatrixType, HouseholderQRPreconditioner>(m);
44 }

References m, and svd_fill_random().

Referenced by EIGEN_DECLARE_TEST().

◆ jacobisvd_verify_assert()

template<typename MatrixType >
void jacobisvd_verify_assert ( const MatrixType input = MatrixType())
59  {
60  MatrixType m(input.rows(), input.cols());
62  svd_verify_assert<MatrixType, 0>(m);
63  svd_verify_assert<MatrixType, ColPivHouseholderQRPreconditioner>(m);
64  svd_verify_assert<MatrixType, HouseholderQRPreconditioner>(m);
65  svd_verify_assert_full_only<MatrixType, FullPivHouseholderQRPreconditioner>(m);
66 
67  svd_verify_constructor_options_assert<JacobiSVD<MatrixType>>(m);
68  svd_verify_constructor_options_assert<JacobiSVD<MatrixType, ColPivHouseholderQRPreconditioner>>(m);
69  svd_verify_constructor_options_assert<JacobiSVD<MatrixType, HouseholderQRPreconditioner>>(m);
70  svd_verify_constructor_options_assert<JacobiSVD<MatrixType, FullPivHouseholderQRPreconditioner>>(m);
71 }

References m, and svd_fill_random().

Referenced by EIGEN_DECLARE_TEST().

◆ jacobisvd_verify_inputs()

template<typename MatrixType >
void jacobisvd_verify_inputs ( const MatrixType input = MatrixType())
74  {
75  // check defaults
76  typedef JacobiSVD<MatrixType> DefaultSVD;
77  MatrixType m(input.rows(), input.cols());
79  DefaultSVD defaultSvd(m);
80  VERIFY((int)DefaultSVD::QRPreconditioner == (int)ColPivHouseholderQRPreconditioner);
81  VERIFY(!defaultSvd.computeU());
82  VERIFY(!defaultSvd.computeV());
83 
84  // ColPivHouseholderQR is always default in presence of other options.
95 }
#define VERIFY(a)
Definition: main.h:362

References Eigen::ColPivHouseholderQRPreconditioner, m, svd_fill_random(), and VERIFY.

Referenced by EIGEN_DECLARE_TEST().

◆ msvc_workaround()

void msvc_workaround ( )
108  {
109  const Foo::Bar a;
110  const Foo::Bar b;
113 }
#define EIGEN_UNUSED_VARIABLE(var)
Definition: Macros.h:966
#define EIGEN_NOT_A_MACRO
Definition: Macros.h:813
Scalar * b
Definition: benchVecAdd.cpp:17
Definition: jacobisvd.cpp:100
#define max(a, b)
Definition: datatypes.h:23
const Scalar * a
Definition: level2_cplx_impl.h:32

References a, b, calibrate::c, EIGEN_NOT_A_MACRO, EIGEN_UNUSED_VARIABLE, and max.

Referenced by EIGEN_DECLARE_TEST().