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 
38 {
39  for(int i = 0; i < g_repeat; i++) {
40  CALL_SUBTEST_1( miscMatrices(Matrix<float, 1, 1>()) );
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 }
Matrix3f m
SCALAR Scalar
Definition: bench_gemm.cpp:33
Vector v1
void test_miscmatrices()
Scalar Scalar * c
Definition: benchVecAdd.cpp:17
MatrixXf MatrixType
#define VERIFY_IS_APPROX(a, b)
void miscMatrices(const MatrixType &m)
Matrix3d m1
Definition: IOFormat.cpp:2
static int g_repeat
Definition: main.h:144
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33
static const double r2
#define VERIFY_IS_MUCH_SMALLER_THAN(a, b)
Definition: main.h:335
The matrix class, also used for vectors and row-vectors.
EIGEN_DEVICE_FUNC const SquareReturnType square() const


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:43:01