TensorMeta.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) 2015 Benoit Steiner <benoit.steiner.goog@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_CXX11_TENSOR_TENSOR_META_H
11 #define EIGEN_CXX11_TENSOR_TENSOR_META_H
12 
13 namespace Eigen {
14 
15 template<bool cond> struct Cond {};
16 
17 template<typename T1, typename T2> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
18 const T1& choose(Cond<true>, const T1& first, const T2&) {
19  return first;
20 }
21 
22 template<typename T1, typename T2> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
23 const T2& choose(Cond<false>, const T1&, const T2& second) {
24  return second;
25 }
26 
27 
28 template <typename T, typename X, typename Y>
30 T divup(const X x, const Y y) {
31  return static_cast<T>((x + y - 1) / y);
32 }
33 
34 template <typename T>
36 T divup(const T x, const T y) {
37  return static_cast<T>((x + y - 1) / y);
38 }
39 
40 template <size_t n> struct max_n_1 {
41  static const size_t size = n;
42 };
43 template <> struct max_n_1<0> {
44  static const size_t size = 1;
45 };
46 
47 
48 // Default packet types
49 template <typename Scalar, typename Device>
52 };
53 
54 // For CUDA packet types when using a GpuDevice
55 #if defined(EIGEN_USE_GPU) && defined(EIGEN_HAS_GPU_FP16)
56 
57 typedef ulonglong2 Packet4h2;
58 template<>
59 struct PacketType<half, GpuDevice> {
60  typedef Packet4h2 type;
61  static const int size = 8;
62  enum {
63  HasAdd = 1,
64  HasSub = 1,
65  HasMul = 1,
66  HasNegate = 1,
67  HasAbs = 1,
68  HasArg = 0,
69  HasAbs2 = 0,
70  HasMin = 1,
71  HasMax = 1,
72  HasConj = 0,
73  HasSetLinear = 0,
74  HasBlend = 0,
75 
76  HasDiv = 1,
77  HasSqrt = 1,
78  HasRsqrt = 1,
79  HasExp = 1,
80  HasExpm1 = 0,
81  HasLog = 1,
82  HasLog1p = 0,
83  HasLog10 = 0,
84  HasPow = 1,
85  };
86 };
87 #endif
88 
89 #if defined(EIGEN_USE_SYCL)
90 
91 namespace TensorSycl {
92 namespace internal {
93 
94 template <typename Index, Index A, Index B> struct PlusOp {
95  static constexpr Index Value = A + B;
96 };
97 
98 template <typename Index, Index A, Index B> struct DivOp {
99  static constexpr Index Value = A / B;
100 };
101 
102 template <typename Index, Index start, Index end, Index step,
103  template <class Indx, Indx...> class StepOp>
104 struct static_for {
105  template <typename UnaryOperator>
106  static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void loop(UnaryOperator op) {
107  op(start);
108  static_for<Index, StepOp<Index, start, step>::Value, end, step,
109  StepOp>::loop(op);
110  }
111 };
112 template <typename Index, Index end, Index step,
113  template <class Indx, Indx...> class StepOp>
114 struct static_for<Index, end, end, step, StepOp> {
115  template <typename UnaryOperator>
116  static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void loop(UnaryOperator) {}
117 };
118 
119 template <typename OutScalar, typename Device, bool Vectorizable>
120 struct Vectorise {
121  static const int PacketSize = 1;
122  typedef OutScalar PacketReturnType;
123 };
124 
125 template <typename OutScalar, typename Device>
126 struct Vectorise<OutScalar, Device, true> {
127  static const int PacketSize = Eigen::PacketType<OutScalar, Device>::size;
128  typedef typename Eigen::PacketType<OutScalar, Device>::type PacketReturnType;
129 };
130 
132  return ((((x) + (y)-1) / (y)) * (y));
133 }
134 
135 } // namespace internal
136 } // namespace TensorSycl
137 
138 template <>
139  struct PacketType<half, SyclDevice> {
140  typedef half type;
141  static const int size = 1;
142  enum {
143  HasAdd = 0,
144  HasSub = 0,
145  HasMul = 0,
146  HasNegate = 0,
147  HasAbs = 0,
148  HasArg = 0,
149  HasAbs2 = 0,
150  HasMin = 0,
151  HasMax = 0,
152  HasConj = 0,
153  HasSetLinear = 0,
154  HasBlend = 0
155  };
156 };
157 template <typename Scalar>
158 struct PacketType<Scalar, SyclDevice> : internal::default_packet_traits {
159  typedef Scalar type;
160  typedef Scalar half;
161  enum {
162  Vectorizable = 0,
163  size = 1,
164  AlignedOnScalar = 0,
165  HasHalfPacket = 0
166  };
167  enum {
168  HasAdd = 0,
169  HasSub = 0,
170  HasMul = 0,
171  HasNegate = 0,
172  HasAbs = 0,
173  HasAbs2 = 0,
174  HasMin = 0,
175  HasMax = 0,
176  HasConj = 0,
177  HasSetLinear = 0
178  };
179 
180 };
181 
182 template <typename Scalar>
183 struct PacketType<Scalar, const SyclDevice> : PacketType<Scalar, SyclDevice>{};
184 
185 #ifndef EIGEN_DONT_VECTORIZE_SYCL
186 #define PACKET_TYPE(CVQual, Type, val, lengths, DEV)\
187 template<> struct PacketType<CVQual Type, DEV> : internal::sycl_packet_traits<val, lengths> \
188 {\
189  typedef typename internal::packet_traits<Type>::type type;\
190  typedef typename internal::packet_traits<Type>::half half;\
191 };
192 
193 
194 PACKET_TYPE(const, float, 1, 4, SyclDevice)
195 PACKET_TYPE(, float, 1, 4, SyclDevice)
196 PACKET_TYPE(const, float, 1, 4, const SyclDevice)
197 PACKET_TYPE(, float, 1, 4, const SyclDevice)
198 
199 PACKET_TYPE(const, double, 0, 2, SyclDevice)
200 PACKET_TYPE(, double, 0, 2, SyclDevice)
201 PACKET_TYPE(const, double, 0, 2, const SyclDevice)
202 PACKET_TYPE(, double, 0, 2, const SyclDevice)
203 #undef PACKET_TYPE
204 
205 template<> struct PacketType<half, const SyclDevice>: PacketType<half, SyclDevice>{};
206 template<> struct PacketType<const half, const SyclDevice>: PacketType<half, SyclDevice>{};
207 #endif
208 #endif
209 
210 // Tuple mimics std::pair but works on e.g. nvcc.
211 template <typename U, typename V> struct Tuple {
212  public:
215 
216  typedef U first_type;
217  typedef V second_type;
218 
220  Tuple() : first(), second() {}
221 
223  Tuple(const U& f, const V& s) : first(f), second(s) {}
224 
226  void swap(Tuple& rhs) {
227  using numext::swap;
228  swap(first, rhs.first);
229  swap(second, rhs.second);
230  }
231 };
232 
233 template <typename U, typename V>
235 bool operator==(const Tuple<U, V>& x, const Tuple<U, V>& y) {
236  return (x.first == y.first && x.second == y.second);
237 }
238 
239 template <typename U, typename V>
241 bool operator!=(const Tuple<U, V>& x, const Tuple<U, V>& y) {
242  return !(x == y);
243 }
244 
245 
246 // Can't use std::pairs on cuda devices
247 template <typename Idx> struct IndexPair {
250 
252  first = val.first;
253  second = val.second;
254  }
255 
256  Idx first;
257  Idx second;
258 };
259 
260 
261 #ifdef EIGEN_HAS_SFINAE
262 namespace internal {
263 
264  template<typename IndexType, typename Index, Index... Is>
266  array<Index, sizeof...(Is)> customIndices2Array(IndexType& idx, numeric_list<Index, Is...>) {
267  return { idx[Is]... };
268  }
269  template<typename IndexType, typename Index>
271  array<Index, 0> customIndices2Array(IndexType&, numeric_list<Index>) {
272  return array<Index, 0>();
273  }
274 
276  template<typename Index, std::size_t NumIndices, typename IndexType>
278  array<Index, NumIndices> customIndices2Array(IndexType& idx) {
279  return customIndices2Array(idx, typename gen_numeric_list<Index, NumIndices>::type{});
280  }
281 
282 
283  template <typename B, typename D>
284  struct is_base_of
285  {
286 
287  typedef char (&yes)[1];
288  typedef char (&no)[2];
289 
290  template <typename BB, typename DD>
291  struct Host
292  {
293  operator BB*() const;
294  operator DD*();
295  };
296 
297  template<typename T>
298  static yes check(D*, T);
299  static no check(B*, int);
300 
301  static const bool value = sizeof(check(Host<B,D>(), int())) == sizeof(yes);
302  };
303 
304 }
305 #endif
306 
307 
308 
309 } // namespace Eigen
310 
311 #endif // EIGEN_CXX11_TENSOR_TENSOR_META_H
EIGEN_DEVICE_FUNC
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:976
Eigen::operator!=
EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool operator!=(const Tuple< U, V > &x, const Tuple< U, V > &y)
Definition: TensorMeta.h:241
Eigen::internal::packet_traits< Scalar >::HasAbs
@ HasAbs
Definition: GenericPacketMath.h:121
Eigen
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
Eigen::internal::default_packet_traits::HasLog10
@ HasLog10
Definition: GenericPacketMath.h:72
D
MatrixXcd D
Definition: EigenSolver_EigenSolver_MatrixType.cpp:14
Eigen::internal::default_packet_traits::HasLog
@ HasLog
Definition: GenericPacketMath.h:70
Eigen::internal::packet_traits< Scalar >::HasSub
@ HasSub
Definition: GenericPacketMath.h:118
gtsam.examples.DogLegOptimizerExample.type
type
Definition: DogLegOptimizerExample.py:111
Eigen::internal::packet_traits< Scalar >::size
@ size
Definition: GenericPacketMath.h:112
s
RealScalar s
Definition: level1_cplx_impl.h:126
Eigen::IndexPair::IndexPair
EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE IndexPair()
Definition: TensorMeta.h:248
Eigen::array
Definition: EmulateArray.h:21
Eigen::IndexPair::second
Idx second
Definition: TensorMeta.h:257
gtsam::Y
GaussianFactorGraphValuePair Y
Definition: HybridGaussianProductFactor.cpp:29
Eigen::Tuple
Definition: TensorMeta.h:211
Eigen::internal::default_packet_traits::HasLog1p
@ HasLog1p
Definition: GenericPacketMath.h:71
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::internal::packet_traits
Definition: GenericPacketMath.h:106
B
Definition: test_numpy_dtypes.cpp:299
EIGEN_CONSTEXPR
#define EIGEN_CONSTEXPR
Definition: Macros.h:787
Eigen::PacketType::type
internal::packet_traits< Scalar >::type type
Definition: TensorMeta.h:51
Eigen::internal::packet_traits< Scalar >::HasMin
@ HasMin
Definition: GenericPacketMath.h:123
Eigen::internal::default_packet_traits::HasPow
@ HasPow
Definition: GenericPacketMath.h:73
X
#define X
Definition: icosphere.cpp:20
Eigen::internal::default_packet_traits::HasBlend
@ HasBlend
Definition: GenericPacketMath.h:60
Eigen::IndexPair
Definition: TensorMeta.h:247
Eigen::IndexPair::set
EIGEN_DEVICE_FUNC void set(IndexPair< Idx > val)
Definition: TensorMeta.h:251
Eigen::internal::packet_traits< Scalar >::HasHalfPacket
@ HasHalfPacket
Definition: GenericPacketMath.h:114
Eigen::Tuple::Tuple
EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Tuple()
Definition: TensorMeta.h:220
n
int n
Definition: BiCGSTAB_simple.cpp:1
Eigen::PacketType
Definition: TensorMeta.h:50
A
Definition: test_numpy_dtypes.cpp:298
Eigen::Cond
Definition: TensorMeta.h:15
Eigen::internal::packet_traits< Scalar >::HasConj
@ HasConj
Definition: GenericPacketMath.h:125
Eigen::internal::packet_traits< Scalar >::AlignedOnScalar
@ AlignedOnScalar
Definition: GenericPacketMath.h:113
Eigen::internal::packet_traits< Scalar >::half
Scalar half
Definition: GenericPacketMath.h:109
check
void check(bool b, bool ref)
Definition: fastmath.cpp:12
Eigen::IndexPair::first
Idx first
Definition: TensorMeta.h:256
Eigen::max_n_1
Definition: TensorMeta.h:40
EIGEN_STRONG_INLINE
#define EIGEN_STRONG_INLINE
Definition: Macros.h:917
gtsam::utils.visual_isam.step
def step(data, isam, result, truth, currPoseIndex, isamArgs=())
Definition: visual_isam.py:82
Eigen::internal::default_packet_traits::HasSqrt
@ HasSqrt
Definition: GenericPacketMath.h:66
EIGEN_ALWAYS_INLINE
#define EIGEN_ALWAYS_INLINE
Definition: Macros.h:932
T2
static const Pose3 T2(Rot3::Rodrigues(0.3, 0.2, 0.1), P2)
Eigen::Triplet< double >
Eigen::IndexPair::IndexPair
EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE IndexPair(Idx f, Idx s)
Definition: TensorMeta.h:249
Eigen::Tuple::Tuple
EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Tuple(const U &f, const V &s)
Definition: TensorMeta.h:223
Eigen::Tuple::second_type
V second_type
Definition: TensorMeta.h:217
y
Scalar * y
Definition: level1_cplx_impl.h:124
tree::f
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
Definition: testExpression.cpp:218
array
Definition: numpy.h:821
Eigen::internal::packet_traits< Scalar >::HasAbs2
@ HasAbs2
Definition: GenericPacketMath.h:122
Eigen::internal::default_packet_traits::HasExp
@ HasExp
Definition: GenericPacketMath.h:68
Eigen::operator==
EIGEN_CONSTEXPR EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool operator==(const Tuple< U, V > &x, const Tuple< U, V > &y)
Definition: TensorMeta.h:235
Eigen::numext::swap
EIGEN_STRONG_INLINE void swap(T &a, T &b)
Definition: Meta.h:766
Eigen::internal::default_packet_traits::HasRsqrt
@ HasRsqrt
Definition: GenericPacketMath.h:67
Eigen::max_n_1::size
static const size_t size
Definition: TensorMeta.h:41
Eigen::internal::default_packet_traits::HasExpm1
@ HasExpm1
Definition: GenericPacketMath.h:69
Eigen::Tuple::first_type
U first_type
Definition: TensorMeta.h:216
Eigen::internal::packet_traits< Scalar >::HasAdd
@ HasAdd
Definition: GenericPacketMath.h:117
Eigen::internal::packet_traits< Scalar >::HasMax
@ HasMax
Definition: GenericPacketMath.h:124
U
@ U
Definition: testDecisionTree.cpp:342
Eigen::Tuple::swap
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void swap(Tuple &rhs)
Definition: TensorMeta.h:226
Eigen::internal::packet_traits< Scalar >::HasNegate
@ HasNegate
Definition: GenericPacketMath.h:120
V
MatrixXcd V
Definition: EigenSolver_EigenSolver_MatrixType.cpp:15
Eigen::internal::default_packet_traits::HasDiv
@ HasDiv
Definition: GenericPacketMath.h:65
internal
Definition: BandTriangularSolver.h:13
Eigen::Tuple::first
U first
Definition: TensorMeta.h:213
Eigen::choose
EIGEN_DEVICE_FUNC const EIGEN_ALWAYS_INLINE T1 & choose(Cond< true >, const T1 &first, const T2 &)
Definition: TensorMeta.h:18
Eigen::divup
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE T divup(const X x, const Y y)
Definition: TensorMeta.h:30
Eigen::placeholders::end
static const EIGEN_DEPRECATED end_t end
Definition: IndexedViewHelper.h:181
T1
static const Similarity3 T1(R, Point3(3.5, -8.2, 4.2), 1)
Eigen::half
Definition: Half.h:142
Eigen::internal::default_packet_traits::HasArg
@ HasArg
Definition: GenericPacketMath.h:53
Eigen::Tuple::second
V second
Definition: TensorMeta.h:214
Eigen::internal::packet_traits< Scalar >::HasMul
@ HasMul
Definition: GenericPacketMath.h:119
Eigen::internal::packet_traits< Scalar >::Vectorizable
@ Vectorizable
Definition: GenericPacketMath.h:111
test_callbacks.value
value
Definition: test_callbacks.py:160
Scalar
SCALAR Scalar
Definition: bench_gemm.cpp:46
Eigen::internal::packet_traits< Scalar >::HasSetLinear
@ HasSetLinear
Definition: GenericPacketMath.h:126
Eigen::Index
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74


gtsam
Author(s):
autogenerated on Thu Dec 19 2024 04:05:02