MCPcopy Create free account
hub / github.com/PX4/eigen / nomalloc

Function nomalloc

test/nomalloc.cpp:23–90  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21#include <Eigen/SVD>
22
23template<typename MatrixType> void nomalloc(const MatrixType& m)
24{
25 /* this test check no dynamic memory allocation are issued with fixed-size matrices
26 */
27 typedef typename MatrixType::Index Index;
28 typedef typename MatrixType::Scalar Scalar;
29
30 Index rows = m.rows();
31 Index cols = m.cols();
32
33 MatrixType m1 = MatrixType::Random(rows, cols),
34 m2 = MatrixType::Random(rows, cols),
35 m3(rows, cols);
36
37 Scalar s1 = internal::random<Scalar>();
38
39 Index r = internal::random<Index>(0, rows-1),
40 c = internal::random<Index>(0, cols-1);
41
42 VERIFY_IS_APPROX((m1+m2)*s1, s1*m1+s1*m2);
43 VERIFY_IS_APPROX((m1+m2)(r,c), (m1(r,c))+(m2(r,c)));
44 VERIFY_IS_APPROX(m1.cwiseProduct(m1.block(0,0,rows,cols)), (m1.array()*m1.array()).matrix());
45 VERIFY_IS_APPROX((m1*m1.transpose())*m2, m1*(m1.transpose()*m2));
46
47 m2.col(0).noalias() = m1 * m1.col(0);
48 m2.col(0).noalias() -= m1.adjoint() * m1.col(0);
49 m2.col(0).noalias() -= m1 * m1.row(0).adjoint();
50 m2.col(0).noalias() -= m1.adjoint() * m1.row(0).adjoint();
51
52 m2.row(0).noalias() = m1.row(0) * m1;
53 m2.row(0).noalias() -= m1.row(0) * m1.adjoint();
54 m2.row(0).noalias() -= m1.col(0).adjoint() * m1;
55 m2.row(0).noalias() -= m1.col(0).adjoint() * m1.adjoint();
56 VERIFY_IS_APPROX(m2,m2);
57
58 m2.col(0).noalias() = m1.template triangularView<Upper>() * m1.col(0);
59 m2.col(0).noalias() -= m1.adjoint().template triangularView<Upper>() * m1.col(0);
60 m2.col(0).noalias() -= m1.template triangularView<Upper>() * m1.row(0).adjoint();
61 m2.col(0).noalias() -= m1.adjoint().template triangularView<Upper>() * m1.row(0).adjoint();
62
63 m2.row(0).noalias() = m1.row(0) * m1.template triangularView<Upper>();
64 m2.row(0).noalias() -= m1.row(0) * m1.adjoint().template triangularView<Upper>();
65 m2.row(0).noalias() -= m1.col(0).adjoint() * m1.template triangularView<Upper>();
66 m2.row(0).noalias() -= m1.col(0).adjoint() * m1.adjoint().template triangularView<Upper>();
67 VERIFY_IS_APPROX(m2,m2);
68
69 m2.col(0).noalias() = m1.template selfadjointView<Upper>() * m1.col(0);
70 m2.col(0).noalias() -= m1.adjoint().template selfadjointView<Upper>() * m1.col(0);
71 m2.col(0).noalias() -= m1.template selfadjointView<Upper>() * m1.row(0).adjoint();
72 m2.col(0).noalias() -= m1.adjoint().template selfadjointView<Upper>() * m1.row(0).adjoint();
73
74 m2.row(0).noalias() = m1.row(0) * m1.template selfadjointView<Upper>();
75 m2.row(0).noalias() -= m1.row(0) * m1.adjoint().template selfadjointView<Upper>();
76 m2.row(0).noalias() -= m1.col(0).adjoint() * m1.template selfadjointView<Upper>();
77 m2.row(0).noalias() -= m1.col(0).adjoint() * m1.adjoint().template selfadjointView<Upper>();
78 VERIFY_IS_APPROX(m2,m2);
79
80 m2.template selfadjointView<Lower>().rankUpdate(m1.col(0),-1);

Callers 1

test_nomallocFunction · 0.85

Calls 11

noaliasMethod · 0.80
rowsMethod · 0.45
colsMethod · 0.45
cwiseProductMethod · 0.45
matrixMethod · 0.45
arrayMethod · 0.45
transposeMethod · 0.45
colMethod · 0.45
adjointMethod · 0.45
rowMethod · 0.45
rankUpdateMethod · 0.45

Tested by 1

test_nomallocFunction · 0.68