diff options
author | Christoph Hertzberg <chtz@informatik.uni-bremen.de> | 2014-09-25 16:05:17 +0200 |
---|---|---|
committer | Christoph Hertzberg <chtz@informatik.uni-bremen.de> | 2014-09-25 16:05:17 +0200 |
commit | 4ba8aa14822ae0b444baa9e0d41d8744cdcd6b03 (patch) | |
tree | c1c0abd45012c09a8e2cf9583226b146d41ce501 /test | |
parent | 27d6b4daf90488e105d70f45e5d5684b8f1a906d (diff) |
Fix bug #884: No malloc for zero-sized matrices or for Ref without temporaries
Diffstat (limited to 'test')
-rw-r--r-- | test/nomalloc.cpp | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/test/nomalloc.cpp b/test/nomalloc.cpp index cbd02dd21..5458806f5 100644 --- a/test/nomalloc.cpp +++ b/test/nomalloc.cpp @@ -165,6 +165,38 @@ void ctms_decompositions() Eigen::JacobiSVD<Matrix> jSVD; jSVD.compute(A, ComputeFullU | ComputeFullV); } +void test_zerosized() { + // default constructors: + Eigen::MatrixXd A; + Eigen::VectorXd v; + // explicit zero-sized: + Eigen::ArrayXXd A0(0,0); + Eigen::ArrayXd v0(0); + + // assigning empty objects to each other: + A=A0; + v=v0; +} + +template<typename MatrixType> void test_reference(const MatrixType& m) { + typedef typename MatrixType::Scalar Scalar; + enum { Flag = MatrixType::IsRowMajor ? Eigen::RowMajor : Eigen::ColMajor}; + enum { TransposeFlag = !MatrixType::IsRowMajor ? Eigen::RowMajor : Eigen::ColMajor}; + typename MatrixType::Index rows = m.rows(), cols=m.cols(); + // Dynamic reference: + typedef Eigen::Ref<const Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic, Flag > > Ref; + typedef Eigen::Ref<const Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic, TransposeFlag> > RefT; + + Ref r1(m); + Ref r2(m.block(rows/3, cols/4, rows/2, cols/2)); + RefT r3(m.transpose()); + RefT r4(m.topLeftCorner(rows/2, cols/2).transpose()); + + VERIFY_RAISES_ASSERT(RefT r5(m)); + VERIFY_RAISES_ASSERT(Ref r6(m.transpose())); + VERIFY_RAISES_ASSERT(Ref r7(Scalar(2) * m)); +} + void test_nomalloc() { // check that our operator new is indeed called: @@ -175,5 +207,6 @@ void test_nomalloc() // Check decomposition modules with dynamic matrices that have a known compile-time max size (ctms) CALL_SUBTEST_4(ctms_decompositions<float>()); - + CALL_SUBTEST_5(test_zerosized()); + CALL_SUBTEST_6(test_reference(Matrix<float,32,32>())); } |