product_trsolve.cpp File Reference
#include "main.h"

Macros

#define VERIFY_TRSM(TRI, XB)
 
#define VERIFY_TRSM_ONTHERIGHT(TRI, XB)
 

Functions

template<typename Scalar , int Size, int Cols>
void trsolve (int size=Size, int cols=Cols)
 
 EIGEN_DECLARE_TEST (product_trsolve)
 

Macro Definition Documentation

◆ VERIFY_TRSM

#define VERIFY_TRSM (   TRI,
  XB 
)
Value:
{ \
(XB).setRandom(); \
ref = (XB); \
(TRI).solveInPlace(XB); \
VERIFY_IS_APPROX((TRI).toDenseMatrix() * (XB), ref); \
(XB).setRandom(); \
ref = (XB); \
(XB) = (TRI).solve(XB); \
VERIFY_IS_APPROX((TRI).toDenseMatrix() * (XB), ref); \
}
A setRandom()

◆ VERIFY_TRSM_ONTHERIGHT

#define VERIFY_TRSM_ONTHERIGHT (   TRI,
  XB 
)
Value:
{ \
(XB).setRandom(); \
ref = (XB); \
(TRI).transpose().template solveInPlace<OnTheRight>(XB.transpose()); \
VERIFY_IS_APPROX((XB).transpose() * (TRI).transpose().toDenseMatrix(), ref.transpose()); \
(XB).setRandom(); \
ref = (XB); \
(XB).transpose() = (TRI).transpose().template solve<OnTheRight>(XB.transpose()); \
VERIFY_IS_APPROX((XB).transpose() * (TRI).transpose().toDenseMatrix(), ref.transpose()); \
}
void transpose()
Definition: skew_symmetric_matrix3.cpp:135

Function Documentation

◆ EIGEN_DECLARE_TEST()

EIGEN_DECLARE_TEST ( product_trsolve  )
111  {
112  for (int i = 0; i < g_repeat; i++) {
113  // matrices
114  CALL_SUBTEST_1((trsolve<float, Dynamic, Dynamic>(internal::random<int>(1, EIGEN_TEST_MAX_SIZE),
115  internal::random<int>(1, EIGEN_TEST_MAX_SIZE))));
116  CALL_SUBTEST_2((trsolve<double, Dynamic, Dynamic>(internal::random<int>(1, EIGEN_TEST_MAX_SIZE),
117  internal::random<int>(1, EIGEN_TEST_MAX_SIZE))));
118  CALL_SUBTEST_3((trsolve<std::complex<float>, Dynamic, Dynamic>(internal::random<int>(1, EIGEN_TEST_MAX_SIZE / 2),
119  internal::random<int>(1, EIGEN_TEST_MAX_SIZE / 2))));
120  CALL_SUBTEST_4((trsolve<std::complex<double>, Dynamic, Dynamic>(
121  internal::random<int>(1, EIGEN_TEST_MAX_SIZE / 2), internal::random<int>(1, EIGEN_TEST_MAX_SIZE / 2))));
122 
123  // vectors
124  CALL_SUBTEST_5((trsolve<float, Dynamic, 1>(internal::random<int>(1, EIGEN_TEST_MAX_SIZE))));
125  CALL_SUBTEST_6((trsolve<double, Dynamic, 1>(internal::random<int>(1, EIGEN_TEST_MAX_SIZE))));
126  CALL_SUBTEST_7((trsolve<std::complex<float>, Dynamic, 1>(internal::random<int>(1, EIGEN_TEST_MAX_SIZE))));
127  CALL_SUBTEST_8((trsolve<std::complex<double>, Dynamic, 1>(internal::random<int>(1, EIGEN_TEST_MAX_SIZE))));
128 
129  // meta-unrollers
130  CALL_SUBTEST_9((trsolve<float, 4, 1>()));
131  CALL_SUBTEST_10((trsolve<double, 4, 1>()));
132  CALL_SUBTEST_11((trsolve<std::complex<float>, 4, 1>()));
133  CALL_SUBTEST_12((trsolve<float, 1, 1>()));
134  CALL_SUBTEST_13((trsolve<float, 1, 2>()));
135  CALL_SUBTEST_14((trsolve<float, 3, 1>()));
136  }
137 }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
#define EIGEN_TEST_MAX_SIZE
Definition: boostmultiprec.cpp:16
static int g_repeat
Definition: main.h:191
const int Dynamic
Definition: Constants.h:25
void trsolve(int size=Size, int cols=Cols)
Definition: product_trsolve.cpp:37
#define CALL_SUBTEST_6(FUNC)
Definition: split_test_helper.h:34
#define CALL_SUBTEST_3(FUNC)
Definition: split_test_helper.h:16
#define CALL_SUBTEST_1(FUNC)
Definition: split_test_helper.h:4
#define CALL_SUBTEST_13(FUNC)
Definition: split_test_helper.h:76
#define CALL_SUBTEST_14(FUNC)
Definition: split_test_helper.h:82
#define CALL_SUBTEST_8(FUNC)
Definition: split_test_helper.h:46
#define CALL_SUBTEST_5(FUNC)
Definition: split_test_helper.h:28
#define CALL_SUBTEST_11(FUNC)
Definition: split_test_helper.h:64
#define CALL_SUBTEST_12(FUNC)
Definition: split_test_helper.h:70
#define CALL_SUBTEST_2(FUNC)
Definition: split_test_helper.h:10
#define CALL_SUBTEST_7(FUNC)
Definition: split_test_helper.h:40
#define CALL_SUBTEST_4(FUNC)
Definition: split_test_helper.h:22
#define CALL_SUBTEST_9(FUNC)
Definition: split_test_helper.h:52
#define CALL_SUBTEST_10(FUNC)
Definition: split_test_helper.h:58

References CALL_SUBTEST_1, CALL_SUBTEST_10, CALL_SUBTEST_11, CALL_SUBTEST_12, CALL_SUBTEST_13, CALL_SUBTEST_14, CALL_SUBTEST_2, CALL_SUBTEST_3, CALL_SUBTEST_4, CALL_SUBTEST_5, CALL_SUBTEST_6, CALL_SUBTEST_7, CALL_SUBTEST_8, CALL_SUBTEST_9, Eigen::Dynamic, EIGEN_TEST_MAX_SIZE, Eigen::g_repeat, i, and trsolve().

◆ trsolve()

template<typename Scalar , int Size, int Cols>
void trsolve ( int  size = Size,
int  cols = Cols 
)
37  {
38  typedef typename NumTraits<Scalar>::Real RealScalar;
39 
42 
43  enum { colmajor = Size == 1 ? RowMajor : ColMajor, rowmajor = Cols == 1 ? ColMajor : RowMajor };
47 
48  cmLhs.setRandom();
49  cmLhs *= static_cast<RealScalar>(0.1);
50  cmLhs.diagonal().array() += static_cast<RealScalar>(1);
51  rmLhs.setRandom();
52  rmLhs *= static_cast<RealScalar>(0.1);
53  rmLhs.diagonal().array() += static_cast<RealScalar>(1);
54 
55  VERIFY_TRSM(cmLhs.conjugate().template triangularView<Lower>(), cmRhs);
56  VERIFY_TRSM(cmLhs.adjoint().template triangularView<Lower>(), cmRhs);
57  VERIFY_TRSM(cmLhs.template triangularView<Upper>(), cmRhs);
58  VERIFY_TRSM(cmLhs.template triangularView<Lower>(), rmRhs);
59  VERIFY_TRSM(cmLhs.conjugate().template triangularView<Upper>(), rmRhs);
60  VERIFY_TRSM(cmLhs.adjoint().template triangularView<Upper>(), rmRhs);
61 
62  VERIFY_TRSM(cmLhs.conjugate().template triangularView<UnitLower>(), cmRhs);
63  VERIFY_TRSM(cmLhs.template triangularView<UnitUpper>(), rmRhs);
64 
65  VERIFY_TRSM(rmLhs.template triangularView<Lower>(), cmRhs);
66  VERIFY_TRSM(rmLhs.conjugate().template triangularView<UnitUpper>(), rmRhs);
67 
68  VERIFY_TRSM_ONTHERIGHT(cmLhs.conjugate().template triangularView<Lower>(), cmRhs);
69  VERIFY_TRSM_ONTHERIGHT(cmLhs.template triangularView<Upper>(), cmRhs);
70  VERIFY_TRSM_ONTHERIGHT(cmLhs.template triangularView<Lower>(), rmRhs);
71  VERIFY_TRSM_ONTHERIGHT(cmLhs.conjugate().template triangularView<Upper>(), rmRhs);
72 
73  VERIFY_TRSM_ONTHERIGHT(cmLhs.conjugate().template triangularView<UnitLower>(), cmRhs);
74  VERIFY_TRSM_ONTHERIGHT(cmLhs.template triangularView<UnitUpper>(), rmRhs);
75 
76  VERIFY_TRSM_ONTHERIGHT(rmLhs.template triangularView<Lower>(), cmRhs);
77  VERIFY_TRSM_ONTHERIGHT(rmLhs.conjugate().template triangularView<UnitUpper>(), rmRhs);
78 
79  int c = internal::random<int>(0, cols - 1);
80  VERIFY_TRSM(rmLhs.template triangularView<Lower>(), rmRhs.col(c));
81  VERIFY_TRSM(cmLhs.template triangularView<Lower>(), rmRhs.col(c));
82 
83  // destination with a non-default inner-stride
84  // see bug 1741
85  {
86  typedef Matrix<Scalar, Dynamic, Dynamic> MatrixX;
87  MatrixX buffer(2 * cmRhs.rows(), 2 * cmRhs.cols());
89  buffer.data(), cmRhs.rows(), cmRhs.cols(), Stride<Dynamic, 2>(2 * cmRhs.outerStride(), 2));
91  buffer.data(), rmRhs.rows(), rmRhs.cols(), Stride<Dynamic, 2>(2 * rmRhs.outerStride(), 2));
92  buffer.setZero();
93  VERIFY_TRSM(cmLhs.conjugate().template triangularView<Lower>(), map1);
94  buffer.setZero();
95  VERIFY_TRSM(cmLhs.template triangularView<Lower>(), map2);
96  }
97 
98  if (Size == Dynamic) {
99  cmLhs.resize(0, 0);
100  cmRhs.resize(0, cmRhs.cols());
101  Matrix<Scalar, Size, Cols, colmajor> res = cmLhs.template triangularView<Lower>().solve(cmRhs);
102  VERIFY_IS_EQUAL(res.rows(), 0);
103  VERIFY_IS_EQUAL(res.cols(), cmRhs.cols());
104  res = cmRhs;
105  cmLhs.template triangularView<Lower>().solveInPlace(res);
106  VERIFY_IS_EQUAL(res.rows(), 0);
107  VERIFY_IS_EQUAL(res.cols(), cmRhs.cols());
108  }
109 }
cout<< "Here is the matrix m:"<< endl<< m<< endl;Matrix< ptrdiff_t, 3, 1 > res
Definition: PartialRedux_count.cpp:3
int cols
Definition: Tutorial_commainit_02.cpp:1
Scalar Scalar int size
Definition: benchVecAdd.cpp:17
NumTraits< Scalar >::Real RealScalar
Definition: bench_gemm.cpp:46
A matrix or vector expression mapping an existing array of data.
Definition: Map.h:96
The matrix class, also used for vectors and row-vectors.
Definition: Eigen/Eigen/src/Core/Matrix.h:186
Holds strides information for Map.
Definition: Stride.h:55
@ ColMajor
Definition: Constants.h:318
@ RowMajor
Definition: Constants.h:320
#define VERIFY_IS_EQUAL(a, b)
Definition: main.h:367
int c
Definition: calibrate.py:100
#define VERIFY_TRSM(TRI, XB)
Definition: product_trsolve.cpp:12
#define VERIFY_TRSM_ONTHERIGHT(TRI, XB)
Definition: product_trsolve.cpp:24
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition: NumTraits.h:217

References calibrate::c, Eigen::ColMajor, cols, Eigen::PlainObjectBase< Derived >::cols(), Eigen::Dynamic, Eigen::Matrix< Scalar_, Rows_, Cols_, Options_, MaxRows_, MaxCols_ >::outerStride(), res, Eigen::PlainObjectBase< Derived >::resize(), Eigen::RowMajor, Eigen::PlainObjectBase< Derived >::rows(), Eigen::PlainObjectBase< Derived >::setRandom(), size, VERIFY_IS_EQUAL, VERIFY_TRSM, and VERIFY_TRSM_ONTHERIGHT.

Referenced by EIGEN_DECLARE_TEST().