aboutsummaryrefslogtreecommitdiffhomepage
path: root/Eigen/src/Core/util/SymbolicIndex.h
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2017-01-19 19:25:29 +0100
committerGravatar Gael Guennebaud <g.gael@free.fr>2017-01-19 19:25:29 +0100
commit7691723e3486196576c183045e50892b5d734170 (patch)
treeb62c6e7a0eb262fb3b74edfab662fa9908afa088 /Eigen/src/Core/util/SymbolicIndex.h
parente84ed7b6ef09653fb8e042c5f3fda386de1b192e (diff)
Add support for fixed-value in symbolic expression, c++11 only for now.
Diffstat (limited to 'Eigen/src/Core/util/SymbolicIndex.h')
-rw-r--r--Eigen/src/Core/util/SymbolicIndex.h50
1 files changed, 39 insertions, 11 deletions
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.