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 
14 namespace Eigen {
15 
16 namespace internal {
17 
18 template<int N> class FixedInt;
19 template<int N> class VariableAndFixedInt;
20 
51 template<int N> class FixedInt
52 {
53 public:
54  static const int value = N;
55  EIGEN_CONSTEXPR operator int() const { return value; }
56  FixedInt() {}
58  #ifndef EIGEN_INTERNAL_DEBUGGING
59  EIGEN_UNUSED_VARIABLE(other);
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 
123 template<int N> class VariableAndFixedInt
124 {
125 public:
126  static const int value = N;
127  operator int() const { return m_value; }
128  VariableAndFixedInt(int val) { m_value = val; }
129 protected:
130  int m_value;
131 };
132 
133 template<typename T, int Default=Dynamic> struct get_fixed_value {
134  static const int value = Default;
135 };
136 
137 template<int N,int Default> struct get_fixed_value<FixedInt<N>,Default> {
138  static const int value = N;
139 };
140 
141 #if !EIGEN_HAS_CXX14
142 template<int N,int Default> struct get_fixed_value<FixedInt<N> (*)(),Default> {
143  static const int value = N;
144 };
145 #endif
146 
147 template<int N,int Default> struct get_fixed_value<VariableAndFixedInt<N>,Default> {
148  static const int value = N ;
149 };
150 
151 template<typename T, int N, int Default>
153  static const int value = N;
154 };
155 
156 template<typename T> EIGEN_DEVICE_FUNC Index get_runtime_value(const T &x) { return x; }
157 #if !EIGEN_HAS_CXX14
158 template<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:
164 template<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
167 template<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>:
171 template<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:
175 template<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):
177 template<int DynamicKey> struct cleanup_index_type<VariableAndFixedInt<DynamicKey>, DynamicKey> { typedef Index type; };
178 
179 #if EIGEN_HAS_CXX11
180 template<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
188 template<int N>
189 static const internal::FixedInt<N> fix{};
190 #else
191 template<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.
196 template<int N,typename T>
197 inline internal::VariableAndFixedInt<N> fix(T val) { return internal::VariableAndFixedInt<N>(internal::convert_index<int>(val)); }
198 #endif
199 
200 #else // EIGEN_PARSED_BY_DOXYGEN
201 
234 template<int N>
235 static const auto fix();
236 
265 template<int N>
266 static const auto fix(int val);
267 
268 #endif // EIGEN_PARSED_BY_DOXYGEN
269 
270 } // end namespace Eigen
271 
272 #endif // EIGEN_INTEGRAL_CONSTANT_H
FixedInt< N &M > operator &(FixedInt< M >) const
Matrix< RealScalar, Dynamic, Dynamic > M
Definition: bench_gemm.cpp:51
FixedInt(FixedInt< N >(*)())
FixedInt< N+M > operator+(FixedInt< M >) const
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
#define N
Definition: gksort.c:12
FixedInt< N *M > operator*(FixedInt< M >) const
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74
#define EIGEN_CONSTEXPR
Definition: Macros.h:787
FixedInt< N|M > operator|(FixedInt< M >) const
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:976
FixedInt< N-M > operator-(FixedInt< M >) const
FixedInt<-N > operator-() const
FixedInt< N/M > operator/(FixedInt< M >) const
internal::FixedInt< N > fix()
FixedInt(VariableAndFixedInt< N > other)
EIGEN_DEVICE_FUNC Index get_runtime_value(const T &x)
#define eigen_internal_assert(x)
Definition: Macros.h:1043
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
internal::enable_if< internal::valid_indexed_view_overload< RowIndices, ColIndices >::value &&internal::traits< typename EIGEN_INDEXED_VIEW_METHOD_TYPE< RowIndices, ColIndices >::type >::ReturnAsIndexedView, typename EIGEN_INDEXED_VIEW_METHOD_TYPE< RowIndices, ColIndices >::type >::type operator()(const RowIndices &rowIndices, const ColIndices &colIndices) EIGEN_INDEXED_VIEW_METHOD_CONST
#define EIGEN_UNUSED_VARIABLE(var)
Definition: Macros.h:1076
FixedInt< N%M > operator%(FixedInt< M >) const


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:34:23