diff options
author | 2010-02-06 17:43:32 +0100 | |
---|---|---|
committer | 2010-02-06 17:43:32 +0100 | |
commit | 871698d3aa3e125561226a08bee9aa2db5dec6aa (patch) | |
tree | 588969399138db2bed8b54721d9740aac98951f4 /Eigen/src/Core/util | |
parent | 6f3f8578979b8af3d29abc8bfc17e7995bf54143 (diff) |
Introduced NestParentByRefBit and NestByRefBit - this should fix temporaries related to nested products.
Fixed a few typos and a few warnings.
Diffstat (limited to 'Eigen/src/Core/util')
-rw-r--r-- | Eigen/src/Core/util/Constants.h | 7 | ||||
-rw-r--r-- | Eigen/src/Core/util/XprHelper.h | 53 |
2 files changed, 34 insertions, 26 deletions
diff --git a/Eigen/src/Core/util/Constants.h b/Eigen/src/Core/util/Constants.h index c747d970b..1b34b401d 100644 --- a/Eigen/src/Core/util/Constants.h +++ b/Eigen/src/Core/util/Constants.h @@ -35,7 +35,7 @@ * - It should be smaller than the sqrt of INT_MAX. Indeed, we often multiply a number of rows with a number * of columns in order to compute a number of coefficients. Even if we guard that with an "if" checking whether * the values are Dynamic, we still get a compiler warning "integer overflow". So the only way to get around - * it would be a meta-selector. Doing this everywhere would reduce code readability and lenghten compilation times. + * it would be a meta-selector. Doing this everywhere would reduce code readability and lengthen compilation times. * Also, disabling compiler warnings for integer overflow, sounds like a bad idea. * - It should be a prime number, because for example the old value 10000 led to bugs with 100x100 matrices. * @@ -76,7 +76,7 @@ const unsigned int EvalBeforeNestingBit = 0x2; /** \ingroup flags * - * means the expression should be evaluated before any assignement */ + * means the expression should be evaluated before any assignment */ const unsigned int EvalBeforeAssigningBit = 0x4; /** \ingroup flags @@ -97,6 +97,9 @@ const unsigned int EvalBeforeAssigningBit = 0x4; */ const unsigned int PacketAccessBit = 0x8; +const unsigned int NestParentByRefBit = 0x80; +const unsigned int NestByRefBit = 0x100; + #ifdef EIGEN_VECTORIZE /** \ingroup flags * diff --git a/Eigen/src/Core/util/XprHelper.h b/Eigen/src/Core/util/XprHelper.h index 136cc876b..77b3968b1 100644 --- a/Eigen/src/Core/util/XprHelper.h +++ b/Eigen/src/Core/util/XprHelper.h @@ -97,7 +97,7 @@ class ei_compute_matrix_flags }; public: - enum { ret = LinearAccessBit | DirectAccessBit | packet_access_bit | row_major_bit | aligned_bit }; + enum { ret = LinearAccessBit | DirectAccessBit | NestByRefBit | packet_access_bit | row_major_bit | aligned_bit }; }; template<int _Rows, int _Cols> struct ei_size_at_compile_time @@ -201,6 +201,28 @@ template<typename T> struct ei_plain_matrix_type_row_major // we should be able to get rid of this one too template<typename T> struct ei_must_nest_by_value { enum { ret = false }; }; +template<class T> +struct ei_is_reference +{ +#ifndef NDEBUG + static void check() { std::cout << typeid(T).name() << std::endl; } +#else + static void check() {} +#endif + enum { ret = false }; +}; + +template<class T> +struct ei_is_reference<T&> +{ +#ifndef NDEBUG + static void check() { std::cout << typeid(T).name() << "&" << std::endl; } +#else + static void check() {} +#endif + enum { ret = true }; +}; + /** * The reference selector for template expressions. The idea is that we don't * need to use references for expressions since they are light weight proxy @@ -209,31 +231,14 @@ template<typename T> struct ei_must_nest_by_value { enum { ret = false }; }; template <typename T> struct ei_ref_selector { - typedef T type; -}; - -/** -* Matrices on the other hand side should only be copied, when it is sure -* we gain by copying (see arithmetic cost check and eval before nesting flag). -* Note: This is an optimization measure that comprises potential (though little) -* to create erroneous code. Any user, utilizing ei_nested outside of -* Eigen needs to take care that no references to temporaries are -* stored or that this potential danger is at least communicated -* to the user. -**/ -template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols> -struct ei_ref_selector< Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> > -{ - typedef Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> MatrixType; - typedef MatrixType const& type; + typedef typename ei_meta_if< + bool(ei_traits<T>::Flags & NestByRefBit), + T const&, + T + >::ret type; }; -template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols> -struct ei_ref_selector< Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> > -{ - typedef Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> ArrayType; - typedef ArrayType const& type; -}; +#define EIGEN_PROPAGATE_NESTING_BIT(ReferenceFlags) ((ReferenceFlags) & NestParentByRefBit)<<1 /** \internal Determines how a given expression should be nested into another one. * For example, when you do a * (b+c), Eigen will determine how the expression b+c should be |