NumTraits.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) 2006-2010 Benoit Jacob <jacob.benoit.1@gmail.com>
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_NUMTRAITS_H
11 #define EIGEN_NUMTRAITS_H
12 
13 namespace Eigen {
14 
15 namespace internal {
16 
17 // default implementation of digits10(), based on numeric_limits if specialized,
18 // 0 for integer types, and log10(epsilon()) otherwise.
19 template< typename T,
20  bool use_numeric_limits = std::numeric_limits<T>::is_specialized,
21  bool is_integer = NumTraits<T>::IsInteger>
23 {
24  static int run() { return std::numeric_limits<T>::digits10; }
25 };
26 
27 template<typename T>
28 struct default_digits10_impl<T,false,false> // Floating point
29 {
30  static int run() {
31  using std::log10;
32  using std::ceil;
33  typedef typename NumTraits<T>::Real Real;
35  }
36 };
37 
38 template<typename T>
39 struct default_digits10_impl<T,false,true> // Integer
40 {
41  static int run() { return 0; }
42 };
43 
44 } // end namespace internal
45 
88 template<typename T> struct GenericNumTraits
89 {
90  enum {
91  IsInteger = std::numeric_limits<T>::is_integer,
92  IsSigned = std::numeric_limits<T>::is_signed,
93  IsComplex = 0,
95  ReadCost = 1,
96  AddCost = 1,
97  MulCost = 1
98  };
99 
100  typedef T Real;
101  typedef typename internal::conditional<
102  IsInteger,
103  typename internal::conditional<sizeof(T)<=2, float, double>::type,
104  T
105  >::type NonInteger;
106  typedef T Nested;
107  typedef T Literal;
108 
109  EIGEN_DEVICE_FUNC
110  static inline Real epsilon()
111  {
112  return numext::numeric_limits<T>::epsilon();
113  }
114 
115  EIGEN_DEVICE_FUNC
116  static inline int digits10()
117  {
119  }
120 
121  EIGEN_DEVICE_FUNC
122  static inline Real dummy_precision()
123  {
124  // make sure to override this for floating-point types
125  return Real(0);
126  }
127 
128 
129  EIGEN_DEVICE_FUNC
130  static inline T highest() {
132  }
133 
134  EIGEN_DEVICE_FUNC
135  static inline T lowest() {
136  return IsInteger ? (numext::numeric_limits<T>::min)() : (-(numext::numeric_limits<T>::max)());
137  }
138 
139  EIGEN_DEVICE_FUNC
140  static inline T infinity() {
141  return numext::numeric_limits<T>::infinity();
142  }
143 
144  EIGEN_DEVICE_FUNC
145  static inline T quiet_NaN() {
146  return numext::numeric_limits<T>::quiet_NaN();
147  }
148 };
149 
150 template<typename T> struct NumTraits : GenericNumTraits<T>
151 {};
152 
153 template<> struct NumTraits<float>
154  : GenericNumTraits<float>
155 {
156  EIGEN_DEVICE_FUNC
157  static inline float dummy_precision() { return 1e-5f; }
158 };
159 
160 template<> struct NumTraits<double> : GenericNumTraits<double>
161 {
162  EIGEN_DEVICE_FUNC
163  static inline double dummy_precision() { return 1e-12; }
164 };
165 
166 template<> struct NumTraits<long double>
167  : GenericNumTraits<long double>
168 {
169  static inline long double dummy_precision() { return 1e-15l; }
170 };
171 
172 template<typename _Real> struct NumTraits<std::complex<_Real> >
173  : GenericNumTraits<std::complex<_Real> >
174 {
175  typedef _Real Real;
177  enum {
183  };
184 
185  EIGEN_DEVICE_FUNC
186  static inline Real epsilon() { return NumTraits<Real>::epsilon(); }
187  EIGEN_DEVICE_FUNC
189  EIGEN_DEVICE_FUNC
190  static inline int digits10() { return NumTraits<Real>::digits10(); }
191 };
192 
193 template<typename Scalar, int Rows, int Cols, int Options, int MaxRows, int MaxCols>
194 struct NumTraits<Array<Scalar, Rows, Cols, Options, MaxRows, MaxCols> >
195 {
201  typedef ArrayType & Nested;
203 
204  enum {
209  ReadCost = ArrayType::SizeAtCompileTime==Dynamic ? HugeCost : ArrayType::SizeAtCompileTime * NumTraits<Scalar>::ReadCost,
210  AddCost = ArrayType::SizeAtCompileTime==Dynamic ? HugeCost : ArrayType::SizeAtCompileTime * NumTraits<Scalar>::AddCost,
211  MulCost = ArrayType::SizeAtCompileTime==Dynamic ? HugeCost : ArrayType::SizeAtCompileTime * NumTraits<Scalar>::MulCost
212  };
213 
214  EIGEN_DEVICE_FUNC
215  static inline RealScalar epsilon() { return NumTraits<RealScalar>::epsilon(); }
216  EIGEN_DEVICE_FUNC
218 
219  static inline int digits10() { return NumTraits<Scalar>::digits10(); }
220 };
221 
222 template<> struct NumTraits<std::string>
223  : GenericNumTraits<std::string>
224 {
225  enum {
230  };
231 
232  static inline int digits10() { return 0; }
233 
234 private:
235  static inline std::string epsilon();
236  static inline std::string dummy_precision();
237  static inline std::string lowest();
238  static inline std::string highest();
239  static inline std::string infinity();
240  static inline std::string quiet_NaN();
241 };
242 
243 // Empty specialization for void to allow template specialization based on NumTraits<T>::Real with T==void and SFINAE.
244 template<> struct NumTraits<void> {};
245 
246 } // end namespace Eigen
247 
248 #endif // EIGEN_NUMTRAITS_H
Eigen::NumTraits< Array< Scalar, Rows, Cols, Options, MaxRows, MaxCols > >::epsilon
static EIGEN_DEVICE_FUNC RealScalar epsilon()
Definition: NumTraits.h:215
Eigen::NumTraits< Array< Scalar, Rows, Cols, Options, MaxRows, MaxCols > >::Real
Array< RealScalar, Rows, Cols, Options, MaxRows, MaxCols > Real
Definition: NumTraits.h:198
Eigen::HugeCost
const int HugeCost
Definition: Constants.h:39
Eigen::GenericNumTraits::MulCost
@ MulCost
Definition: NumTraits.h:97
Eigen
Definition: common.h:73
Eigen::GenericNumTraits::IsSigned
@ IsSigned
Definition: NumTraits.h:92
Eigen::NumTraits< std::complex< _Real > >::dummy_precision
static EIGEN_DEVICE_FUNC Real dummy_precision()
Definition: NumTraits.h:188
Eigen::Array
General-purpose arrays with easy API for coefficient-wise operations.
Definition: Array.h:45
Eigen::NumTraits< Array< Scalar, Rows, Cols, Options, MaxRows, MaxCols > >::digits10
static int digits10()
Definition: NumTraits.h:219
Eigen::GenericNumTraits::RequireInitialization
@ RequireInitialization
Definition: NumTraits.h:94
Scalar
SCALAR Scalar
Definition: common.h:84
Eigen::GenericNumTraits::ReadCost
@ ReadCost
Definition: NumTraits.h:95
Eigen::NumTraits< std::complex< _Real > >::digits10
static EIGEN_DEVICE_FUNC int digits10()
Definition: NumTraits.h:190
Eigen::NumTraits< Array< Scalar, Rows, Cols, Options, MaxRows, MaxCols > >::ArrayType
Array< Scalar, Rows, Cols, Options, MaxRows, MaxCols > ArrayType
Definition: NumTraits.h:196
Eigen::GenericNumTraits
Definition: NumTraits.h:88
Eigen::NumTraits< Array< Scalar, Rows, Cols, Options, MaxRows, MaxCols > >::Literal
NumTraits< Scalar >::Literal Literal
Definition: NumTraits.h:202
Eigen::NumTraits< std::string >::digits10
static int digits10()
Definition: NumTraits.h:232
Eigen::GenericNumTraits::AddCost
@ AddCost
Definition: NumTraits.h:96
Eigen::NumTraits< float >::dummy_precision
static EIGEN_DEVICE_FUNC float dummy_precision()
Definition: NumTraits.h:157
Eigen::NumTraits< Array< Scalar, Rows, Cols, Options, MaxRows, MaxCols > >::NonInteger
Array< NonIntegerScalar, Rows, Cols, Options, MaxRows, MaxCols > NonInteger
Definition: NumTraits.h:200
Eigen::GenericNumTraits::IsComplex
@ IsComplex
Definition: NumTraits.h:93
Eigen::NumTraits< Array< Scalar, Rows, Cols, Options, MaxRows, MaxCols > >::RealScalar
NumTraits< Scalar >::Real RealScalar
Definition: NumTraits.h:197
Eigen::Dynamic
const int Dynamic
Definition: Constants.h:21
Eigen::GenericNumTraits::IsInteger
@ IsInteger
Definition: NumTraits.h:91
Eigen::NumTraits< Array< Scalar, Rows, Cols, Options, MaxRows, MaxCols > >::Nested
ArrayType & Nested
Definition: NumTraits.h:201
Eigen::internal::default_digits10_impl
Definition: NumTraits.h:22
Eigen::NumTraits< long double >::dummy_precision
static long double dummy_precision()
Definition: NumTraits.h:169
int
return int(ret)+1
Eigen::NumTraits< std::complex< _Real > >::Literal
NumTraits< _Real >::Literal Literal
Definition: NumTraits.h:176
Eigen::internal::default_digits10_impl< T, false, true >::run
static int run()
Definition: NumTraits.h:41
std
Definition: Half.h:150
Eigen::internal::conditional
Definition: Meta.h:58
min
#define min(a, b)
Definition: datatypes.h:19
ceil
const EIGEN_DEVICE_FUNC CeilReturnType ceil() const
Definition: ArrayCwiseUnaryOps.h:402
internal
Definition: BandTriangularSolver.h:13
Eigen::NumTraits< Array< Scalar, Rows, Cols, Options, MaxRows, MaxCols > >::NonIntegerScalar
NumTraits< Scalar >::NonInteger NonIntegerScalar
Definition: NumTraits.h:199
Eigen::NumTraits< Array< Scalar, Rows, Cols, Options, MaxRows, MaxCols > >::dummy_precision
static EIGEN_DEVICE_FUNC RealScalar dummy_precision()
Definition: NumTraits.h:217
Eigen::NumTraits< std::complex< _Real > >::epsilon
static EIGEN_DEVICE_FUNC Real epsilon()
Definition: NumTraits.h:186
Eigen::internal::default_digits10_impl< T, false, false >::run
static int run()
Definition: NumTraits.h:30
max
#define max(a, b)
Definition: datatypes.h:20
Eigen::internal::default_digits10_impl::run
static int run()
Definition: NumTraits.h:24
Eigen::NumTraits
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition: NumTraits.h:150
log10
const EIGEN_DEVICE_FUNC Log10ReturnType log10() const
Definition: ArrayCwiseUnaryOps.h:135
Eigen::GenericNumTraits::Real
T Real
Definition: NumTraits.h:100
Eigen::NumTraits< std::complex< _Real > >::Real
_Real Real
Definition: NumTraits.h:175
complex
Definition: datatypes.h:12
Eigen::internal::is_arithmetic
Definition: Meta.h:85
Eigen::NumTraits< double >::dummy_precision
static EIGEN_DEVICE_FUNC double dummy_precision()
Definition: NumTraits.h:163


control_box_rst
Author(s): Christoph Rösmann
autogenerated on Wed Mar 2 2022 00:05:58