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