Main Page
Related Pages
Modules
Namespaces
Namespace List
Namespace Members
All
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Functions
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Variables
_
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Typedefs
_
a
b
c
d
e
f
g
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
y
Enumerations
a
c
d
e
f
g
i
k
l
m
n
p
q
r
s
t
u
Enumerator
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
r
s
t
u
v
w
x
z
Classes
Class List
Class Hierarchy
Class Members
All
!
:
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
~
Functions
!
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
~
Variables
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Typedefs
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
z
Enumerations
a
b
c
d
f
k
l
m
n
o
p
r
s
t
v
z
Enumerator
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Related Functions
:
a
b
c
d
e
g
h
i
l
m
n
o
p
r
s
t
u
v
Files
File List
File Members
All
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Functions
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Variables
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Typedefs
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
x
z
Enumerations
Enumerator
b
c
e
f
g
i
l
m
n
o
p
r
s
t
u
v
x
y
z
Macros
_
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
x
z
Examples
gtsam
3rdparty
Eigen
test
bdcsvd.cpp
Go to the documentation of this file.
1
// This file is part of Eigen, a lightweight C++ template library
2
// for linear algebra.
3
//
4
// Copyright (C) 2013 Gauthier Brun <brun.gauthier@gmail.com>
5
// Copyright (C) 2013 Nicolas Carre <nicolas.carre@ensimag.fr>
6
// Copyright (C) 2013 Jean Ceccato <jean.ceccato@ensimag.fr>
7
// Copyright (C) 2013 Pierre Zoppitelli <pierre.zoppitelli@ensimag.fr>
8
//
9
// This Source Code Form is subject to the terms of the Mozilla
10
// Public License v. 2.0. If a copy of the MPL was not distributed
11
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/
12
13
// discard stack allocation as that too bypasses malloc
14
#define EIGEN_STACK_ALLOCATION_LIMIT 0
15
#define EIGEN_RUNTIME_NO_MALLOC
16
17
#include "
main.h
"
18
#include <Eigen/SVD>
19
#include <iostream>
20
#include <Eigen/LU>
21
22
23
#define SVD_DEFAULT(M) BDCSVD<M>
24
#define SVD_FOR_MIN_NORM(M) BDCSVD<M>
25
#include "
svd_common.h
"
26
27
// Check all variants of JacobiSVD
28
template
<
typename
MatrixType>
29
void
bdcsvd
(
const
MatrixType
&
a
=
MatrixType
(),
bool
pickrandom =
true
)
30
{
31
MatrixType
m
;
32
if
(pickrandom) {
33
m
.resizeLike(
a
);
34
svd_fill_random
(
m
);
35
}
36
else
37
m
=
a
;
38
39
CALL_SUBTEST
((
svd_test_all_computation_options
<
BDCSVD<MatrixType>
>(
m
,
false
) ));
40
}
41
42
template
<
typename
MatrixType>
43
void
bdcsvd_method
()
44
{
45
enum
{ Size = MatrixType::RowsAtCompileTime };
46
typedef
typename
MatrixType::RealScalar
RealScalar
;
47
typedef
Matrix<RealScalar, Size, 1>
RealVecType;
48
MatrixType
m
= MatrixType::Identity();
49
VERIFY_IS_APPROX
(
m
.bdcSvd().singularValues(), RealVecType::Ones());
50
VERIFY_RAISES_ASSERT
(
m
.bdcSvd().matrixU());
51
VERIFY_RAISES_ASSERT
(
m
.bdcSvd().matrixV());
52
VERIFY_IS_APPROX
(
m
.bdcSvd(
ComputeFullU
|
ComputeFullV
).solve(
m
),
m
);
53
VERIFY_IS_APPROX
(
m
.bdcSvd(
ComputeFullU
|
ComputeFullV
).transpose().solve(
m
),
m
);
54
VERIFY_IS_APPROX
(
m
.bdcSvd(
ComputeFullU
|
ComputeFullV
).adjoint().solve(
m
),
m
);
55
}
56
57
// compare the Singular values returned with Jacobi and Bdc
58
template
<
typename
MatrixType>
59
void
compare_bdc_jacobi
(
const
MatrixType
&
a
=
MatrixType
(),
unsigned
int
computationOptions = 0)
60
{
61
MatrixType
m
= MatrixType::Random(
a
.rows(),
a
.cols());
62
BDCSVD<MatrixType>
bdc_svd(
m
);
63
JacobiSVD<MatrixType>
jacobi_svd(
m
);
64
VERIFY_IS_APPROX
(bdc_svd.singularValues(), jacobi_svd.singularValues());
65
if
(computationOptions &
ComputeFullU
)
VERIFY_IS_APPROX
(bdc_svd.matrixU(), jacobi_svd.matrixU());
66
if
(computationOptions &
ComputeThinU
)
VERIFY_IS_APPROX
(bdc_svd.matrixU(), jacobi_svd.matrixU());
67
if
(computationOptions &
ComputeFullV
)
VERIFY_IS_APPROX
(bdc_svd.matrixV(), jacobi_svd.matrixV());
68
if
(computationOptions &
ComputeThinV
)
VERIFY_IS_APPROX
(bdc_svd.matrixV(), jacobi_svd.matrixV());
69
}
70
71
EIGEN_DECLARE_TEST
(
bdcsvd
)
72
{
73
CALL_SUBTEST_3
((
svd_verify_assert
<
BDCSVD<Matrix3f>
>(Matrix3f()) ));
74
CALL_SUBTEST_4
((
svd_verify_assert
<
BDCSVD<Matrix4d>
>(Matrix4d()) ));
75
CALL_SUBTEST_7
((
svd_verify_assert
<
BDCSVD<MatrixXf>
>(MatrixXf(10,12)) ));
76
CALL_SUBTEST_8
((
svd_verify_assert
<
BDCSVD<MatrixXcd>
>(MatrixXcd(7,5)) ));
77
78
CALL_SUBTEST_101
((
svd_all_trivial_2x2
(bdcsvd<Matrix2cd>) ));
79
CALL_SUBTEST_102
((
svd_all_trivial_2x2
(bdcsvd<Matrix2d>) ));
80
81
for
(
int
i
= 0;
i
<
g_repeat
;
i
++) {
82
CALL_SUBTEST_3
(( bdcsvd<Matrix3f>() ));
83
CALL_SUBTEST_4
(( bdcsvd<Matrix4d>() ));
84
CALL_SUBTEST_5
((
bdcsvd
<
Matrix<float,3,5>
>() ));
85
86
int
r = internal::random<int>(1,
EIGEN_TEST_MAX_SIZE
/2),
87
c
= internal::random<int>(1,
EIGEN_TEST_MAX_SIZE
/2);
88
89
TEST_SET_BUT_UNUSED_VARIABLE
(r)
90
TEST_SET_BUT_UNUSED_VARIABLE
(
c
)
91
92
CALL_SUBTEST_6
((
bdcsvd
(
Matrix<double,Dynamic,2>
(r,2)) ));
93
CALL_SUBTEST_7
((
bdcsvd
(MatrixXf(r,
c
)) ));
94
CALL_SUBTEST_7
((
compare_bdc_jacobi
(MatrixXf(r,
c
)) ));
95
CALL_SUBTEST_10
((
bdcsvd
(MatrixXd(r,
c
)) ));
96
CALL_SUBTEST_10
((
compare_bdc_jacobi
(MatrixXd(r,
c
)) ));
97
CALL_SUBTEST_8
((
bdcsvd
(MatrixXcd(r,
c
)) ));
98
CALL_SUBTEST_8
((
compare_bdc_jacobi
(MatrixXcd(r,
c
)) ));
99
100
// Test on inf/nan matrix
101
CALL_SUBTEST_7
( (
svd_inf_nan
<
BDCSVD<MatrixXf>
, MatrixXf>()) );
102
CALL_SUBTEST_10
( (
svd_inf_nan
<
BDCSVD<MatrixXd>
, MatrixXd>()) );
103
}
104
105
// test matrixbase method
106
CALL_SUBTEST_1
(( bdcsvd_method<Matrix2cd>() ));
107
CALL_SUBTEST_3
(( bdcsvd_method<Matrix3f>() ));
108
109
// Test problem size constructors
110
CALL_SUBTEST_7
(
BDCSVD<MatrixXf>
(10,10) );
111
112
// Check that preallocation avoids subsequent mallocs
113
// Disabled because not supported by BDCSVD
114
// CALL_SUBTEST_9( svd_preallocate<void>() );
115
116
CALL_SUBTEST_2
( svd_underoverflow<void>() );
117
}
118
bdcsvd_method
void bdcsvd_method()
Definition:
bdcsvd.cpp:43
Eigen::ComputeFullV
@ ComputeFullV
Definition:
Constants.h:397
MatrixType
MatrixXf MatrixType
Definition:
benchmark-blocking-sizes.cpp:52
CALL_SUBTEST_101
#define CALL_SUBTEST_101(FUNC)
Definition:
split_test_helper.h:604
c
Scalar Scalar * c
Definition:
benchVecAdd.cpp:17
Eigen::ComputeFullU
@ ComputeFullU
Definition:
Constants.h:393
svd_inf_nan
void svd_inf_nan()
Definition:
svd_common.h:304
VERIFY_RAISES_ASSERT
#define VERIFY_RAISES_ASSERT(a)
Definition:
main.h:340
svd_verify_assert
void svd_verify_assert(const MatrixType &m, bool fullOnly=false)
Definition:
svd_common.h:465
CALL_SUBTEST_4
#define CALL_SUBTEST_4(FUNC)
Definition:
split_test_helper.h:22
CALL_SUBTEST_3
#define CALL_SUBTEST_3(FUNC)
Definition:
split_test_helper.h:16
CALL_SUBTEST_1
#define CALL_SUBTEST_1(FUNC)
Definition:
split_test_helper.h:4
svd_fill_random
void svd_fill_random(MatrixType &m, int Option=0)
Definition:
svd_fill.h:21
Eigen::ComputeThinU
@ ComputeThinU
Definition:
Constants.h:395
svd_all_trivial_2x2
void svd_all_trivial_2x2(void(*cb)(const MatrixType &, bool))
Definition:
svd_common.h:401
svd_common.h
Eigen::BDCSVD
class Bidiagonal Divide and Conquer SVD
Definition:
ForwardDeclarations.h:279
CALL_SUBTEST_10
#define CALL_SUBTEST_10(FUNC)
Definition:
split_test_helper.h:58
CALL_SUBTEST_5
#define CALL_SUBTEST_5(FUNC)
Definition:
split_test_helper.h:28
Eigen::g_repeat
static int g_repeat
Definition:
main.h:169
m
Matrix3f m
Definition:
AngleAxis_mimic_euler.cpp:1
CALL_SUBTEST_6
#define CALL_SUBTEST_6(FUNC)
Definition:
split_test_helper.h:34
CALL_SUBTEST_2
#define CALL_SUBTEST_2(FUNC)
Definition:
split_test_helper.h:10
CALL_SUBTEST_102
#define CALL_SUBTEST_102(FUNC)
Definition:
split_test_helper.h:610
VERIFY_IS_APPROX
#define VERIFY_IS_APPROX(a, b)
Definition:
integer_types.cpp:15
RealScalar
NumTraits< Scalar >::Real RealScalar
Definition:
bench_gemm.cpp:47
Eigen::JacobiSVD
Two-sided Jacobi SVD decomposition of a rectangular matrix.
Definition:
ForwardDeclarations.h:278
a
ArrayXXi a
Definition:
Array_initializer_list_23_cxx11.cpp:1
Eigen::ComputeThinV
@ ComputeThinV
Definition:
Constants.h:399
main.h
EIGEN_TEST_MAX_SIZE
#define EIGEN_TEST_MAX_SIZE
Definition:
boostmultiprec.cpp:16
compare_bdc_jacobi
void compare_bdc_jacobi(const MatrixType &a=MatrixType(), unsigned int computationOptions=0)
Definition:
bdcsvd.cpp:59
svd_test_all_computation_options
void svd_test_all_computation_options(const MatrixType &m, bool full_only)
Definition:
svd_common.h:244
Eigen::Matrix
The matrix class, also used for vectors and row-vectors.
Definition:
3rdparty/Eigen/Eigen/src/Core/Matrix.h:178
bdcsvd
void bdcsvd(const MatrixType &a=MatrixType(), bool pickrandom=true)
Definition:
bdcsvd.cpp:29
CALL_SUBTEST_7
#define CALL_SUBTEST_7(FUNC)
Definition:
split_test_helper.h:40
CALL_SUBTEST_8
#define CALL_SUBTEST_8(FUNC)
Definition:
split_test_helper.h:46
i
int i
Definition:
BiCGSTAB_step_by_step.cpp:9
TEST_SET_BUT_UNUSED_VARIABLE
#define TEST_SET_BUT_UNUSED_VARIABLE(X)
Definition:
main.h:121
CALL_SUBTEST
#define CALL_SUBTEST(FUNC)
Definition:
main.h:399
EIGEN_DECLARE_TEST
EIGEN_DECLARE_TEST(bdcsvd)
Definition:
bdcsvd.cpp:71
gtsam
Author(s):
autogenerated on Wed Mar 19 2025 03:01:18