TR-mbed 1.0
Loading...
Searching...
No Matches
IntegralConstant.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
11#ifndef EIGEN_INTEGRAL_CONSTANT_H
12#define EIGEN_INTEGRAL_CONSTANT_H
13
14namespace Eigen {
15
16namespace internal {
17
18template<int N> class FixedInt;
19template<int N> class VariableAndFixedInt;
20
51template<int N> class FixedInt
52{
53public:
54 static const int value = N;
55 EIGEN_CONSTEXPR operator int() const { return value; }
58 #ifndef EIGEN_INTERNAL_DEBUGGING
60 #endif
61 eigen_internal_assert(int(other)==N);
62 }
63
64 FixedInt<-N> operator-() const { return FixedInt<-N>(); }
65 template<int M>
67 template<int M>
68 FixedInt<N-M> operator-( FixedInt<M>) const { return FixedInt<N-M>(); }
69 template<int M>
71 template<int M>
72 FixedInt<N/M> operator/( FixedInt<M>) const { return FixedInt<N/M>(); }
73 template<int M>
75 template<int M>
77 template<int M>
79
80#if EIGEN_HAS_CXX14_VARIABLE_TEMPLATES
81 // Needed in C++14 to allow fix<N>():
82 FixedInt operator() () const { return *this; }
83
84 VariableAndFixedInt<N> operator() (int val) const { return VariableAndFixedInt<N>(val); }
85#else
86 FixedInt ( FixedInt<N> (*)() ) {}
87#endif
88
89#if EIGEN_HAS_CXX11
90 FixedInt(std::integral_constant<int,N>) {}
91#endif
92};
93
123template<int N> class VariableAndFixedInt
124{
125public:
126 static const int value = N;
127 operator int() const { return m_value; }
128 VariableAndFixedInt(int val) { m_value = val; }
129protected:
131};
132
133template<typename T, int Default=Dynamic> struct get_fixed_value {
134 static const int value = Default;
135};
136
137template<int N,int Default> struct get_fixed_value<FixedInt<N>,Default> {
138 static const int value = N;
139};
140
141#if !EIGEN_HAS_CXX14
142template<int N,int Default> struct get_fixed_value<FixedInt<N> (*)(),Default> {
143 static const int value = N;
144};
145#endif
146
147template<int N,int Default> struct get_fixed_value<VariableAndFixedInt<N>,Default> {
148 static const int value = N ;
149};
150
151template<typename T, int N, int Default>
153 static const int value = N;
154};
155
156template<typename T> EIGEN_DEVICE_FUNC Index get_runtime_value(const T &x) { return x; }
157#if !EIGEN_HAS_CXX14
158template<int N> EIGEN_DEVICE_FUNC Index get_runtime_value(FixedInt<N> (*)()) { return N; }
159#endif
160
161// Cleanup integer/FixedInt/VariableAndFixedInt/etc types:
162
163// By default, no cleanup:
164template<typename T, int DynamicKey=Dynamic, typename EnableIf=void> struct cleanup_index_type { typedef T type; };
165
166// Convert any integral type (e.g., short, int, unsigned int, etc.) to Eigen::Index
167template<typename T, int DynamicKey> struct cleanup_index_type<T,DynamicKey,typename internal::enable_if<internal::is_integral<T>::value>::type> { typedef Index type; };
168
169#if !EIGEN_HAS_CXX14
170// In c++98/c++11, fix<N> is a pointer to function that we better cleanup to a true FixedInt<N>:
171template<int N, int DynamicKey> struct cleanup_index_type<FixedInt<N> (*)(), DynamicKey> { typedef FixedInt<N> type; };
172#endif
173
174// If VariableAndFixedInt does not match DynamicKey, then we turn it to a pure compile-time value:
175template<int N, int DynamicKey> struct cleanup_index_type<VariableAndFixedInt<N>, DynamicKey> { typedef FixedInt<N> type; };
176// If VariableAndFixedInt matches DynamicKey, then we turn it to a pure runtime-value (aka Index):
177template<int DynamicKey> struct cleanup_index_type<VariableAndFixedInt<DynamicKey>, DynamicKey> { typedef Index type; };
178
179#if EIGEN_HAS_CXX11
180template<int N, int DynamicKey> struct cleanup_index_type<std::integral_constant<int,N>, DynamicKey> { typedef FixedInt<N> type; };
181#endif
182
183} // end namespace internal
184
185#ifndef EIGEN_PARSED_BY_DOXYGEN
186
187#if EIGEN_HAS_CXX14_VARIABLE_TEMPLATES
188template<int N>
189static const internal::FixedInt<N> fix{};
190#else
191template<int N>
193
194// The generic typename T is mandatory. Otherwise, a code like fix<N> could refer to either the function above or this next overload.
195// This way a code like fix<N> can only refer to the previous function.
196template<int N,typename T>
198#endif
199
200#else // EIGEN_PARSED_BY_DOXYGEN
201
234template<int N>
235static const auto fix();
236
265template<int N>
266static const auto fix(int val);
267
268#endif // EIGEN_PARSED_BY_DOXYGEN
269
270} // end namespace Eigen
271
272#endif // EIGEN_INTEGRAL_CONSTANT_H
internal::enable_if< internal::valid_indexed_view_overload< RowIndices, ColIndices >::value &&internal::traits< typenameEIGEN_INDEXED_VIEW_METHOD_TYPE< RowIndices, ColIndices >::type >::ReturnAsIndexedView, typenameEIGEN_INDEXED_VIEW_METHOD_TYPE< RowIndices, ColIndices >::type >::type operator()(const RowIndices &rowIndices, const ColIndices &colIndices) EIGEN_INDEXED_VIEW_METHOD_CONST
Definition IndexedViewMethods.h:73
#define eigen_internal_assert(x)
Definition Macros.h:1043
#define EIGEN_CONSTEXPR
Definition Macros.h:787
#define EIGEN_UNUSED_VARIABLE(var)
Definition Macros.h:1076
#define EIGEN_DEVICE_FUNC
Definition Macros.h:976
The matrix class, also used for vectors and row-vectors.
Definition Matrix.h:180
Definition IntegralConstant.h:52
FixedInt< N|M > operator|(FixedInt< M >) const
Definition IntegralConstant.h:76
FixedInt<-N > operator-() const
Definition IntegralConstant.h:64
FixedInt< N/M > operator/(FixedInt< M >) const
Definition IntegralConstant.h:72
static const int value
Definition IntegralConstant.h:54
FixedInt(FixedInt< N >(*)())
Definition IntegralConstant.h:86
FixedInt(VariableAndFixedInt< N > other)
Definition IntegralConstant.h:57
FixedInt()
Definition IntegralConstant.h:56
FixedInt< N+M > operator+(FixedInt< M >) const
Definition IntegralConstant.h:66
FixedInt< N%M > operator%(FixedInt< M >) const
Definition IntegralConstant.h:74
FixedInt< N &M > operator&(FixedInt< M >) const
Definition IntegralConstant.h:78
FixedInt< N *M > operator*(FixedInt< M >) const
Definition IntegralConstant.h:70
FixedInt< N-M > operator-(FixedInt< M >) const
Definition IntegralConstant.h:68
Definition IntegralConstant.h:124
static const int value
Definition IntegralConstant.h:126
int m_value
Definition IntegralConstant.h:130
VariableAndFixedInt(int val)
Definition IntegralConstant.h:128
Definition XprHelper.h:130
@ N
Definition constructor.cpp:23
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
Definition gnuplot_common_settings.hh:12
return int(ret)+1
EIGEN_DEVICE_FUNC Index get_runtime_value(const T &x)
Definition IntegralConstant.h:156
Namespace containing all symbols from the Eigen library.
Definition bench_norm.cpp:85
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition Meta.h:74
@ Default
Definition Constants.h:362
internal::FixedInt< N > fix()
Definition IntegralConstant.h:192
Definition BandTriangularSolver.h:13
Definition BFloat16.h:88
FixedInt< N > type
Definition IntegralConstant.h:171
Definition IntegralConstant.h:164
T type
Definition IntegralConstant.h:164
Definition Meta.h:273
Definition IntegralConstant.h:133
static const int value
Definition IntegralConstant.h:134
Definition ForwardDeclarations.h:17