Warning, file /include/eigen3/Eigen/src/Core/util/SymbolicIndex.h was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef EIGEN_SYMBOLIC_INDEX_H
0011 #define EIGEN_SYMBOLIC_INDEX_H
0012
0013 namespace Eigen {
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041 namespace symbolic {
0042
0043 template<typename Tag> class Symbol;
0044 template<typename Arg0> class NegateExpr;
0045 template<typename Arg1,typename Arg2> class AddExpr;
0046 template<typename Arg1,typename Arg2> class ProductExpr;
0047 template<typename Arg1,typename Arg2> class QuotientExpr;
0048
0049
0050
0051 template<typename IndexType=Index>
0052 class ValueExpr {
0053 public:
0054 ValueExpr(IndexType val) : m_value(val) {}
0055 template<typename T>
0056 IndexType eval_impl(const T&) const { return m_value; }
0057 protected:
0058 IndexType m_value;
0059 };
0060
0061
0062
0063 template<int N>
0064 class ValueExpr<internal::FixedInt<N> > {
0065 public:
0066 ValueExpr() {}
0067 template<typename T>
0068 EIGEN_CONSTEXPR Index eval_impl(const T&) const { return N; }
0069 };
0070
0071
0072
0073
0074
0075
0076 template<typename Derived>
0077 class BaseExpr
0078 {
0079 public:
0080 const Derived& derived() const { return *static_cast<const Derived*>(this); }
0081
0082
0083
0084
0085
0086
0087
0088 template<typename T>
0089 Index eval(const T& values) const { return derived().eval_impl(values); }
0090
0091 #if EIGEN_HAS_CXX14
0092 template<typename... Types>
0093 Index eval(Types&&... values) const { return derived().eval_impl(std::make_tuple(values...)); }
0094 #endif
0095
0096 NegateExpr<Derived> operator-() const { return NegateExpr<Derived>(derived()); }
0097
0098 AddExpr<Derived,ValueExpr<> > operator+(Index b) const
0099 { return AddExpr<Derived,ValueExpr<> >(derived(), b); }
0100 AddExpr<Derived,ValueExpr<> > operator-(Index a) const
0101 { return AddExpr<Derived,ValueExpr<> >(derived(), -a); }
0102 ProductExpr<Derived,ValueExpr<> > operator*(Index a) const
0103 { return ProductExpr<Derived,ValueExpr<> >(derived(),a); }
0104 QuotientExpr<Derived,ValueExpr<> > operator/(Index a) const
0105 { return QuotientExpr<Derived,ValueExpr<> >(derived(),a); }
0106
0107 friend AddExpr<Derived,ValueExpr<> > operator+(Index a, const BaseExpr& b)
0108 { return AddExpr<Derived,ValueExpr<> >(b.derived(), a); }
0109 friend AddExpr<NegateExpr<Derived>,ValueExpr<> > operator-(Index a, const BaseExpr& b)
0110 { return AddExpr<NegateExpr<Derived>,ValueExpr<> >(-b.derived(), a); }
0111 friend ProductExpr<ValueExpr<>,Derived> operator*(Index a, const BaseExpr& b)
0112 { return ProductExpr<ValueExpr<>,Derived>(a,b.derived()); }
0113 friend QuotientExpr<ValueExpr<>,Derived> operator/(Index a, const BaseExpr& b)
0114 { return QuotientExpr<ValueExpr<>,Derived>(a,b.derived()); }
0115
0116 template<int N>
0117 AddExpr<Derived,ValueExpr<internal::FixedInt<N> > > operator+(internal::FixedInt<N>) const
0118 { return AddExpr<Derived,ValueExpr<internal::FixedInt<N> > >(derived(), ValueExpr<internal::FixedInt<N> >()); }
0119 template<int N>
0120 AddExpr<Derived,ValueExpr<internal::FixedInt<-N> > > operator-(internal::FixedInt<N>) const
0121 { return AddExpr<Derived,ValueExpr<internal::FixedInt<-N> > >(derived(), ValueExpr<internal::FixedInt<-N> >()); }
0122 template<int N>
0123 ProductExpr<Derived,ValueExpr<internal::FixedInt<N> > > operator*(internal::FixedInt<N>) const
0124 { return ProductExpr<Derived,ValueExpr<internal::FixedInt<N> > >(derived(),ValueExpr<internal::FixedInt<N> >()); }
0125 template<int N>
0126 QuotientExpr<Derived,ValueExpr<internal::FixedInt<N> > > operator/(internal::FixedInt<N>) const
0127 { return QuotientExpr<Derived,ValueExpr<internal::FixedInt<N> > >(derived(),ValueExpr<internal::FixedInt<N> >()); }
0128
0129 template<int N>
0130 friend AddExpr<Derived,ValueExpr<internal::FixedInt<N> > > operator+(internal::FixedInt<N>, const BaseExpr& b)
0131 { return AddExpr<Derived,ValueExpr<internal::FixedInt<N> > >(b.derived(), ValueExpr<internal::FixedInt<N> >()); }
0132 template<int N>
0133 friend AddExpr<NegateExpr<Derived>,ValueExpr<internal::FixedInt<N> > > operator-(internal::FixedInt<N>, const BaseExpr& b)
0134 { return AddExpr<NegateExpr<Derived>,ValueExpr<internal::FixedInt<N> > >(-b.derived(), ValueExpr<internal::FixedInt<N> >()); }
0135 template<int N>
0136 friend ProductExpr<ValueExpr<internal::FixedInt<N> >,Derived> operator*(internal::FixedInt<N>, const BaseExpr& b)
0137 { return ProductExpr<ValueExpr<internal::FixedInt<N> >,Derived>(ValueExpr<internal::FixedInt<N> >(),b.derived()); }
0138 template<int N>
0139 friend QuotientExpr<ValueExpr<internal::FixedInt<N> >,Derived> operator/(internal::FixedInt<N>, const BaseExpr& b)
0140 { return QuotientExpr<ValueExpr<internal::FixedInt<N> > ,Derived>(ValueExpr<internal::FixedInt<N> >(),b.derived()); }
0141
0142 #if (!EIGEN_HAS_CXX14)
0143 template<int N>
0144 AddExpr<Derived,ValueExpr<internal::FixedInt<N> > > operator+(internal::FixedInt<N> (*)()) const
0145 { return AddExpr<Derived,ValueExpr<internal::FixedInt<N> > >(derived(), ValueExpr<internal::FixedInt<N> >()); }
0146 template<int N>
0147 AddExpr<Derived,ValueExpr<internal::FixedInt<-N> > > operator-(internal::FixedInt<N> (*)()) const
0148 { return AddExpr<Derived,ValueExpr<internal::FixedInt<-N> > >(derived(), ValueExpr<internal::FixedInt<-N> >()); }
0149 template<int N>
0150 ProductExpr<Derived,ValueExpr<internal::FixedInt<N> > > operator*(internal::FixedInt<N> (*)()) const
0151 { return ProductExpr<Derived,ValueExpr<internal::FixedInt<N> > >(derived(),ValueExpr<internal::FixedInt<N> >()); }
0152 template<int N>
0153 QuotientExpr<Derived,ValueExpr<internal::FixedInt<N> > > operator/(internal::FixedInt<N> (*)()) const
0154 { return QuotientExpr<Derived,ValueExpr<internal::FixedInt<N> > >(derived(),ValueExpr<internal::FixedInt<N> >()); }
0155
0156 template<int N>
0157 friend AddExpr<Derived,ValueExpr<internal::FixedInt<N> > > operator+(internal::FixedInt<N> (*)(), const BaseExpr& b)
0158 { return AddExpr<Derived,ValueExpr<internal::FixedInt<N> > >(b.derived(), ValueExpr<internal::FixedInt<N> >()); }
0159 template<int N>
0160 friend AddExpr<NegateExpr<Derived>,ValueExpr<internal::FixedInt<N> > > operator-(internal::FixedInt<N> (*)(), const BaseExpr& b)
0161 { return AddExpr<NegateExpr<Derived>,ValueExpr<internal::FixedInt<N> > >(-b.derived(), ValueExpr<internal::FixedInt<N> >()); }
0162 template<int N>
0163 friend ProductExpr<ValueExpr<internal::FixedInt<N> >,Derived> operator*(internal::FixedInt<N> (*)(), const BaseExpr& b)
0164 { return ProductExpr<ValueExpr<internal::FixedInt<N> >,Derived>(ValueExpr<internal::FixedInt<N> >(),b.derived()); }
0165 template<int N>
0166 friend QuotientExpr<ValueExpr<internal::FixedInt<N> >,Derived> operator/(internal::FixedInt<N> (*)(), const BaseExpr& b)
0167 { return QuotientExpr<ValueExpr<internal::FixedInt<N> > ,Derived>(ValueExpr<internal::FixedInt<N> >(),b.derived()); }
0168 #endif
0169
0170
0171 template<typename OtherDerived>
0172 AddExpr<Derived,OtherDerived> operator+(const BaseExpr<OtherDerived> &b) const
0173 { return AddExpr<Derived,OtherDerived>(derived(), b.derived()); }
0174
0175 template<typename OtherDerived>
0176 AddExpr<Derived,NegateExpr<OtherDerived> > operator-(const BaseExpr<OtherDerived> &b) const
0177 { return AddExpr<Derived,NegateExpr<OtherDerived> >(derived(), -b.derived()); }
0178
0179 template<typename OtherDerived>
0180 ProductExpr<Derived,OtherDerived> operator*(const BaseExpr<OtherDerived> &b) const
0181 { return ProductExpr<Derived,OtherDerived>(derived(), b.derived()); }
0182
0183 template<typename OtherDerived>
0184 QuotientExpr<Derived,OtherDerived> operator/(const BaseExpr<OtherDerived> &b) const
0185 { return QuotientExpr<Derived,OtherDerived>(derived(), b.derived()); }
0186 };
0187
0188 template<typename T>
0189 struct is_symbolic {
0190
0191 enum { value = internal::is_convertible<T,BaseExpr<T> >::value };
0192 };
0193
0194
0195
0196
0197
0198 template<typename Tag>
0199 class SymbolValue
0200 {
0201 public:
0202
0203 SymbolValue(Index val) : m_value(val) {}
0204
0205
0206 Index value() const { return m_value; }
0207 protected:
0208 Index m_value;
0209 };
0210
0211
0212 template<typename tag>
0213 class SymbolExpr : public BaseExpr<SymbolExpr<tag> >
0214 {
0215 public:
0216
0217 typedef tag Tag;
0218
0219 SymbolExpr() {}
0220
0221
0222
0223
0224
0225 SymbolValue<Tag> operator=(Index val) const {
0226 return SymbolValue<Tag>(val);
0227 }
0228
0229 Index eval_impl(const SymbolValue<Tag> &values) const { return values.value(); }
0230
0231 #if EIGEN_HAS_CXX14
0232
0233 template<typename... Types>
0234 Index eval_impl(const std::tuple<Types...>& values) const { return std::get<SymbolValue<Tag> >(values).value(); }
0235 #endif
0236 };
0237
0238 template<typename Arg0>
0239 class NegateExpr : public BaseExpr<NegateExpr<Arg0> >
0240 {
0241 public:
0242 NegateExpr(const Arg0& arg0) : m_arg0(arg0) {}
0243
0244 template<typename T>
0245 Index eval_impl(const T& values) const { return -m_arg0.eval_impl(values); }
0246 protected:
0247 Arg0 m_arg0;
0248 };
0249
0250 template<typename Arg0, typename Arg1>
0251 class AddExpr : public BaseExpr<AddExpr<Arg0,Arg1> >
0252 {
0253 public:
0254 AddExpr(const Arg0& arg0, const Arg1& arg1) : m_arg0(arg0), m_arg1(arg1) {}
0255
0256 template<typename T>
0257 Index eval_impl(const T& values) const { return m_arg0.eval_impl(values) + m_arg1.eval_impl(values); }
0258 protected:
0259 Arg0 m_arg0;
0260 Arg1 m_arg1;
0261 };
0262
0263 template<typename Arg0, typename Arg1>
0264 class ProductExpr : public BaseExpr<ProductExpr<Arg0,Arg1> >
0265 {
0266 public:
0267 ProductExpr(const Arg0& arg0, const Arg1& arg1) : m_arg0(arg0), m_arg1(arg1) {}
0268
0269 template<typename T>
0270 Index eval_impl(const T& values) const { return m_arg0.eval_impl(values) * m_arg1.eval_impl(values); }
0271 protected:
0272 Arg0 m_arg0;
0273 Arg1 m_arg1;
0274 };
0275
0276 template<typename Arg0, typename Arg1>
0277 class QuotientExpr : public BaseExpr<QuotientExpr<Arg0,Arg1> >
0278 {
0279 public:
0280 QuotientExpr(const Arg0& arg0, const Arg1& arg1) : m_arg0(arg0), m_arg1(arg1) {}
0281
0282 template<typename T>
0283 Index eval_impl(const T& values) const { return m_arg0.eval_impl(values) / m_arg1.eval_impl(values); }
0284 protected:
0285 Arg0 m_arg0;
0286 Arg1 m_arg1;
0287 };
0288
0289 }
0290
0291 }
0292
0293 #endif