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
sparse_ref.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) 20015 Gael Guennebaud <gael.guennebaud@inria.fr>
5
//
6
// This Source Code Form is subject to the terms of the Mozilla
7
// Public License v. 2.0. If a copy of the MPL was not distributed
8
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9
10
// This unit test cannot be easily written to work with EIGEN_DEFAULT_TO_ROW_MAJOR
11
#ifdef EIGEN_DEFAULT_TO_ROW_MAJOR
12
#undef EIGEN_DEFAULT_TO_ROW_MAJOR
13
#endif
14
15
static
long
int
nb_temporaries
;
16
17
inline
void
on_temporary_creation
() {
18
// here's a great place to set a breakpoint when debugging failures in this test!
19
nb_temporaries
++;
20
}
21
22
#define EIGEN_SPARSE_CREATE_TEMPORARY_PLUGIN { on_temporary_creation(); }
23
24
#include "
main.h
"
25
#include <Eigen/SparseCore>
26
27
#define VERIFY_EVALUATION_COUNT(XPR,N) {\
28
nb_temporaries = 0; \
29
CALL_SUBTEST( XPR ); \
30
if(nb_temporaries!=N) std::cerr << "nb_temporaries == " << nb_temporaries << "\n"; \
31
VERIFY( (#XPR) && nb_temporaries==N ); \
32
}
33
34
template
<
typename
PlainObjectType>
void
check_const_correctness
(
const
PlainObjectType&)
35
{
36
// verify that ref-to-const don't have LvalueBit
37
typedef
typename
internal::add_const<PlainObjectType>::type
ConstPlainObjectType;
38
VERIFY
( !(internal::traits<
Ref<ConstPlainObjectType>
>::Flags &
LvalueBit
) );
39
VERIFY
( !(internal::traits<
Ref<ConstPlainObjectType, Aligned>
>::Flags &
LvalueBit
) );
40
VERIFY
( !(
Ref<ConstPlainObjectType>::Flags
&
LvalueBit
) );
41
VERIFY
( !(
Ref<ConstPlainObjectType, Aligned>::Flags
&
LvalueBit
) );
42
}
43
44
template
<
typename
B>
45
EIGEN_DONT_INLINE
void
call_ref_1
(
Ref
<
SparseMatrix<float>
>
a
,
const
B
&
b
) {
VERIFY_IS_EQUAL
(
a
.toDense(),
b
.toDense()); }
46
47
template
<
typename
B>
48
EIGEN_DONT_INLINE
void
call_ref_2
(
const
Ref
<
const
SparseMatrix<float>
>&
a
,
const
B
&
b
) {
VERIFY_IS_EQUAL
(
a
.toDense(),
b
.toDense()); }
49
50
template
<
typename
B>
51
EIGEN_DONT_INLINE
void
call_ref_3
(
const
Ref
<
const
SparseMatrix<float>
,
StandardCompressedFormat
>&
a
,
const
B
&
b
) {
52
VERIFY
(
a
.isCompressed());
53
VERIFY_IS_EQUAL
(
a
.toDense(),
b
.toDense());
54
}
55
56
template
<
typename
B>
57
EIGEN_DONT_INLINE
void
call_ref_4
(
Ref
<
SparseVector<float>
>
a
,
const
B
&
b
) {
VERIFY_IS_EQUAL
(
a
.toDense(),
b
.toDense()); }
58
59
template
<
typename
B>
60
EIGEN_DONT_INLINE
void
call_ref_5
(
const
Ref
<
const
SparseVector<float>
>&
a
,
const
B
&
b
) {
VERIFY_IS_EQUAL
(
a
.toDense(),
b
.toDense()); }
61
62
void
call_ref
()
63
{
64
SparseMatrix<float>
A
= MatrixXf::Random(10,10).sparseView(0.5,1);
65
SparseMatrix<float,RowMajor>
B
= MatrixXf::Random(10,10).sparseView(0.5,1);
66
SparseMatrix<float>
C
= MatrixXf::Random(10,10).sparseView(0.5,1);
67
C
.reserve(VectorXi::Constant(
C
.outerSize(), 2));
68
const
SparseMatrix<float>
& Ac(
A
);
69
Block<SparseMatrix<float>
>
Ab
(
A
,0,1, 3,3);
70
const
Block<SparseMatrix<float>
> Abc(
A
,0,1,3,3);
71
SparseVector<float>
vc = VectorXf::Random(10).sparseView(0.5,1);
72
SparseVector<float,RowMajor>
vr = VectorXf::Random(10).sparseView(0.5,1);
73
SparseMatrix<float>
AA =
A
*
A
;
74
75
76
VERIFY_EVALUATION_COUNT
(
call_ref_1
(
A
,
A
), 0);
77
// VERIFY_EVALUATION_COUNT( call_ref_1(Ac, Ac), 0); // does not compile on purpose
78
VERIFY_EVALUATION_COUNT
(
call_ref_2
(
A
,
A
), 0);
79
VERIFY_EVALUATION_COUNT
(
call_ref_3
(
A
,
A
), 0);
80
VERIFY_EVALUATION_COUNT
(
call_ref_2
(
A
.transpose(),
A
.transpose()), 1);
81
VERIFY_EVALUATION_COUNT
(
call_ref_3
(
A
.transpose(),
A
.transpose()), 1);
82
VERIFY_EVALUATION_COUNT
(
call_ref_2
(Ac,Ac), 0);
83
VERIFY_EVALUATION_COUNT
(
call_ref_3
(Ac,Ac), 0);
84
VERIFY_EVALUATION_COUNT
(
call_ref_2
(
A
+
A
,2*Ac), 1);
85
VERIFY_EVALUATION_COUNT
(
call_ref_3
(
A
+
A
,2*Ac), 1);
86
VERIFY_EVALUATION_COUNT
(
call_ref_2
(
B
,
B
), 1);
87
VERIFY_EVALUATION_COUNT
(
call_ref_3
(
B
,
B
), 1);
88
VERIFY_EVALUATION_COUNT
(
call_ref_2
(
B
.transpose(),
B
.transpose()), 0);
89
VERIFY_EVALUATION_COUNT
(
call_ref_3
(
B
.transpose(),
B
.transpose()), 0);
90
VERIFY_EVALUATION_COUNT
(
call_ref_2
(
A
*
A
, AA), 3);
91
VERIFY_EVALUATION_COUNT
(
call_ref_3
(
A
*
A
, AA), 3);
92
93
VERIFY
(!
C
.isCompressed());
94
VERIFY_EVALUATION_COUNT
(
call_ref_3
(
C
,
C
), 1);
95
96
Ref<SparseMatrix<float>
> Ar(
A
);
97
VERIFY_IS_APPROX
(Ar+Ar,
A
+
A
);
98
VERIFY_EVALUATION_COUNT
(
call_ref_1
(Ar,
A
), 0);
99
VERIFY_EVALUATION_COUNT
(
call_ref_2
(Ar,
A
), 0);
100
101
Ref<SparseMatrix<float,RowMajor>
> Br(
B
);
102
VERIFY_EVALUATION_COUNT
(
call_ref_1
(Br.transpose(), Br.transpose()), 0);
103
VERIFY_EVALUATION_COUNT
(
call_ref_2
(Br, Br), 1);
104
VERIFY_EVALUATION_COUNT
(
call_ref_2
(Br.transpose(), Br.transpose()), 0);
105
106
Ref<const SparseMatrix<float>
> Arc(
A
);
107
// VERIFY_EVALUATION_COUNT( call_ref_1(Arc, Arc), 0); // does not compile on purpose
108
VERIFY_EVALUATION_COUNT
(
call_ref_2
(Arc, Arc), 0);
109
110
VERIFY_EVALUATION_COUNT
(
call_ref_2
(
A
.middleCols(1,3),
A
.middleCols(1,3)), 0);
111
112
VERIFY_EVALUATION_COUNT
(
call_ref_2
(
A
.col(2),
A
.col(2)), 0);
113
VERIFY_EVALUATION_COUNT
(
call_ref_2
(vc, vc), 0);
114
VERIFY_EVALUATION_COUNT
(
call_ref_2
(vr.transpose(), vr.transpose()), 0);
115
VERIFY_EVALUATION_COUNT
(
call_ref_2
(vr, vr.transpose()), 0);
116
117
VERIFY_EVALUATION_COUNT
(
call_ref_2
(
A
.block(1,1,3,3),
A
.block(1,1,3,3)), 1);
// should be 0 (allocate starts/nnz only)
118
119
VERIFY_EVALUATION_COUNT
(
call_ref_4
(vc, vc), 0);
120
VERIFY_EVALUATION_COUNT
(
call_ref_4
(vr, vr.transpose()), 0);
121
VERIFY_EVALUATION_COUNT
(
call_ref_5
(vc, vc), 0);
122
VERIFY_EVALUATION_COUNT
(
call_ref_5
(vr, vr.transpose()), 0);
123
VERIFY_EVALUATION_COUNT
(
call_ref_4
(
A
.col(2),
A
.col(2)), 0);
124
VERIFY_EVALUATION_COUNT
(
call_ref_5
(
A
.col(2),
A
.col(2)), 0);
125
// VERIFY_EVALUATION_COUNT( call_ref_4(A.row(2), A.row(2).transpose()), 1); // does not compile on purpose
126
VERIFY_EVALUATION_COUNT
(
call_ref_5
(
A
.row(2),
A
.row(2).transpose()), 1);
127
}
128
129
EIGEN_DECLARE_TEST
(sparse_ref)
130
{
131
for
(
int
i
= 0;
i
<
g_repeat
;
i
++) {
132
CALL_SUBTEST_1
(
check_const_correctness
(
SparseMatrix<float>
()) );
133
CALL_SUBTEST_1
(
check_const_correctness
(
SparseMatrix<double,RowMajor>
()) );
134
CALL_SUBTEST_2
(
call_ref
() );
135
136
CALL_SUBTEST_3
(
check_const_correctness
(
SparseVector<float>
()) );
137
CALL_SUBTEST_3
(
check_const_correctness
(
SparseVector<double,RowMajor>
()) );
138
}
139
}
Eigen::SparseMatrix
A versatible sparse matrix representation.
Definition:
SparseMatrix.h:96
B
Matrix< SCALARB, Dynamic, Dynamic, opt_B > B
Definition:
bench_gemm.cpp:49
Eigen::Block
Expression of a fixed-size or dynamic-size block.
Definition:
Block.h:103
gtsam.examples.DogLegOptimizerExample.type
type
Definition:
DogLegOptimizerExample.py:111
nb_temporaries
static long int nb_temporaries
Definition:
sparse_ref.cpp:15
VERIFY_IS_EQUAL
#define VERIFY_IS_EQUAL(a, b)
Definition:
main.h:386
b
Scalar * b
Definition:
benchVecAdd.cpp:17
call_ref_1
EIGEN_DONT_INLINE void call_ref_1(Ref< SparseMatrix< float > > a, const B &b)
Definition:
sparse_ref.cpp:45
call_ref_4
EIGEN_DONT_INLINE void call_ref_4(Ref< SparseVector< float > > a, const B &b)
Definition:
sparse_ref.cpp:57
VERIFY_EVALUATION_COUNT
#define VERIFY_EVALUATION_COUNT(XPR, N)
Definition:
sparse_ref.cpp:27
call_ref_5
EIGEN_DONT_INLINE void call_ref_5(const Ref< const SparseVector< float > > &a, const B &b)
Definition:
sparse_ref.cpp:60
A
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
Definition:
bench_gemm.cpp:48
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
Eigen::LvalueBit
const unsigned int LvalueBit
Definition:
Constants.h:144
call_ref
void call_ref()
Definition:
sparse_ref.cpp:62
Eigen::g_repeat
static int g_repeat
Definition:
main.h:169
Eigen::StandardCompressedFormat
@ StandardCompressedFormat
Definition:
SparseRef.h:16
call_ref_2
EIGEN_DONT_INLINE void call_ref_2(const Ref< const SparseMatrix< float > > &a, const B &b)
Definition:
sparse_ref.cpp:48
CALL_SUBTEST_2
#define CALL_SUBTEST_2(FUNC)
Definition:
split_test_helper.h:10
VERIFY_IS_APPROX
#define VERIFY_IS_APPROX(a, b)
Definition:
integer_types.cpp:15
a
ArrayXXi a
Definition:
Array_initializer_list_23_cxx11.cpp:1
Eigen::Ref
A matrix or vector expression mapping an existing expression.
Definition:
Ref.h:281
C
Matrix< Scalar, Dynamic, Dynamic > C
Definition:
bench_gemm.cpp:50
check_const_correctness
void check_const_correctness(const PlainObjectType &)
Definition:
sparse_ref.cpp:34
main.h
call_ref_3
EIGEN_DONT_INLINE void call_ref_3(const Ref< const SparseMatrix< float >, StandardCompressedFormat > &a, const B &b)
Definition:
sparse_ref.cpp:51
Eigen::SparseVector
a sparse vector class
Definition:
SparseUtil.h:54
EIGEN_DECLARE_TEST
EIGEN_DECLARE_TEST(sparse_ref)
Definition:
sparse_ref.cpp:129
exampleQR::Ab
Matrix Ab
Definition:
testNoiseModel.cpp:207
i
int i
Definition:
BiCGSTAB_step_by_step.cpp:9
on_temporary_creation
void on_temporary_creation()
Definition:
sparse_ref.cpp:17
VERIFY
#define VERIFY(a)
Definition:
main.h:380
EIGEN_DONT_INLINE
#define EIGEN_DONT_INLINE
Definition:
Macros.h:940
gtsam
Author(s):
autogenerated on Wed Mar 19 2025 03:03:43