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

Function test_reference

test/nomalloc.cpp:172–204  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

170}
171
172template<typename MatrixType> void test_reference(const MatrixType& m) {
173 typedef typename MatrixType::Scalar Scalar;
174 enum { Flag = MatrixType::IsRowMajor ? Eigen::RowMajor : Eigen::ColMajor};
175 enum { TransposeFlag = !MatrixType::IsRowMajor ? Eigen::RowMajor : Eigen::ColMajor};
176 typename MatrixType::Index rows = m.rows(), cols=m.cols();
177 typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic, Flag > MatrixX;
178 typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic, TransposeFlag> MatrixXT;
179 // Dynamic reference:
180 typedef Eigen::Ref<const MatrixX > Ref;
181 typedef Eigen::Ref<const MatrixXT > RefT;
182
183 Ref r1(m);
184 Ref r2(m.block(rows/3, cols/4, rows/2, cols/2));
185 RefT r3(m.transpose());
186 RefT r4(m.topLeftCorner(rows/2, cols/2).transpose());
187
188 VERIFY_RAISES_ASSERT(RefT r5(m));
189 VERIFY_RAISES_ASSERT(Ref r6(m.transpose()));
190 VERIFY_RAISES_ASSERT(Ref r7(Scalar(2) * m));
191
192 // Copy constructors shall also never malloc
193 Ref r8 = r1;
194 RefT r9 = r3;
195
196 // Initializing from a compatible Ref shall also never malloc
197 Eigen::Ref<const MatrixX, Unaligned, Stride<Dynamic, Dynamic> > r10=r8, r11=m;
198
199 // Initializing from an incompatible Ref will malloc:
200 typedef Eigen::Ref<const MatrixX, Aligned> RefAligned;
201 VERIFY_RAISES_ASSERT(RefAligned r12=r10);
202 VERIFY_RAISES_ASSERT(Ref r13=r10); // r10 has more dynamic strides
203
204}
205
206void test_nomalloc()
207{

Callers 1

test_nomallocFunction · 0.85

Calls 3

rowsMethod · 0.45
colsMethod · 0.45
transposeMethod · 0.45

Tested by

no test coverage detected