SymbolicIndex.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2017 Gael Guennebaud <gael.guennebaud@inria.fr>
5 //
6 // This Source Code Form is subject to the terms of the Mozilla
7 // Public License v. 2.0. If a copy of the MPL was not distributed
8 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 
10 #ifndef EIGEN_SYMBOLIC_INDEX_H
11 #define EIGEN_SYMBOLIC_INDEX_H
12 
13 namespace Eigen {
14 
41 namespace symbolic {
42 
43 template<typename Tag> class Symbol;
44 template<typename Arg0> class NegateExpr;
45 template<typename Arg1,typename Arg2> class AddExpr;
46 template<typename Arg1,typename Arg2> class ProductExpr;
47 template<typename Arg1,typename Arg2> class QuotientExpr;
48 
49 // A simple wrapper around an integral value to provide the eval method.
50 // We could also use a free-function symbolic_eval...
51 template<typename IndexType=Index>
52 class ValueExpr {
53 public:
54  ValueExpr(IndexType val) : m_value(val) {}
55  template<typename T>
56  IndexType eval_impl(const T&) const { return m_value; }
57 protected:
58  IndexType m_value;
59 };
60 
61 // Specialization for compile-time value,
62 // It is similar to ValueExpr(N) but this version helps the compiler to generate better code.
63 template<int N>
64 class ValueExpr<internal::FixedInt<N> > {
65 public:
66  ValueExpr() {}
67  template<typename T>
68  EIGEN_CONSTEXPR Index eval_impl(const T&) const { return N; }
69 };
70 
71 
76 template<typename Derived>
77 class BaseExpr
78 {
79 public:
80  const Derived& derived() const { return *static_cast<const Derived*>(this); }
81 
88  template<typename T>
89  Index eval(const T& values) const { return derived().eval_impl(values); }
90 
91 #if EIGEN_HAS_CXX14
92  template<typename... Types>
93  Index eval(Types&&... values) const { return derived().eval_impl(std::make_tuple(values...)); }
94 #endif
95 
97 
99  { return AddExpr<Derived,ValueExpr<> >(derived(), b); }
101  { return AddExpr<Derived,ValueExpr<> >(derived(), -a); }
103  { return ProductExpr<Derived,ValueExpr<> >(derived(),a); }
106 
108  { return AddExpr<Derived,ValueExpr<> >(b.derived(), a); }
110  { return AddExpr<NegateExpr<Derived>,ValueExpr<> >(-b.derived(), a); }
112  { return ProductExpr<ValueExpr<>,Derived>(a,b.derived()); }
114  { return QuotientExpr<ValueExpr<>,Derived>(a,b.derived()); }
115 
116  template<int N>
119  template<int N>
121  { return AddExpr<Derived,ValueExpr<internal::FixedInt<-N> > >(derived(), ValueExpr<internal::FixedInt<-N> >()); }
122  template<int N>
125  template<int N>
128 
129  template<int N>
132  template<int N>
135  template<int N>
138  template<int N>
141 
142 #if (!EIGEN_HAS_CXX14)
143  template<int N>
146  template<int N>
148  { return AddExpr<Derived,ValueExpr<internal::FixedInt<-N> > >(derived(), ValueExpr<internal::FixedInt<-N> >()); }
149  template<int N>
152  template<int N>
155 
156  template<int N>
159  template<int N>
162  template<int N>
165  template<int N>
168 #endif
169 
170 
171  template<typename OtherDerived>
173  { return AddExpr<Derived,OtherDerived>(derived(), b.derived()); }
174 
175  template<typename OtherDerived>
177  { return AddExpr<Derived,NegateExpr<OtherDerived> >(derived(), -b.derived()); }
178 
179  template<typename OtherDerived>
181  { return ProductExpr<Derived,OtherDerived>(derived(), b.derived()); }
182 
183  template<typename OtherDerived>
185  { return QuotientExpr<Derived,OtherDerived>(derived(), b.derived()); }
186 };
187 
188 template<typename T>
189 struct is_symbolic {
190  // BaseExpr has no conversion ctor, so we only have to check whether T can be statically cast to its base class BaseExpr<T>.
192 };
193 
198 template<typename Tag>
200 {
201 public:
203  SymbolValue(Index val) : m_value(val) {}
204 
206  Index value() const { return m_value; }
207 protected:
209 };
210 
212 template<typename tag>
213 class SymbolExpr : public BaseExpr<SymbolExpr<tag> >
214 {
215 public:
217  typedef tag Tag;
218 
220 
226  return SymbolValue<Tag>(val);
227  }
228 
229  Index eval_impl(const SymbolValue<Tag> &values) const { return values.value(); }
230 
231 #if EIGEN_HAS_CXX14
232  // C++14 versions suitable for multiple symbols
233  template<typename... Types>
234  Index eval_impl(const std::tuple<Types...>& values) const { return std::get<SymbolValue<Tag> >(values).value(); }
235 #endif
236 };
237 
238 template<typename Arg0>
239 class NegateExpr : public BaseExpr<NegateExpr<Arg0> >
240 {
241 public:
242  NegateExpr(const Arg0& arg0) : m_arg0(arg0) {}
243 
244  template<typename T>
245  Index eval_impl(const T& values) const { return -m_arg0.eval_impl(values); }
246 protected:
247  Arg0 m_arg0;
248 };
249 
250 template<typename Arg0, typename Arg1>
251 class AddExpr : public BaseExpr<AddExpr<Arg0,Arg1> >
252 {
253 public:
254  AddExpr(const Arg0& arg0, const Arg1& arg1) : m_arg0(arg0), m_arg1(arg1) {}
255 
256  template<typename T>
257  Index eval_impl(const T& values) const { return m_arg0.eval_impl(values) + m_arg1.eval_impl(values); }
258 protected:
259  Arg0 m_arg0;
260  Arg1 m_arg1;
261 };
262 
263 template<typename Arg0, typename Arg1>
264 class ProductExpr : public BaseExpr<ProductExpr<Arg0,Arg1> >
265 {
266 public:
267  ProductExpr(const Arg0& arg0, const Arg1& arg1) : m_arg0(arg0), m_arg1(arg1) {}
268 
269  template<typename T>
270  Index eval_impl(const T& values) const { return m_arg0.eval_impl(values) * m_arg1.eval_impl(values); }
271 protected:
272  Arg0 m_arg0;
273  Arg1 m_arg1;
274 };
275 
276 template<typename Arg0, typename Arg1>
277 class QuotientExpr : public BaseExpr<QuotientExpr<Arg0,Arg1> >
278 {
279 public:
280  QuotientExpr(const Arg0& arg0, const Arg1& arg1) : m_arg0(arg0), m_arg1(arg1) {}
281 
282  template<typename T>
283  Index eval_impl(const T& values) const { return m_arg0.eval_impl(values) / m_arg1.eval_impl(values); }
284 protected:
285  Arg0 m_arg0;
286  Arg1 m_arg1;
287 };
288 
289 } // end namespace symbolic
290 
291 } // end namespace Eigen
292 
293 #endif // EIGEN_SYMBOLIC_INDEX_H
Eigen::symbolic::BaseExpr::operator-
AddExpr< Derived, NegateExpr< OtherDerived > > operator-(const BaseExpr< OtherDerived > &b) const
Definition: SymbolicIndex.h:176
Eigen::symbolic::BaseExpr::derived
const Derived & derived() const
Definition: SymbolicIndex.h:80
Eigen::symbolic::ProductExpr::m_arg0
Arg0 m_arg0
Definition: SymbolicIndex.h:272
Eigen
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
Eigen::symbolic::AddExpr::m_arg0
Arg0 m_arg0
Definition: SymbolicIndex.h:259
Eigen::symbolic::SymbolExpr::operator=
SymbolValue< Tag > operator=(Index val) const
Definition: SymbolicIndex.h:225
Eigen::symbolic::BaseExpr::operator*
ProductExpr< Derived, OtherDerived > operator*(const BaseExpr< OtherDerived > &b) const
Definition: SymbolicIndex.h:180
Eigen::symbolic::BaseExpr::operator/
QuotientExpr< Derived, OtherDerived > operator/(const BaseExpr< OtherDerived > &b) const
Definition: SymbolicIndex.h:184
Eigen::symbolic::AddExpr::eval_impl
Index eval_impl(const T &values) const
Definition: SymbolicIndex.h:257
Eigen::symbolic::ValueExpr::eval_impl
IndexType eval_impl(const T &) const
Definition: SymbolicIndex.h:56
b
Scalar * b
Definition: benchVecAdd.cpp:17
Eigen::symbolic::BaseExpr::operator-
friend AddExpr< NegateExpr< Derived >, ValueExpr< internal::FixedInt< N > > > operator-(internal::FixedInt< N >(*)(), const BaseExpr &b)
Definition: SymbolicIndex.h:160
Eigen::symbolic::QuotientExpr::QuotientExpr
QuotientExpr(const Arg0 &arg0, const Arg1 &arg1)
Definition: SymbolicIndex.h:280
Eigen::symbolic::BaseExpr::operator+
friend AddExpr< Derived, ValueExpr< internal::FixedInt< N > > > operator+(internal::FixedInt< N >(*)(), const BaseExpr &b)
Definition: SymbolicIndex.h:157
Eigen::symbolic::is_symbolic
Definition: SymbolicIndex.h:189
Eigen::symbolic::ValueExpr< internal::FixedInt< N > >::ValueExpr
ValueExpr()
Definition: SymbolicIndex.h:66
EIGEN_CONSTEXPR
#define EIGEN_CONSTEXPR
Definition: Macros.h:787
Eigen::internal::FixedInt
Definition: IntegralConstant.h:18
Eigen::symbolic::BaseExpr::operator-
friend AddExpr< NegateExpr< Derived >, ValueExpr<> > operator-(Index a, const BaseExpr &b)
Definition: SymbolicIndex.h:109
Eigen::symbolic::is_symbolic::value
@ value
Definition: SymbolicIndex.h:191
Eigen::symbolic::BaseExpr::operator-
AddExpr< Derived, ValueExpr<> > operator-(Index a) const
Definition: SymbolicIndex.h:100
different_sigmas::values
HybridValues values
Definition: testHybridBayesNet.cpp:245
Eigen::symbolic::NegateExpr
Definition: SymbolicIndex.h:44
Eigen::symbolic::QuotientExpr::eval_impl
Index eval_impl(const T &values) const
Definition: SymbolicIndex.h:283
Eigen::symbolic::BaseExpr::operator-
NegateExpr< Derived > operator-() const
Definition: SymbolicIndex.h:96
Eigen::symbolic::BaseExpr::operator*
friend ProductExpr< ValueExpr< internal::FixedInt< N > >, Derived > operator*(internal::FixedInt< N >(*)(), const BaseExpr &b)
Definition: SymbolicIndex.h:163
Eigen::symbolic::BaseExpr::operator/
friend QuotientExpr< ValueExpr< internal::FixedInt< N > >, Derived > operator/(internal::FixedInt< N >(*)(), const BaseExpr &b)
Definition: SymbolicIndex.h:166
Eigen::symbolic::ValueExpr
Definition: SymbolicIndex.h:52
Eigen::symbolic::NegateExpr::NegateExpr
NegateExpr(const Arg0 &arg0)
Definition: SymbolicIndex.h:242
Eigen::symbolic::ProductExpr::ProductExpr
ProductExpr(const Arg0 &arg0, const Arg1 &arg1)
Definition: SymbolicIndex.h:267
Eigen::symbolic::BaseExpr::operator+
AddExpr< Derived, ValueExpr< internal::FixedInt< N > > > operator+(internal::FixedInt< N >(*)()) const
Definition: SymbolicIndex.h:144
Eigen::symbolic::ProductExpr::eval_impl
Index eval_impl(const T &values) const
Definition: SymbolicIndex.h:270
Eigen::symbolic::BaseExpr::operator+
AddExpr< Derived, ValueExpr< internal::FixedInt< N > > > operator+(internal::FixedInt< N >) const
Definition: SymbolicIndex.h:117
Eigen::internal::is_convertible
Definition: Meta.h:257
Eigen::symbolic::BaseExpr::operator+
AddExpr< Derived, ValueExpr<> > operator+(Index b) const
Definition: SymbolicIndex.h:98
Eigen::symbolic::BaseExpr
Definition: SymbolicIndex.h:77
Eigen::symbolic::BaseExpr::operator-
AddExpr< Derived, ValueExpr< internal::FixedInt<-N > > > operator-(internal::FixedInt< N >) const
Definition: SymbolicIndex.h:120
Eigen::symbolic::BaseExpr::operator/
QuotientExpr< Derived, ValueExpr< internal::FixedInt< N > > > operator/(internal::FixedInt< N >(*)()) const
Definition: SymbolicIndex.h:153
make_tuple
tuple make_tuple()
Definition: cast.h:1383
Eigen::symbolic::BaseExpr::operator/
friend QuotientExpr< ValueExpr< internal::FixedInt< N > >, Derived > operator/(internal::FixedInt< N >, const BaseExpr &b)
Definition: SymbolicIndex.h:139
Eigen::symbolic::AddExpr::AddExpr
AddExpr(const Arg0 &arg0, const Arg1 &arg1)
Definition: SymbolicIndex.h:254
Eigen::symbolic::SymbolValue::SymbolValue
SymbolValue(Index val)
Definition: SymbolicIndex.h:203
Eigen::symbolic::BaseExpr::operator*
ProductExpr< Derived, ValueExpr< internal::FixedInt< N > > > operator*(internal::FixedInt< N >) const
Definition: SymbolicIndex.h:123
Eigen::symbolic::QuotientExpr::m_arg1
Arg1 m_arg1
Definition: SymbolicIndex.h:286
Eigen::symbolic::SymbolExpr::SymbolExpr
SymbolExpr()
Definition: SymbolicIndex.h:219
Eigen::symbolic::QuotientExpr
Definition: SymbolicIndex.h:47
Eigen::symbolic::SymbolValue::value
Index value() const
Definition: SymbolicIndex.h:206
Eigen::Triplet< double >
Eigen::symbolic::BaseExpr::operator/
QuotientExpr< Derived, ValueExpr<> > operator/(Index a) const
Definition: SymbolicIndex.h:104
Eigen::symbolic::ValueExpr< internal::FixedInt< N > >::eval_impl
EIGEN_CONSTEXPR Index eval_impl(const T &) const
Definition: SymbolicIndex.h:68
Eigen::symbolic::ProductExpr
Definition: SymbolicIndex.h:46
Eigen::symbolic::NegateExpr::eval_impl
Index eval_impl(const T &values) const
Definition: SymbolicIndex.h:245
Eigen::symbolic::AddExpr
Definition: SymbolicIndex.h:45
Eigen::symbolic::BaseExpr::operator-
friend AddExpr< NegateExpr< Derived >, ValueExpr< internal::FixedInt< N > > > operator-(internal::FixedInt< N >, const BaseExpr &b)
Definition: SymbolicIndex.h:133
Eigen::symbolic::ValueExpr::m_value
IndexType m_value
Definition: SymbolicIndex.h:58
Eigen::symbolic::SymbolExpr::eval_impl
Index eval_impl(const SymbolValue< Tag > &values) const
Definition: SymbolicIndex.h:229
Eigen::symbolic::BaseExpr::operator/
QuotientExpr< Derived, ValueExpr< internal::FixedInt< N > > > operator/(internal::FixedInt< N >) const
Definition: SymbolicIndex.h:126
Eigen::symbolic::AddExpr::m_arg1
Arg1 m_arg1
Definition: SymbolicIndex.h:260
Eigen::symbolic::BaseExpr::operator+
friend AddExpr< Derived, ValueExpr<> > operator+(Index a, const BaseExpr &b)
Definition: SymbolicIndex.h:107
a
ArrayXXi a
Definition: Array_initializer_list_23_cxx11.cpp:1
Eigen::symbolic::BaseExpr::operator/
friend QuotientExpr< ValueExpr<>, Derived > operator/(Index a, const BaseExpr &b)
Definition: SymbolicIndex.h:113
Eigen::symbolic::BaseExpr::operator+
friend AddExpr< Derived, ValueExpr< internal::FixedInt< N > > > operator+(internal::FixedInt< N >, const BaseExpr &b)
Definition: SymbolicIndex.h:130
Eigen::symbolic::NegateExpr::m_arg0
Arg0 m_arg0
Definition: SymbolicIndex.h:247
Eigen::symbolic::ProductExpr::m_arg1
Arg1 m_arg1
Definition: SymbolicIndex.h:273
Eigen::symbolic::BaseExpr::operator+
AddExpr< Derived, OtherDerived > operator+(const BaseExpr< OtherDerived > &b) const
Definition: SymbolicIndex.h:172
Eigen::symbolic::Symbol
Definition: SymbolicIndex.h:43
Eigen::symbolic::ValueExpr::ValueExpr
ValueExpr(IndexType val)
Definition: SymbolicIndex.h:54
N
#define N
Definition: igam.h:9
internal
Definition: BandTriangularSolver.h:13
Eigen::symbolic::SymbolValue
Definition: SymbolicIndex.h:199
Eigen::symbolic::BaseExpr::operator-
AddExpr< Derived, ValueExpr< internal::FixedInt<-N > > > operator-(internal::FixedInt< N >(*)()) const
Definition: SymbolicIndex.h:147
Eigen::symbolic::SymbolExpr::Tag
tag Tag
Definition: SymbolicIndex.h:217
Eigen::symbolic::SymbolValue::m_value
Index m_value
Definition: SymbolicIndex.h:208
Eigen::symbolic::BaseExpr::eval
Index eval(const T &values) const
Definition: SymbolicIndex.h:89
Eigen::symbolic::BaseExpr::operator*
friend ProductExpr< ValueExpr<>, Derived > operator*(Index a, const BaseExpr &b)
Definition: SymbolicIndex.h:111
test_callbacks.value
value
Definition: test_callbacks.py:160
Eigen::symbolic::BaseExpr::operator*
ProductExpr< Derived, ValueExpr<> > operator*(Index a) const
Definition: SymbolicIndex.h:102
Eigen::symbolic::BaseExpr::operator*
ProductExpr< Derived, ValueExpr< internal::FixedInt< N > > > operator*(internal::FixedInt< N >(*)()) const
Definition: SymbolicIndex.h:150
Eigen::symbolic::QuotientExpr::m_arg0
Arg0 m_arg0
Definition: SymbolicIndex.h:285
Eigen::symbolic::BaseExpr::operator*
friend ProductExpr< ValueExpr< internal::FixedInt< N > >, Derived > operator*(internal::FixedInt< N >, const BaseExpr &b)
Definition: SymbolicIndex.h:136
Eigen::Index
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74
Eigen::symbolic::SymbolExpr
Definition: SymbolicIndex.h:213


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:05:21