diff options
author | Gael Guennebaud <g.gael@free.fr> | 2017-01-19 19:25:29 +0100 |
---|---|---|
committer | Gael Guennebaud <g.gael@free.fr> | 2017-01-19 19:25:29 +0100 |
commit | 7691723e3486196576c183045e50892b5d734170 (patch) | |
tree | b62c6e7a0eb262fb3b74edfab662fa9908afa088 /Eigen/src/Core/util | |
parent | e84ed7b6ef09653fb8e042c5f3fda386de1b192e (diff) |
Add support for fixed-value in symbolic expression, c++11 only for now.
Diffstat (limited to 'Eigen/src/Core/util')
-rw-r--r-- | Eigen/src/Core/util/IndexedViewHelper.h | 2 | ||||
-rw-r--r-- | Eigen/src/Core/util/SymbolicIndex.h | 50 |
2 files changed, 40 insertions, 12 deletions
diff --git a/Eigen/src/Core/util/IndexedViewHelper.h b/Eigen/src/Core/util/IndexedViewHelper.h index a8259bb2c..5dca1926c 100644 --- a/Eigen/src/Core/util/IndexedViewHelper.h +++ b/Eigen/src/Core/util/IndexedViewHelper.h @@ -60,7 +60,7 @@ static const auto end = last+1; #else // Using a FixedExpr<1> expression is important here to make sure the compiler // can fully optimize the computation starting indices with zero overhead. -static const Symbolic::AddExpr<Symbolic::SymbolExpr<internal::symbolic_last_tag>,Symbolic::FixedExpr<1> > end(last+Symbolic::FixedExpr<1>()); +static const Symbolic::AddExpr<Symbolic::SymbolExpr<internal::symbolic_last_tag>,Symbolic::FixedExpr<1> > end(last+fix<1>()); #endif } // end namespace placeholders diff --git a/Eigen/src/Core/util/SymbolicIndex.h b/Eigen/src/Core/util/SymbolicIndex.h index cee5d908a..fcc5921e6 100644 --- a/Eigen/src/Core/util/SymbolicIndex.h +++ b/Eigen/src/Core/util/SymbolicIndex.h @@ -57,6 +57,17 @@ protected: Index m_value; }; +// Simple wrapper around a compile-time value, +// It is similar to ValueExpr(N) but this version helps the compiler to generate better code. +template<int N> +class FixedExpr { +public: + FixedExpr() {} + template<typename T> + Index eval_impl(const T&) const { return N; } +}; + + /** \class BaseExpr * \ingroup Core_Module * Common base class of any symbolic expressions @@ -101,6 +112,34 @@ public: friend QuotientExpr<ValueExpr,Derived> operator/(Index a, const BaseExpr& b) { return QuotientExpr<ValueExpr,Derived>(a,b.derived()); } + + template<int N> + AddExpr<Derived,FixedExpr<N> > operator+(internal::fix_t<N>) const + { return AddExpr<Derived,FixedExpr<N> >(derived(), FixedExpr<N>()); } + template<int N> + AddExpr<Derived,FixedExpr<N> > operator-(internal::fix_t<N>) const + { return AddExpr<Derived,FixedExpr<-N> >(derived(), FixedExpr<-N>()); } + template<int N> + ProductExpr<Derived,FixedExpr<N> > operator*(internal::fix_t<N>) const + { return ProductExpr<Derived,FixedExpr<N> >(derived(),FixedExpr<N>()); } + template<int N> + QuotientExpr<Derived,FixedExpr<N> > operator/(internal::fix_t<N>) const + { return QuotientExpr<Derived,FixedExpr<N> >(derived(),FixedExpr<N>()); } + + template<int N> + friend AddExpr<Derived,FixedExpr<N> > operator+(internal::fix_t<N>, const BaseExpr& b) + { return AddExpr<Derived,FixedExpr<N> >(b.derived(), FixedExpr<N>()); } + template<int N> + friend AddExpr<NegateExpr<Derived>,FixedExpr<N> > operator-(internal::fix_t<N>, const BaseExpr& b) + { return AddExpr<NegateExpr<Derived>,FixedExpr<N> >(-b.derived(), FixedExpr<N>()); } + template<int N> + friend ProductExpr<FixedExpr<N>,Derived> operator*(internal::fix_t<N>, const BaseExpr& b) + { return ProductExpr<FixedExpr<N>,Derived>(FixedExpr<N>(),b.derived()); } + template<int N> + friend QuotientExpr<FixedExpr<N>,Derived> operator/(internal::fix_t<N>, const BaseExpr& b) + { return QuotientExpr<FixedExpr<N> ,Derived>(FixedExpr<N>(),b.derived()); } + + template<typename OtherDerived> AddExpr<Derived,OtherDerived> operator+(const BaseExpr<OtherDerived> &b) const { return AddExpr<Derived,OtherDerived>(derived(), b.derived()); } @@ -124,17 +163,6 @@ struct is_symbolic { enum { value = internal::is_convertible<T,BaseExpr<T> >::value }; }; -// Simple wrapper around a compile-time value, -// It is similar to ValueExpr(N) but this version helps the compiler to generate better code. -template<int N> -class FixedExpr : public BaseExpr<FixedExpr<N> > { -public: - FixedExpr() {} - template<typename T> - Index eval_impl(const T&) const { return N; } -}; - - /** Represents the actual value of a symbol identified by its tag * * It is the return type of SymbolValue::operator=, and most of the time this is only way it is used. |