miscmatrices.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) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
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 #include "main.h"
11 
12 template<typename MatrixType> void miscMatrices(const MatrixType& m)
13 {
14  /* this test covers the following files:
15  DiagonalMatrix.h Ones.h
16  */
17  typedef typename MatrixType::Scalar Scalar;
19  Index rows = m.rows();
20  Index cols = m.cols();
21 
22  Index r = internal::random<Index>(0, rows-1), r2 = internal::random<Index>(0, rows-1), c = internal::random<Index>(0, cols-1);
23  VERIFY_IS_APPROX(MatrixType::Ones(rows,cols)(r,c), static_cast<Scalar>(1));
24  MatrixType m1 = MatrixType::Ones(rows,cols);
25  VERIFY_IS_APPROX(m1(r,c), static_cast<Scalar>(1));
26  VectorType v1 = VectorType::Random(rows);
27  v1[0];
29  square(v1.asDiagonal());
30  if(r==r2) VERIFY_IS_APPROX(square(r,r2), v1[r]);
31  else VERIFY_IS_MUCH_SMALLER_THAN(square(r,r2), static_cast<Scalar>(1));
32  square = MatrixType::Zero(rows, rows);
33  square.diagonal() = VectorType::Ones(rows);
34  VERIFY_IS_APPROX(square, MatrixType::Identity(rows, rows));
35 }
36 
37 EIGEN_DECLARE_TEST(miscmatrices)
38 {
39  for(int i = 0; i < g_repeat; i++) {
41  CALL_SUBTEST_2( miscMatrices(Matrix4d()) );
42  CALL_SUBTEST_3( miscMatrices(MatrixXcf(3, 3)) );
43  CALL_SUBTEST_4( miscMatrices(MatrixXi(8, 12)) );
44  CALL_SUBTEST_5( miscMatrices(MatrixXcd(20, 20)) );
45  }
46 }
VERIFY_IS_MUCH_SMALLER_THAN
#define VERIFY_IS_MUCH_SMALLER_THAN(a, b)
Definition: main.h:390
EIGEN_DECLARE_TEST
EIGEN_DECLARE_TEST(miscmatrices)
Definition: miscmatrices.cpp:37
MatrixType
MatrixXf MatrixType
Definition: benchmark-blocking-sizes.cpp:52
r2
static const double r2
Definition: testSmartRangeFactor.cpp:32
c
Scalar Scalar * c
Definition: benchVecAdd.cpp:17
m1
Matrix3d m1
Definition: IOFormat.cpp:2
rows
int rows
Definition: Tutorial_commainit_02.cpp:1
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
square
const EIGEN_DEVICE_FUNC SquareReturnType square() const
Definition: ArrayCwiseUnaryOps.h:425
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_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::Matrix
The matrix class, also used for vectors and row-vectors.
Definition: 3rdparty/Eigen/Eigen/src/Core/Matrix.h:178
VectorType
Definition: FFTW.cpp:65
cols
int cols
Definition: Tutorial_commainit_02.cpp:1
miscMatrices
void miscMatrices(const MatrixType &m)
Definition: miscmatrices.cpp:12
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9
v1
Vector v1
Definition: testSerializationBase.cpp:38
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 Tue Jun 25 2024 03:01:44