Medial Code Documentation
Loading...
Searching...
No Matches
Meta.h
1// This file is part of Eigen, a lightweight C++ template library
2// for linear algebra.
3//
4// Copyright (C) 2008-2015 Gael Guennebaud <gael.guennebaud@inria.fr>
5// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
6//
7// This Source Code Form is subject to the terms of the Mozilla
8// Public License v. 2.0. If a copy of the MPL was not distributed
9// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
10
11#ifndef EIGEN_META_H
12#define EIGEN_META_H
13
14#if defined(__CUDA_ARCH__)
15#include <cfloat>
16#include <math_constants.h>
17#endif
18
19namespace Eigen {
20
21namespace internal {
22
30struct true_type { enum { value = 1 }; };
31struct false_type { enum { value = 0 }; };
32
33template<bool Condition, typename Then, typename Else>
34struct conditional { typedef Then type; };
35
36template<typename Then, typename Else>
37struct conditional <false, Then, Else> { typedef Else type; };
38
39template<typename T, typename U> struct is_same { enum { value = 0 }; };
40template<typename T> struct is_same<T,T> { enum { value = 1 }; };
41
42template<typename T> struct remove_reference { typedef T type; };
43template<typename T> struct remove_reference<T&> { typedef T type; };
44
45template<typename T> struct remove_pointer { typedef T type; };
46template<typename T> struct remove_pointer<T*> { typedef T type; };
47template<typename T> struct remove_pointer<T*const> { typedef T type; };
48
49template <class T> struct remove_const { typedef T type; };
50template <class T> struct remove_const<const T> { typedef T type; };
51template <class T> struct remove_const<const T[]> { typedef T type[]; };
52template <class T, unsigned int Size> struct remove_const<const T[Size]> { typedef T type[Size]; };
53
54template<typename T> struct remove_all { typedef T type; };
55template<typename T> struct remove_all<const T> { typedef typename remove_all<T>::type type; };
56template<typename T> struct remove_all<T const&> { typedef typename remove_all<T>::type type; };
57template<typename T> struct remove_all<T&> { typedef typename remove_all<T>::type type; };
58template<typename T> struct remove_all<T const*> { typedef typename remove_all<T>::type type; };
59template<typename T> struct remove_all<T*> { typedef typename remove_all<T>::type type; };
60
61template<typename T> struct is_arithmetic { enum { value = false }; };
62template<> struct is_arithmetic<float> { enum { value = true }; };
63template<> struct is_arithmetic<double> { enum { value = true }; };
64template<> struct is_arithmetic<long double> { enum { value = true }; };
65template<> struct is_arithmetic<bool> { enum { value = true }; };
66template<> struct is_arithmetic<char> { enum { value = true }; };
67template<> struct is_arithmetic<signed char> { enum { value = true }; };
68template<> struct is_arithmetic<unsigned char> { enum { value = true }; };
69template<> struct is_arithmetic<signed short> { enum { value = true }; };
70template<> struct is_arithmetic<unsigned short>{ enum { value = true }; };
71template<> struct is_arithmetic<signed int> { enum { value = true }; };
72template<> struct is_arithmetic<unsigned int> { enum { value = true }; };
73template<> struct is_arithmetic<signed long> { enum { value = true }; };
74template<> struct is_arithmetic<unsigned long> { enum { value = true }; };
75
76template<typename T> struct is_integral { enum { value = false }; };
77template<> struct is_integral<bool> { enum { value = true }; };
78template<> struct is_integral<char> { enum { value = true }; };
79template<> struct is_integral<signed char> { enum { value = true }; };
80template<> struct is_integral<unsigned char> { enum { value = true }; };
81template<> struct is_integral<signed short> { enum { value = true }; };
82template<> struct is_integral<unsigned short> { enum { value = true }; };
83template<> struct is_integral<signed int> { enum { value = true }; };
84template<> struct is_integral<unsigned int> { enum { value = true }; };
85template<> struct is_integral<signed long> { enum { value = true }; };
86template<> struct is_integral<unsigned long> { enum { value = true }; };
87
88template <typename T> struct add_const { typedef const T type; };
89template <typename T> struct add_const<T&> { typedef T& type; };
90
91template <typename T> struct is_const { enum { value = 0 }; };
92template <typename T> struct is_const<T const> { enum { value = 1 }; };
93
94template<typename T> struct add_const_on_value_type { typedef const T type; };
95template<typename T> struct add_const_on_value_type<T&> { typedef T const& type; };
96template<typename T> struct add_const_on_value_type<T*> { typedef T const* type; };
97template<typename T> struct add_const_on_value_type<T* const> { typedef T const* const type; };
98template<typename T> struct add_const_on_value_type<T const* const> { typedef T const* const type; };
99
100
101template<typename From, typename To>
103{
104private:
105 struct any_conversion
106 {
107 template <typename T> any_conversion(const volatile T&);
108 template <typename T> any_conversion(T&);
109 };
110 struct yes {int a[1];};
111 struct no {int a[2];};
112
113 static yes test(const To&, int);
114 static no test(any_conversion, ...);
115
116public:
117 static From ms_from;
118 enum { value = sizeof(test(ms_from, 0))==sizeof(yes) };
119};
120
121template<typename From, typename To>
123{
125 typename remove_all<To >::type>::value };
126};
127
131template<bool Condition, typename T> struct enable_if;
132
133template<typename T> struct enable_if<true,T>
134{ typedef T type; };
135
136#if defined(__CUDA_ARCH__)
137#if !defined(__FLT_EPSILON__)
138#define __FLT_EPSILON__ FLT_EPSILON
139#define __DBL_EPSILON__ DBL_EPSILON
140#endif
141
142namespace device {
143
144template<typename T> struct numeric_limits
145{
147 static T epsilon() { return 0; }
148 static T (max)() { assert(false && "Highest not supported for this type"); }
149 static T (min)() { assert(false && "Lowest not supported for this type"); }
150};
151template<> struct numeric_limits<float>
152{
153 EIGEN_DEVICE_FUNC
154 static float epsilon() { return __FLT_EPSILON__; }
155 EIGEN_DEVICE_FUNC
156 static float (max)() { return CUDART_MAX_NORMAL_F; }
157 EIGEN_DEVICE_FUNC
158 static float (min)() { return FLT_MIN; }
159};
160template<> struct numeric_limits<double>
161{
162 EIGEN_DEVICE_FUNC
163 static double epsilon() { return __DBL_EPSILON__; }
164 EIGEN_DEVICE_FUNC
165 static double (max)() { return DBL_MAX; }
166 EIGEN_DEVICE_FUNC
167 static double (min)() { return DBL_MIN; }
168};
169template<> struct numeric_limits<int>
170{
171 EIGEN_DEVICE_FUNC
172 static int epsilon() { return 0; }
173 EIGEN_DEVICE_FUNC
174 static int (max)() { return INT_MAX; }
175 EIGEN_DEVICE_FUNC
176 static int (min)() { return INT_MIN; }
177};
178template<> struct numeric_limits<unsigned int>
179{
180 EIGEN_DEVICE_FUNC
181 static unsigned int epsilon() { return 0; }
182 EIGEN_DEVICE_FUNC
183 static unsigned int (max)() { return UINT_MAX; }
184 EIGEN_DEVICE_FUNC
185 static unsigned int (min)() { return 0; }
186};
187template<> struct numeric_limits<long>
188{
189 EIGEN_DEVICE_FUNC
190 static long epsilon() { return 0; }
191 EIGEN_DEVICE_FUNC
192 static long (max)() { return LONG_MAX; }
193 EIGEN_DEVICE_FUNC
194 static long (min)() { return LONG_MIN; }
195};
196template<> struct numeric_limits<unsigned long>
197{
198 EIGEN_DEVICE_FUNC
199 static unsigned long epsilon() { return 0; }
200 EIGEN_DEVICE_FUNC
201 static unsigned long (max)() { return ULONG_MAX; }
202 EIGEN_DEVICE_FUNC
203 static unsigned long (min)() { return 0; }
204};
205template<> struct numeric_limits<long long>
206{
207 EIGEN_DEVICE_FUNC
208 static long long epsilon() { return 0; }
209 EIGEN_DEVICE_FUNC
210 static long long (max)() { return LLONG_MAX; }
211 EIGEN_DEVICE_FUNC
212 static long long (min)() { return LLONG_MIN; }
213};
214template<> struct numeric_limits<unsigned long long>
215{
216 EIGEN_DEVICE_FUNC
217 static unsigned long long epsilon() { return 0; }
218 EIGEN_DEVICE_FUNC
219 static unsigned long long (max)() { return ULLONG_MAX; }
220 EIGEN_DEVICE_FUNC
221 static unsigned long long (min)() { return 0; }
222};
223
224}
225
226#endif
227
232{
234 EIGEN_DEVICE_FUNC const noncopyable& operator=(const noncopyable&);
235protected:
238};
239
247#ifdef EIGEN_HAS_STD_RESULT_OF
248template<typename T> struct result_of {
249 typedef typename std::result_of<T>::type type1;
250 typedef typename remove_all<type1>::type type;
251};
252#else
253template<typename T> struct result_of { };
254
255struct has_none {int a[1];};
256struct has_std_result_type {int a[2];};
257struct has_tr1_result {int a[3];};
258
259template<typename Func, typename ArgType, int SizeOf=sizeof(has_none)>
260struct unary_result_of_select {typedef ArgType type;};
261
262template<typename Func, typename ArgType>
263struct unary_result_of_select<Func, ArgType, sizeof(has_std_result_type)> {typedef typename Func::result_type type;};
264
265template<typename Func, typename ArgType>
266struct unary_result_of_select<Func, ArgType, sizeof(has_tr1_result)> {typedef typename Func::template result<Func(ArgType)>::type type;};
267
268template<typename Func, typename ArgType>
269struct result_of<Func(ArgType)> {
270 template<typename T>
271 static has_std_result_type testFunctor(T const *, typename T::result_type const * = 0);
272 template<typename T>
273 static has_tr1_result testFunctor(T const *, typename T::template result<T(ArgType)>::type const * = 0);
274 static has_none testFunctor(...);
275
276 // note that the following indirection is needed for gcc-3.3
277 enum {FunctorType = sizeof(testFunctor(static_cast<Func*>(0)))};
278 typedef typename unary_result_of_select<Func, ArgType, FunctorType>::type type;
279};
280
281template<typename Func, typename ArgType0, typename ArgType1, int SizeOf=sizeof(has_none)>
283
284template<typename Func, typename ArgType0, typename ArgType1>
286{typedef typename Func::result_type type;};
287
288template<typename Func, typename ArgType0, typename ArgType1>
290{typedef typename Func::template result<Func(ArgType0,ArgType1)>::type type;};
291
292template<typename Func, typename ArgType0, typename ArgType1>
294 template<typename T>
295 static has_std_result_type testFunctor(T const *, typename T::result_type const * = 0);
296 template<typename T>
297 static has_tr1_result testFunctor(T const *, typename T::template result<T(ArgType0,ArgType1)>::type const * = 0);
298 static has_none testFunctor(...);
299
300 // note that the following indirection is needed for gcc-3.3
301 enum {FunctorType = sizeof(testFunctor(static_cast<Func*>(0)))};
303};
304#endif
305
309template<int Y,
310 int InfX = 0,
311 int SupX = ((Y==1) ? 1 : Y/2),
312 bool Done = ((SupX-InfX)<=1 ? true : ((SupX*SupX <= Y) && ((SupX+1)*(SupX+1) > Y))) >
313 // use ?: instead of || just to shut up a stupid gcc 4.3 warning
315{
316 enum {
317 MidX = (InfX+SupX)/2,
318 TakeInf = MidX*MidX > Y ? 1 : 0,
319 NewInf = int(TakeInf) ? InfX : int(MidX),
320 NewSup = int(TakeInf) ? int(MidX) : SupX
321 };
322 public:
323 enum { ret = meta_sqrt<Y,NewInf,NewSup>::ret };
324};
325
326template<int Y, int InfX, int SupX>
327class meta_sqrt<Y, InfX, SupX, true> { public: enum { ret = (SupX*SupX <= Y) ? SupX : InfX }; };
328
330template<typename T, typename U> struct scalar_product_traits
331{
332 enum { Defined = 0 };
333};
334
335template<typename T> struct scalar_product_traits<T,T>
336{
337 enum {
338 // Cost = NumTraits<T>::MulCost,
339 Defined = 1
340 };
341 typedef T ReturnType;
342};
343
344template<typename T> struct scalar_product_traits<T,std::complex<T> >
345{
346 enum {
347 // Cost = 2*NumTraits<T>::MulCost,
348 Defined = 1
349 };
350 typedef std::complex<T> ReturnType;
351};
352
353template<typename T> struct scalar_product_traits<std::complex<T>, T>
354{
355 enum {
356 // Cost = 2*NumTraits<T>::MulCost,
357 Defined = 1
358 };
359 typedef std::complex<T> ReturnType;
360};
361
362// FIXME quick workaround around current limitation of result_of
363// template<typename Scalar, typename ArgType0, typename ArgType1>
364// struct result_of<scalar_product_op<Scalar>(ArgType0,ArgType1)> {
365// typedef typename scalar_product_traits<typename remove_all<ArgType0>::type, typename remove_all<ArgType1>::type>::ReturnType type;
366// };
367
368} // end namespace internal
369
370namespace numext {
371
372#if defined(__CUDA_ARCH__)
373template<typename T> EIGEN_DEVICE_FUNC void swap(T &a, T &b) { T tmp = b; b = a; a = tmp; }
374#else
375template<typename T> EIGEN_STRONG_INLINE void swap(T &a, T &b) { std::swap(a,b); }
376#endif
377
378// Integer division with rounding up.
379// T is assumed to be an integer type with a>=0, and b>0
380template<typename T>
381T div_ceil(const T &a, const T &b)
382{
383 return (a+b-1) / b;
384}
385
386} // end namespace numext
387
388} // end namespace Eigen
389
390#endif // EIGEN_META_H
Pseudo expression representing a solving operation.
Definition Solve.h:63
Definition Meta.h:315
Definition Meta.h:232
Definition StdDeque.h:58
NLOHMANN_BASIC_JSON_TPL_DECLARATION void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL &j1, nlohmann::NLOHMANN_BASIC_JSON_TPL &j2) noexcept(//NOLINT(readability-inconsistent-declaration-parameter-name, cert-dcl58-cpp) is_nothrow_move_constructible< nlohmann::NLOHMANN_BASIC_JSON_TPL >::value &&//NOLINT(misc-redundant-expression) is_nothrow_move_assignable< nlohmann::NLOHMANN_BASIC_JSON_TPL >::value)
exchanges the values of two JSON objects
Definition json.hpp:24418
Definition Meta.h:88
Definition Meta.h:34
Definition Meta.h:131
Definition Meta.h:31
Definition Meta.h:255
Definition Meta.h:257
Definition Meta.h:61
Definition Meta.h:91
Definition Meta.h:123
Definition Meta.h:76
Definition Meta.h:39
Definition Meta.h:54
Definition Meta.h:49
Definition Meta.h:253
Definition Meta.h:30