gtsam
3rdparty
Eigen
test
determinant.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) 2008 Benoit Jacob <jacob.benoit.1@gmail.com>
5
// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
6
//
7
// This Source Code Form is subject to the terms of the Mozilla
8
// Public License v. 2.0. If a copy of the MPL was not distributed
9
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
10
11
#include "
main.h
"
12
#include <Eigen/LU>
13
14
template
<
typename
MatrixType>
void
determinant
(
const
MatrixType
&
m
)
15
{
16
/* this test covers the following files:
17
Determinant.h
18
*/
19
Index
size
=
m
.rows();
20
21
MatrixType
m1
(
size
,
size
),
m2
(
size
,
size
);
22
m1
.setRandom();
23
m2
.setRandom();
24
typedef
typename
MatrixType::Scalar
Scalar
;
25
Scalar
x
= internal::random<Scalar>();
26
VERIFY_IS_APPROX
(MatrixType::Identity(
size
,
size
).
determinant
(),
Scalar
(1));
27
VERIFY_IS_APPROX
((
m1
*
m2
).
eval
().
determinant
(),
m1
.determinant() *
m2
.determinant());
28
if
(
size
==1)
return
;
29
Index
i
= internal::random<Index>(0,
size
-1);
30
Index
j
;
31
do
{
32
j
= internal::random<Index>(0,
size
-1);
33
}
while
(
j
==
i
);
34
m2
=
m1
;
35
m2
.row(
i
).swap(
m2
.row(
j
));
36
VERIFY_IS_APPROX
(
m2
.determinant(), -
m1
.determinant());
37
m2
=
m1
;
38
m2
.col(
i
).swap(
m2
.col(
j
));
39
VERIFY_IS_APPROX
(
m2
.determinant(), -
m1
.determinant());
40
VERIFY_IS_APPROX
(
m2
.determinant(),
m2
.transpose().determinant());
41
VERIFY_IS_APPROX
(
numext::conj
(
m2
.determinant()),
m2
.adjoint().determinant());
42
m2
=
m1
;
43
m2
.row(
i
) +=
x
*
m2
.row(
j
);
44
VERIFY_IS_APPROX
(
m2
.determinant(),
m1
.determinant());
45
m2
=
m1
;
46
m2
.row(
i
) *=
x
;
47
VERIFY_IS_APPROX
(
m2
.determinant(),
m1
.determinant() *
x
);
48
49
// check empty matrix
50
VERIFY_IS_APPROX
(
m2
.block(0,0,0,0).determinant(),
Scalar
(1));
51
}
52
53
EIGEN_DECLARE_TEST
(
determinant
)
54
{
55
for
(
int
i
= 0;
i
<
g_repeat
;
i
++) {
56
int
s
= 0;
57
CALL_SUBTEST_1
(
determinant
(
Matrix<float, 1, 1>
()) );
58
CALL_SUBTEST_2
(
determinant
(
Matrix<double, 2, 2>
()) );
59
CALL_SUBTEST_3
(
determinant
(
Matrix<double, 3, 3>
()) );
60
CALL_SUBTEST_4
(
determinant
(
Matrix<double, 4, 4>
()) );
61
CALL_SUBTEST_5
(
determinant
(
Matrix
<std::complex<double>, 10, 10>()) );
62
s
= internal::random<int>(1,
EIGEN_TEST_MAX_SIZE
/4);
63
CALL_SUBTEST_6
(
determinant
(MatrixXd(
s
,
s
)) );
64
TEST_SET_BUT_UNUSED_VARIABLE
(
s
)
65
}
66
}
s
RealScalar s
Definition:
level1_cplx_impl.h:126
MatrixType
MatrixXf MatrixType
Definition:
benchmark-blocking-sizes.cpp:52
x
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
Definition:
gnuplot_common_settings.hh:12
m1
Matrix3d m1
Definition:
IOFormat.cpp:2
determinant
void determinant(const MatrixType &m)
Definition:
determinant.cpp:14
size
Scalar Scalar int size
Definition:
benchVecAdd.cpp:17
CALL_SUBTEST_4
#define CALL_SUBTEST_4(FUNC)
Definition:
split_test_helper.h:22
m2
MatrixType m2(n_dims)
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
j
std::ptrdiff_t j
Definition:
tut_arithmetic_redux_minmax.cpp:2
EIGEN_DECLARE_TEST
EIGEN_DECLARE_TEST(determinant)
Definition:
determinant.cpp:53
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
conj
AnnoyingScalar conj(const AnnoyingScalar &x)
Definition:
AnnoyingScalar.h:104
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
VERIFY_IS_APPROX
#define VERIFY_IS_APPROX(a, b)
Definition:
integer_types.cpp:15
main.h
EIGEN_TEST_MAX_SIZE
#define EIGEN_TEST_MAX_SIZE
Definition:
boostmultiprec.cpp:16
Eigen::Matrix
The matrix class, also used for vectors and row-vectors.
Definition:
3rdparty/Eigen/Eigen/src/Core/Matrix.h:178
eval
internal::nested_eval< T, 1 >::type eval(const T &xpr)
Definition:
sparse_permutations.cpp:38
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
Scalar
SCALAR Scalar
Definition:
bench_gemm.cpp:46
Eigen::Index
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition:
Meta.h:74
gtsam
Author(s):
autogenerated on Thu Dec 19 2024 04:01:02