bandmatrix.cpp
Go to the documentation of this file.
1 // This file is triangularView of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2008-2009 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 #include "main.h"
11 
12 template<typename MatrixType> void bandmatrix(const MatrixType& _m)
13 {
14  typedef typename MatrixType::Scalar Scalar;
15  typedef typename NumTraits<Scalar>::Real RealScalar;
16  typedef Matrix<Scalar,Dynamic,Dynamic> DenseMatrixType;
17 
18  Index rows = _m.rows();
19  Index cols = _m.cols();
20  Index supers = _m.supers();
21  Index subs = _m.subs();
22 
23  MatrixType m(rows,cols,supers,subs);
24 
25  DenseMatrixType dm1(rows,cols);
26  dm1.setZero();
27 
28  m.diagonal().setConstant(123);
29  dm1.diagonal().setConstant(123);
30  for (int i=1; i<=m.supers();++i)
31  {
32  m.diagonal(i).setConstant(static_cast<RealScalar>(i));
33  dm1.diagonal(i).setConstant(static_cast<RealScalar>(i));
34  }
35  for (int i=1; i<=m.subs();++i)
36  {
37  m.diagonal(-i).setConstant(-static_cast<RealScalar>(i));
38  dm1.diagonal(-i).setConstant(-static_cast<RealScalar>(i));
39  }
40  //std::cerr << m.m_data << "\n\n" << m.toDense() << "\n\n" << dm1 << "\n\n\n\n";
41  VERIFY_IS_APPROX(dm1,m.toDenseMatrix());
42 
43  for (int i=0; i<cols; ++i)
44  {
45  m.col(i).setConstant(static_cast<RealScalar>(i+1));
46  dm1.col(i).setConstant(static_cast<RealScalar>(i+1));
47  }
48  Index d = (std::min)(rows,cols);
49  Index a = std::max<Index>(0,cols-d-supers);
50  Index b = std::max<Index>(0,rows-d-subs);
51  if(a>0) dm1.block(0,d+supers,rows,a).setZero();
52  dm1.block(0,supers+1,cols-supers-1-a,cols-supers-1-a).template triangularView<Upper>().setZero();
53  dm1.block(subs+1,0,rows-subs-1-b,rows-subs-1-b).template triangularView<Lower>().setZero();
54  if(b>0) dm1.block(d+subs,0,b,cols).setZero();
55  //std::cerr << m.m_data << "\n\n" << m.toDense() << "\n\n" << dm1 << "\n\n";
56  VERIFY_IS_APPROX(dm1,m.toDenseMatrix());
57 
58 }
59 
61 
63 {
64  for(int i = 0; i < 10*g_repeat ; i++) {
65  Index rows = internal::random<Index>(1,10);
66  Index cols = internal::random<Index>(1,10);
67  Index sups = internal::random<Index>(0,cols-1);
68  Index subs = internal::random<Index>(0,rows-1);
69  CALL_SUBTEST(bandmatrix(BandMatrix<float>(rows,cols,sups,subs)) );
70  }
71 }
Matrix3f m
SCALAR Scalar
Definition: bench_gemm.cpp:46
EIGEN_DECLARE_TEST(bandmatrix)
Definition: bandmatrix.cpp:62
Scalar * b
Definition: benchVecAdd.cpp:17
#define min(a, b)
Definition: datatypes.h:19
Represents a rectangular matrix with a banded storage.
Definition: BandMatrix.h:199
MatrixXf MatrixType
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
Definition: NumTraits.h:232
void bandmatrix(const MatrixType &_m)
Definition: bandmatrix.cpp:12
#define VERIFY_IS_APPROX(a, b)
static int g_repeat
Definition: main.h:169
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74
NumTraits< Scalar >::Real RealScalar
Definition: bench_gemm.cpp:47
#define CALL_SUBTEST(FUNC)
Definition: main.h:399
A triangularView< Lower >().adjoint().solveInPlace(B)
v setZero(3)


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:33:56