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
60  #endif
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
gtsam.examples.DogLegOptimizerExample.int
int
Definition: DogLegOptimizerExample.py:111
Eigen::internal::variable_if_dynamic
Definition: XprHelper.h:129
Eigen::internal::VariableAndFixedInt::value
static const int value
Definition: IntegralConstant.h:126
EIGEN_DEVICE_FUNC
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:976
Eigen
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
Eigen::internal::get_runtime_value
EIGEN_DEVICE_FUNC Index get_runtime_value(const T &x)
Definition: IntegralConstant.h:156
Eigen::internal::cleanup_index_type::type
T type
Definition: IntegralConstant.h:164
x
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
Eigen::fix
internal::FixedInt< N > fix()
Definition: IntegralConstant.h:192
EIGEN_CONSTEXPR
#define EIGEN_CONSTEXPR
Definition: Macros.h:787
Eigen::internal::FixedInt
Definition: IntegralConstant.h:18
Eigen::internal::FixedInt::operator+
FixedInt< N+M > operator+(FixedInt< M >) const
Definition: IntegralConstant.h:66
Eigen::internal::cleanup_index_type
Definition: IntegralConstant.h:164
Eigen::internal::cleanup_index_type< VariableAndFixedInt< DynamicKey >, DynamicKey >::type
Index type
Definition: IntegralConstant.h:177
Eigen::internal::VariableAndFixedInt::VariableAndFixedInt
VariableAndFixedInt(int val)
Definition: IntegralConstant.h:128
eigen_internal_assert
#define eigen_internal_assert(x)
Definition: Macros.h:1043
EIGEN_UNUSED_VARIABLE
#define EIGEN_UNUSED_VARIABLE(var)
Definition: Macros.h:1076
Eigen::internal::FixedInt::operator*
FixedInt< N *M > operator*(FixedInt< M >) const
Definition: IntegralConstant.h:70
operator()
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
Definition: IndexedViewMethods.h:73
Eigen::internal::VariableAndFixedInt
Definition: IntegralConstant.h:19
Eigen::internal::cleanup_index_type< VariableAndFixedInt< N >, DynamicKey >::type
FixedInt< N > type
Definition: IntegralConstant.h:175
Eigen::internal::FixedInt::operator-
FixedInt< N-M > operator-(FixedInt< M >) const
Definition: IntegralConstant.h:68
Eigen::internal::FixedInt::value
static const int value
Definition: IntegralConstant.h:54
Eigen::internal::FixedInt::operator&
FixedInt< N &M > operator&(FixedInt< M >) const
Definition: IntegralConstant.h:78
Eigen::Triplet< double >
Eigen::internal::FixedInt::operator|
FixedInt< N|M > operator|(FixedInt< M >) const
Definition: IntegralConstant.h:76
Eigen::internal::FixedInt::operator/
FixedInt< N/M > operator/(FixedInt< M >) const
Definition: IntegralConstant.h:72
Eigen::internal::FixedInt::operator-
FixedInt<-N > operator-() const
Definition: IntegralConstant.h:64
std
Definition: BFloat16.h:88
Eigen::Default
@ Default
Definition: Constants.h:362
Eigen::internal::FixedInt::operator%
FixedInt< N%M > operator%(FixedInt< M >) const
Definition: IntegralConstant.h:74
Eigen::internal::get_fixed_value::value
static const int value
Definition: IntegralConstant.h:134
N
#define N
Definition: igam.h:9
internal
Definition: BandTriangularSolver.h:13
Eigen::internal::get_fixed_value
Definition: IntegralConstant.h:133
Eigen::internal::enable_if
Definition: Meta.h:273
Eigen::internal::FixedInt::FixedInt
FixedInt(FixedInt< N >(*)())
Definition: IntegralConstant.h:86
Eigen::internal::FixedInt::FixedInt
FixedInt()
Definition: IntegralConstant.h:56
Eigen::internal::cleanup_index_type< T, DynamicKey, typename internal::enable_if< internal::is_integral< T >::value >::type >::type
Index type
Definition: IntegralConstant.h:167
Eigen::internal::VariableAndFixedInt::m_value
int m_value
Definition: IntegralConstant.h:130
test_callbacks.value
value
Definition: test_callbacks.py:160
pybind_wrapper_test_script.other
other
Definition: pybind_wrapper_test_script.py:42
Eigen::internal::cleanup_index_type< FixedInt< N >(*)(), DynamicKey >::type
FixedInt< N > type
Definition: IntegralConstant.h:171
Eigen::internal::FixedInt::FixedInt
FixedInt(VariableAndFixedInt< N > other)
Definition: IntegralConstant.h:57
Eigen::Index
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74
M
Matrix< RealScalar, Dynamic, Dynamic > M
Definition: bench_gemm.cpp:51


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:02:28