diff options
author | Hauke Heibel <hauke.heibel@gmail.com> | 2010-02-09 20:32:48 +0100 |
---|---|---|
committer | Hauke Heibel <hauke.heibel@gmail.com> | 2010-02-09 20:32:48 +0100 |
commit | 5da3049b80dc8bb2de796d151e3d83844fe21a5e (patch) | |
tree | 470e55b9413d531ecb18a10acdd58ac367c9610e | |
parent | f96e6a69449c7f68599a128898a98905512a7df9 (diff) |
Regression tests for number of nested temporaries.
Moved EIGEN_DEBUG_MATRIX_CTOR to ei_matrix_storage to capture resize related allocations.
-rw-r--r-- | Eigen/src/Core/DenseStorageBase.h | 4 | ||||
-rw-r--r-- | Eigen/src/Core/MatrixStorage.h | 18 | ||||
-rw-r--r-- | test/product_notemporary.cpp | 23 |
3 files changed, 31 insertions, 14 deletions
diff --git a/Eigen/src/Core/DenseStorageBase.h b/Eigen/src/Core/DenseStorageBase.h index 313ac037c..7006e3a95 100644 --- a/Eigen/src/Core/DenseStorageBase.h +++ b/Eigen/src/Core/DenseStorageBase.h @@ -492,10 +492,6 @@ class DenseStorageBase : public _Base<Derived> EIGEN_STRONG_INLINE void _check_template_params() { - #ifdef EIGEN_DEBUG_MATRIX_CTOR - EIGEN_DEBUG_MATRIX_CTOR; - #endif - EIGEN_STATIC_ASSERT(((RowsAtCompileTime >= MaxRowsAtCompileTime) && (ColsAtCompileTime >= MaxColsAtCompileTime) && (MaxRowsAtCompileTime >= 0) diff --git a/Eigen/src/Core/MatrixStorage.h b/Eigen/src/Core/MatrixStorage.h index 584ba8ca3..046670452 100644 --- a/Eigen/src/Core/MatrixStorage.h +++ b/Eigen/src/Core/MatrixStorage.h @@ -26,6 +26,12 @@ #ifndef EIGEN_MATRIXSTORAGE_H #define EIGEN_MATRIXSTORAGE_H +#ifdef EIGEN_DEBUG_MATRIX_CTOR + #define EIGEN_INT_DEBUG_MATRIX_CTOR EIGEN_DEBUG_MATRIX_CTOR; +#else + #define EIGEN_INT_DEBUG_MATRIX_CTOR +#endif + struct ei_constructor_without_unaligned_array_assert {}; /** \internal @@ -183,7 +189,8 @@ template<typename T, int _Options> class ei_matrix_storage<T, Dynamic, Dynamic, inline ei_matrix_storage(ei_constructor_without_unaligned_array_assert) : m_data(0), m_rows(0), m_cols(0) {} inline ei_matrix_storage(int size, int rows, int cols) - : m_data(ei_conditional_aligned_new<T,(_Options&DontAlign)==0>(size)), m_rows(rows), m_cols(cols) {} + : m_data(ei_conditional_aligned_new<T,(_Options&DontAlign)==0>(size)), m_rows(rows), m_cols(cols) + { EIGEN_INT_DEBUG_MATRIX_CTOR } inline ~ei_matrix_storage() { ei_conditional_aligned_delete<T,(_Options&DontAlign)==0>(m_data, m_rows*m_cols); } inline void swap(ei_matrix_storage& other) { std::swap(m_data,other.m_data); std::swap(m_rows,other.m_rows); std::swap(m_cols,other.m_cols); } @@ -198,6 +205,7 @@ template<typename T, int _Options> class ei_matrix_storage<T, Dynamic, Dynamic, m_data = ei_conditional_aligned_new<T,(_Options&DontAlign)==0>(size); else m_data = 0; + EIGEN_INT_DEBUG_MATRIX_CTOR } m_rows = rows; m_cols = cols; @@ -214,7 +222,8 @@ template<typename T, int _Rows, int _Options> class ei_matrix_storage<T, Dynamic public: inline explicit ei_matrix_storage() : m_data(0), m_cols(0) {} inline ei_matrix_storage(ei_constructor_without_unaligned_array_assert) : m_data(0), m_cols(0) {} - inline ei_matrix_storage(int size, int, int cols) : m_data(ei_conditional_aligned_new<T,(_Options&DontAlign)==0>(size)), m_cols(cols) {} + inline ei_matrix_storage(int size, int, int cols) : m_data(ei_conditional_aligned_new<T,(_Options&DontAlign)==0>(size)), m_cols(cols) + { EIGEN_INT_DEBUG_MATRIX_CTOR } inline ~ei_matrix_storage() { ei_conditional_aligned_delete<T,(_Options&DontAlign)==0>(m_data, _Rows*m_cols); } inline void swap(ei_matrix_storage& other) { std::swap(m_data,other.m_data); std::swap(m_cols,other.m_cols); } inline static int rows(void) {return _Rows;} @@ -228,6 +237,7 @@ template<typename T, int _Rows, int _Options> class ei_matrix_storage<T, Dynamic m_data = ei_conditional_aligned_new<T,(_Options&DontAlign)==0>(size); else m_data = 0; + EIGEN_INT_DEBUG_MATRIX_CTOR } m_cols = cols; } @@ -243,7 +253,8 @@ template<typename T, int _Cols, int _Options> class ei_matrix_storage<T, Dynamic public: inline explicit ei_matrix_storage() : m_data(0), m_rows(0) {} inline ei_matrix_storage(ei_constructor_without_unaligned_array_assert) : m_data(0), m_rows(0) {} - inline ei_matrix_storage(int size, int rows, int) : m_data(ei_conditional_aligned_new<T,(_Options&DontAlign)==0>(size)), m_rows(rows) {} + inline ei_matrix_storage(int size, int rows, int) : m_data(ei_conditional_aligned_new<T,(_Options&DontAlign)==0>(size)), m_rows(rows) + { EIGEN_INT_DEBUG_MATRIX_CTOR } inline ~ei_matrix_storage() { ei_conditional_aligned_delete<T,(_Options&DontAlign)==0>(m_data, _Cols*m_rows); } inline void swap(ei_matrix_storage& other) { std::swap(m_data,other.m_data); std::swap(m_rows,other.m_rows); } inline int rows(void) const {return m_rows;} @@ -257,6 +268,7 @@ template<typename T, int _Cols, int _Options> class ei_matrix_storage<T, Dynamic m_data = ei_conditional_aligned_new<T,(_Options&DontAlign)==0>(size); else m_data = 0; + EIGEN_INT_DEBUG_MATRIX_CTOR } m_rows = rows; } diff --git a/test/product_notemporary.cpp b/test/product_notemporary.cpp index cddf7eb39..c637039e7 100644 --- a/test/product_notemporary.cpp +++ b/test/product_notemporary.cpp @@ -24,10 +24,7 @@ static int nb_temporaries; -#define EIGEN_DEBUG_MATRIX_CTOR { \ - if(SizeAtCompileTime==Dynamic && this->data()!=0) \ - nb_temporaries++; \ - } +#define EIGEN_DEBUG_MATRIX_CTOR { if(size!=0) nb_temporaries++; } #include "main.h" @@ -40,10 +37,11 @@ static int nb_temporaries; template<typename MatrixType> void product_notemporary(const MatrixType& m) { - /* This test checks the number of tempories created + /* This test checks the number of temporaries created * during the evaluation of a complex expression */ typedef typename MatrixType::Scalar Scalar; + typedef typename MatrixType::RealScalar RealScalar; typedef Matrix<Scalar, 1, Dynamic> RowVectorType; typedef Matrix<Scalar, Dynamic, 1> ColVectorType; typedef Matrix<Scalar, Dynamic, Dynamic, RowMajor> RowMajorMatrixType; @@ -105,10 +103,21 @@ template<typename MatrixType> void product_notemporary(const MatrixType& m) VERIFY_EVALUATION_COUNT( m3.template selfadjointView<Lower>().rankUpdate(m2.adjoint()), 0); + // Here we will get 1 temporary for each resize operation of the lhs operator; resize(r1,c1) would lead to zero temporaries m3.resize(1,1); - VERIFY_EVALUATION_COUNT( m3.noalias() = m1.block(r0,r0,r1,r1).template selfadjointView<Lower>() * m2.block(r0,c0,r1,c1), 0); + VERIFY_EVALUATION_COUNT( m3.noalias() = m1.block(r0,r0,r1,r1).template selfadjointView<Lower>() * m2.block(r0,c0,r1,c1), 1); m3.resize(1,1); - VERIFY_EVALUATION_COUNT( m3.noalias() = m1.block(r0,r0,r1,r1).template triangularView<UnitUpper>() * m2.block(r0,c0,r1,c1), 0); + VERIFY_EVALUATION_COUNT( m3.noalias() = m1.block(r0,r0,r1,r1).template triangularView<UnitUpper>() * m2.block(r0,c0,r1,c1), 1); + + // Zero temporaries for lazy products ... + VERIFY_EVALUATION_COUNT( Scalar tmp = Scalar(RealScalar(1)) / (m3.transpose().lazyProduct(m3)).diagonal().sum(), 0 ); + + // ... and one temporary for even deeply (>=2) nested products + VERIFY_EVALUATION_COUNT( Scalar tmp = Scalar(RealScalar(1)) / (m3.transpose() * m3).diagonal().sum(), 1 ); + VERIFY_EVALUATION_COUNT( Scalar tmp = Scalar(RealScalar(1)) / (m3.transpose() * m3).diagonal().array().abs().sum(), 1 ); + + // Zero temporaries for ... CoeffBasedProductMode + VERIFY_EVALUATION_COUNT( m3.col(0).head<5>() * m3.col(0).transpose() + m3.col(0).head<5>() * m3.col(0).transpose(), 0 ); } void test_product_notemporary() |