10#ifndef EIGEN_SYMBOLIC_INDEX_H
11#define EIGEN_SYMBOLIC_INDEX_H
14#include "../InternalHeaderCheck.h"
45template <
typename Tag>
47template <
typename Tag,
typename Type>
49template <
typename Arg0>
51template <
typename Arg1,
typename Arg2>
53template <
typename Arg1,
typename Arg2>
55template <
typename Arg1,
typename Arg2>
57template <
typename IndexType = Index>
64template <
typename Derived_>
67 using Derived = Derived_;
68 constexpr const Derived& derived()
const {
return *
static_cast<const Derived*
>(
this); }
75 template <
typename... Tags,
typename... Types>
77 return derived().eval_impl(values...);
85 template <
typename... Tags,
typename... Types>
90 constexpr NegateExpr<Derived> operator-()
const {
return NegateExpr<Derived>(derived()); }
92 constexpr AddExpr<Derived, ValueExpr<>> operator+(
Index b)
const {
93 return AddExpr<Derived, ValueExpr<>>(derived(), b);
95 constexpr AddExpr<Derived, ValueExpr<>> operator-(Index a)
const {
96 return AddExpr<Derived, ValueExpr<>>(derived(), -a);
98 constexpr ProductExpr<Derived, ValueExpr<>> operator*(
Index a)
const {
99 return ProductExpr<Derived, ValueExpr<>>(derived(), a);
101 constexpr QuotientExpr<Derived, ValueExpr<>> operator/(
Index a)
const {
102 return QuotientExpr<Derived, ValueExpr<>>(derived(), a);
105 friend constexpr AddExpr<Derived, ValueExpr<>> operator+(
Index a,
const BaseExpr& b) {
106 return AddExpr<Derived, ValueExpr<>>(b.derived(), a);
108 friend constexpr AddExpr<NegateExpr<Derived>, ValueExpr<>> operator-(
Index a,
const BaseExpr& b) {
109 return AddExpr<NegateExpr<Derived>, ValueExpr<>>(-b.derived(), a);
111 friend constexpr ProductExpr<ValueExpr<>, Derived> operator*(
Index a,
const BaseExpr& b) {
112 return ProductExpr<ValueExpr<>, Derived>(a, b.derived());
114 friend constexpr QuotientExpr<ValueExpr<>, Derived> operator/(
Index a,
const BaseExpr& b) {
115 return QuotientExpr<ValueExpr<>, Derived>(a, b.derived());
119 constexpr AddExpr<Derived, ValueExpr<internal::FixedInt<N>>> operator+(internal::FixedInt<N>)
const {
120 return AddExpr<Derived, ValueExpr<internal::FixedInt<N>>>(derived(), ValueExpr<internal::FixedInt<N>>());
123 constexpr AddExpr<Derived, ValueExpr<internal::FixedInt<-N>>> operator-(internal::FixedInt<N>)
const {
124 return AddExpr<Derived, ValueExpr<internal::FixedInt<-N>>>(derived(), ValueExpr<internal::FixedInt<-N>>());
127 constexpr ProductExpr<Derived, ValueExpr<internal::FixedInt<N>>> operator*(internal::FixedInt<N>)
const {
128 return ProductExpr<Derived, ValueExpr<internal::FixedInt<N>>>(derived(), ValueExpr<internal::FixedInt<N>>());
131 constexpr QuotientExpr<Derived, ValueExpr<internal::FixedInt<N>>> operator/(internal::FixedInt<N>)
const {
132 return QuotientExpr<Derived, ValueExpr<internal::FixedInt<N>>>(derived(), ValueExpr<internal::FixedInt<N>>());
136 friend constexpr AddExpr<Derived, ValueExpr<internal::FixedInt<N>>> operator+(internal::FixedInt<N>,
138 return AddExpr<Derived, ValueExpr<internal::FixedInt<N>>>(b.derived(), ValueExpr<internal::FixedInt<N>>());
141 friend constexpr AddExpr<NegateExpr<Derived>, ValueExpr<internal::FixedInt<N>>> operator-(internal::FixedInt<N>,
143 return AddExpr<NegateExpr<Derived>, ValueExpr<internal::FixedInt<N>>>(-b.derived(),
144 ValueExpr<internal::FixedInt<N>>());
147 friend constexpr ProductExpr<ValueExpr<internal::FixedInt<N>>, Derived> operator*(internal::FixedInt<N>,
149 return ProductExpr<ValueExpr<internal::FixedInt<N>>, Derived>(ValueExpr<internal::FixedInt<N>>(), b.derived());
152 friend constexpr QuotientExpr<ValueExpr<internal::FixedInt<N>>, Derived> operator/(internal::FixedInt<N>,
154 return QuotientExpr<ValueExpr<internal::FixedInt<N>>, Derived>(ValueExpr<internal::FixedInt<N>>(), b.derived());
157 template <
typename OtherDerived>
158 constexpr AddExpr<Derived, OtherDerived> operator+(
const BaseExpr<OtherDerived>& b)
const {
159 return AddExpr<Derived, OtherDerived>(derived(), b.derived());
162 template <
typename OtherDerived>
163 constexpr AddExpr<Derived, NegateExpr<OtherDerived>> operator-(
const BaseExpr<OtherDerived>& b)
const {
164 return AddExpr<Derived, NegateExpr<OtherDerived>>(derived(), -b.derived());
167 template <
typename OtherDerived>
168 constexpr ProductExpr<Derived, OtherDerived> operator*(
const BaseExpr<OtherDerived>& b)
const {
169 return ProductExpr<Derived, OtherDerived>(derived(), b.derived());
172 template <
typename OtherDerived>
173 constexpr QuotientExpr<Derived, OtherDerived> operator/(
const BaseExpr<OtherDerived>& b)
const {
174 return QuotientExpr<Derived, OtherDerived>(derived(), b.derived());
182 enum { value = internal::is_convertible<T, BaseExpr<T>>::value };
187template <
typename IndexType>
188class ValueExpr :
BaseExpr<ValueExpr<IndexType>> {
190 constexpr ValueExpr() =
default;
191 constexpr ValueExpr(IndexType val) : value_(val) {}
192 template <
typename... Tags,
typename... Types>
193 constexpr IndexType eval_impl(
const SymbolValue<Tags, Types>&...)
const {
196 template <
typename... Tags,
typename... Types>
197 static constexpr IndexType eval_at_compile_time_impl(
const SymbolValue<Tags, Types>&...) {
208class ValueExpr<internal::FixedInt<N>> :
public BaseExpr<ValueExpr<internal::FixedInt<N>>> {
210 constexpr ValueExpr() =
default;
211 constexpr ValueExpr(internal::FixedInt<N>) {}
212 template <
typename... Tags,
typename... Types>
213 constexpr Index eval_impl(
const SymbolValue<Tags, Types>&...)
const {
216 template <
typename... Tags,
typename... Types>
217 static constexpr Index eval_at_compile_time_impl(
const SymbolValue<Tags, Types>&...) {
226template <
typename Tag,
typename Type>
229template <
typename Tag>
238 constexpr Index value()
const {
return value_; }
241 static constexpr Index value_at_compile_time() {
return Index(
Undefined); }
243 template <
typename... Tags,
typename... Types>
244 constexpr Index eval_impl(
const SymbolValue<Tags, Types>&...)
const {
248 template <
typename... Tags,
typename... Types>
249 static constexpr Index eval_at_compile_time_impl(
const SymbolValue<Tags, Types>&...) {
250 return value_at_compile_time();
257template <
typename Tag,
int N>
258class SymbolValue<Tag, internal::FixedInt<N>> :
public BaseExpr<SymbolValue<Tag, internal::FixedInt<N>>> {
260 constexpr SymbolValue() =
default;
263 constexpr SymbolValue(internal::FixedInt<N>) {}
266 constexpr Index value()
const {
return static_cast<Index>(N); }
269 static constexpr Index value_at_compile_time() {
return static_cast<Index>(N); }
271 template <
typename... Tags,
typename... Types>
272 constexpr Index eval_impl(
const SymbolValue<Tags, Types>&...)
const {
276 template <
typename... Tags,
typename... Types>
277 static constexpr Index eval_at_compile_time_impl(
const SymbolValue<Tags, Types>&...) {
278 return value_at_compile_time();
283template <
typename Tag,
typename... Types>
284struct EvalSymbolValueHelper;
287template <
typename Tag>
288struct EvalSymbolValueHelper<Tag> {
289 static constexpr Index eval_impl() {
290 eigen_assert(
false &&
"Symbol not found.");
297template <
typename Tag,
typename Type,
typename... OtherTypes>
298struct EvalSymbolValueHelper<Tag,
SymbolValue<Tag, Type>, OtherTypes...> {
299 static constexpr Index eval_impl(
const SymbolValue<Tag, Type>& symbol,
const OtherTypes&...) {
300 return symbol.value();
302 static constexpr Index eval_at_compile_time_impl(
const SymbolValue<Tag, Type>& symbol,
const OtherTypes&...) {
303 return symbol.value_at_compile_time();
308template <
typename Tag,
typename T1,
typename... OtherTypes>
309struct EvalSymbolValueHelper<Tag, T1, OtherTypes...> {
310 static constexpr Index eval_impl(
const T1&,
const OtherTypes&... values) {
311 return EvalSymbolValueHelper<Tag, OtherTypes...>::eval_impl(values...);
313 static constexpr Index eval_at_compile_time_impl(
const T1&,
const OtherTypes&...) {
314 return EvalSymbolValueHelper<Tag, OtherTypes...>::eval_at_compile_time_impl(OtherTypes{}...);
319template <
typename tag>
320class SymbolExpr :
public BaseExpr<SymbolExpr<tag>> {
325 constexpr SymbolExpr() =
default;
339 template <
typename... Tags,
typename... Types>
340 constexpr Index eval_impl(
const SymbolValue<Tags, Types>&... values)
const {
341 return EvalSymbolValueHelper<Tag, SymbolValue<Tags, Types>...>::eval_impl(values...);
344 template <
typename... Tags,
typename... Types>
345 static constexpr Index eval_at_compile_time_impl(
const SymbolValue<Tags, Types>&...) {
346 return EvalSymbolValueHelper<Tag, SymbolValue<Tags, Types>...>::eval_at_compile_time_impl(
347 SymbolValue<Tags, Types>{}...);
351template <
typename Arg0>
352class NegateExpr :
public BaseExpr<NegateExpr<Arg0>> {
354 constexpr NegateExpr() =
default;
355 constexpr NegateExpr(
const Arg0& arg0) : m_arg0(arg0) {}
357 template <
typename... Tags,
typename... Types>
358 constexpr Index eval_impl(
const SymbolValue<Tags, Types>&... values)
const {
359 return -m_arg0.eval_impl(values...);
362 template <
typename... Tags,
typename... Types>
363 static constexpr Index eval_at_compile_time_impl(
const SymbolValue<Tags, Types>&...) {
364 constexpr Index v = Arg0::eval_at_compile_time_impl(SymbolValue<Tags, Types>{}...);
372template <
typename Arg0,
typename Arg1>
373class AddExpr :
public BaseExpr<AddExpr<Arg0, Arg1>> {
375 constexpr AddExpr() =
default;
376 constexpr AddExpr(
const Arg0& arg0,
const Arg1& arg1) : m_arg0(arg0), m_arg1(arg1) {}
378 template <
typename... Tags,
typename... Types>
379 constexpr Index eval_impl(
const SymbolValue<Tags, Types>&... values)
const {
380 return m_arg0.eval_impl(values...) + m_arg1.eval_impl(values...);
383 template <
typename... Tags,
typename... Types>
384 static constexpr Index eval_at_compile_time_impl(
const SymbolValue<Tags, Types>&...) {
385 constexpr Index v0 = Arg0::eval_at_compile_time_impl(SymbolValue<Tags, Types>{}...);
386 constexpr Index v1 = Arg1::eval_at_compile_time_impl(SymbolValue<Tags, Types>{}...);
395template <
typename Arg0,
typename Arg1>
396class ProductExpr :
public BaseExpr<ProductExpr<Arg0, Arg1>> {
398 constexpr ProductExpr() =
default;
399 constexpr ProductExpr(
const Arg0& arg0,
const Arg1& arg1) : m_arg0(arg0), m_arg1(arg1) {}
401 template <
typename... Tags,
typename... Types>
402 constexpr Index eval_impl(
const SymbolValue<Tags, Types>&... values)
const {
403 return m_arg0.eval_impl(values...) * m_arg1.eval_impl(values...);
406 template <
typename... Tags,
typename... Types>
407 static constexpr Index eval_at_compile_time_impl(
const SymbolValue<Tags, Types>&...) {
408 constexpr Index v0 = Arg0::eval_at_compile_time_impl(SymbolValue<Tags, Types>{}...);
409 constexpr Index v1 = Arg1::eval_at_compile_time_impl(SymbolValue<Tags, Types>{}...);
418template <
typename Arg0,
typename Arg1>
419class QuotientExpr :
public BaseExpr<QuotientExpr<Arg0, Arg1>> {
421 constexpr QuotientExpr() =
default;
422 constexpr QuotientExpr(
const Arg0& arg0,
const Arg1& arg1) : m_arg0(arg0), m_arg1(arg1) {}
424 template <
typename... Tags,
typename... Types>
425 constexpr Index eval_impl(
const SymbolValue<Tags, Types>&... values)
const {
426 return m_arg0.eval_impl(values...) / m_arg1.eval_impl(values...);
429 template <
typename... Tags,
typename... Types>
430 static constexpr Index eval_at_compile_time_impl(
const SymbolValue<Tags, Types>&...) {
431 constexpr Index v0 = Arg0::eval_at_compile_time_impl(SymbolValue<Tags, Types>{}...);
432 constexpr Index v1 = Arg1::eval_at_compile_time_impl(SymbolValue<Tags, Types>{}...);
Definition SymbolicIndex.h:65
constexpr Index eval(const SymbolValue< Tags, Types > &... values) const
Definition SymbolicIndex.h:76
static constexpr Index eval_at_compile_time(const SymbolValue< Tags, Types > &...)
Definition SymbolicIndex.h:86
constexpr SymbolValue< Tag, Index > operator=(Index val) const
Definition SymbolicIndex.h:332
internal::symbolic_last_tag Tag
Definition SymbolicIndex.h:323
Definition SymbolicIndex.h:227
Namespace containing all symbols from the Eigen library.
Definition B01_Experimental.dox:1
const int Undefined
Definition Constants.h:34
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition Meta.h:82