TensorTraits.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) 2014 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_TRAITS_H
11 #define EIGEN_CXX11_TENSOR_TENSOR_TRAITS_H
12 
13 namespace Eigen {
14 namespace internal {
15 
16 
17 template<typename Scalar, int Options>
19 {
20  enum {
22 
24  (
25  ((Options&DontAlign)==0) && (
26 #if EIGEN_MAX_STATIC_ALIGN_BYTES>0
28 #else
29  0
30 #endif
31  |
34 #else
35  0
36 #endif
37  )
38  ),
40  };
41 
42  public:
43  enum { ret = packet_access_bit };
44 };
45 
46 
47 template<typename Scalar_, int NumIndices_, int Options_, typename IndexType_>
48 struct traits<Tensor<Scalar_, NumIndices_, Options_, IndexType_> >
49 {
50  typedef Scalar_ Scalar;
51  typedef Dense StorageKind;
52  typedef IndexType_ Index;
53  static const int NumDimensions = NumIndices_;
54  static const int Layout = Options_ & RowMajor ? RowMajor : ColMajor;
55  enum {
56  Options = Options_,
58  };
59  template <typename T> struct MakePointer {
60  typedef T* Type;
61  };
63 };
64 
65 
66 template<typename Scalar_, typename Dimensions, int Options_, typename IndexType_>
67 struct traits<TensorFixedSize<Scalar_, Dimensions, Options_, IndexType_> >
68 {
69  typedef Scalar_ Scalar;
70  typedef Dense StorageKind;
71  typedef IndexType_ Index;
72  static const int NumDimensions = array_size<Dimensions>::value;
73  static const int Layout = Options_ & RowMajor ? RowMajor : ColMajor;
74  enum {
75  Options = Options_,
77  };
78  template <typename T> struct MakePointer {
79  typedef T* Type;
80  };
82 };
83 
84 
85 template<typename PlainObjectType, int Options_, template <class> class MakePointer_>
86 struct traits<TensorMap<PlainObjectType, Options_, MakePointer_> >
87  : public traits<PlainObjectType>
88 {
90  typedef typename BaseTraits::Scalar Scalar;
91  typedef typename BaseTraits::StorageKind StorageKind;
92  typedef typename BaseTraits::Index Index;
93  static const int NumDimensions = BaseTraits::NumDimensions;
94  static const int Layout = BaseTraits::Layout;
95  enum {
96  Options = Options_,
97  Flags = BaseTraits::Flags
98  };
99  template <class T> struct MakePointer {
100  // Intermediate typedef to workaround MSVC issue.
101  typedef MakePointer_<T> MakePointerT;
102  typedef typename MakePointerT::Type Type;
103  };
105 };
106 
107 template<typename PlainObjectType>
108 struct traits<TensorRef<PlainObjectType> >
109  : public traits<PlainObjectType>
110 {
112  typedef typename BaseTraits::Scalar Scalar;
113  typedef typename BaseTraits::StorageKind StorageKind;
114  typedef typename BaseTraits::Index Index;
115  static const int NumDimensions = BaseTraits::NumDimensions;
116  static const int Layout = BaseTraits::Layout;
117  enum {
118  Options = BaseTraits::Options,
119  Flags = BaseTraits::Flags
120  };
121  typedef typename BaseTraits::PointerType PointerType;
122 };
123 
124 
125 template<typename _Scalar, int NumIndices_, int Options, typename IndexType_>
126 struct eval<Tensor<_Scalar, NumIndices_, Options, IndexType_>, Eigen::Dense>
127 {
129 };
130 
131 template<typename _Scalar, int NumIndices_, int Options, typename IndexType_>
132 struct eval<const Tensor<_Scalar, NumIndices_, Options, IndexType_>, Eigen::Dense>
133 {
135 };
136 
137 template<typename Scalar_, typename Dimensions, int Options, typename IndexType_>
138 struct eval<TensorFixedSize<Scalar_, Dimensions, Options, IndexType_>, Eigen::Dense>
139 {
141 };
142 
143 template<typename Scalar_, typename Dimensions, int Options, typename IndexType_>
144 struct eval<const TensorFixedSize<Scalar_, Dimensions, Options, IndexType_>, Eigen::Dense>
145 {
147 };
148 
149 template<typename PlainObjectType, int Options, template <class> class MakePointer>
150 struct eval<TensorMap<PlainObjectType, Options, MakePointer>, Eigen::Dense>
151 {
153 };
154 
155 template<typename PlainObjectType, int Options, template <class> class MakePointer>
156 struct eval<const TensorMap<PlainObjectType, Options, MakePointer>, Eigen::Dense>
157 {
159 };
160 
161 template<typename PlainObjectType>
162 struct eval<TensorRef<PlainObjectType>, Eigen::Dense>
163 {
165 };
166 
167 template<typename PlainObjectType>
168 struct eval<const TensorRef<PlainObjectType>, Eigen::Dense>
169 {
171 };
172 
173 // TODO nested<> does not exist anymore in Eigen/Core, and it thus has to be removed in favor of ref_selector.
174 template<typename T, int n=1, typename PlainObject = void> struct nested
175 {
176  typedef typename ref_selector<T>::type type;
177 };
178 
179 template <typename Scalar_, int NumIndices_, int Options_, typename IndexType_>
180 struct nested<Tensor<Scalar_, NumIndices_, Options_, IndexType_> >
181 {
183 };
184 
185 template <typename Scalar_, int NumIndices_, int Options_, typename IndexType_>
186 struct nested<const Tensor<Scalar_, NumIndices_, Options_, IndexType_> >
187 {
189 };
190 
191 template <typename Scalar_, typename Dimensions, int Options, typename IndexType_>
192 struct nested<TensorFixedSize<Scalar_, Dimensions, Options, IndexType_> >
193 {
195 };
196 
197 template <typename Scalar_, typename Dimensions, int Options, typename IndexType_>
198 struct nested<const TensorFixedSize<Scalar_, Dimensions, Options, IndexType_> >
199 {
201 };
202 
203 
204 template <typename PlainObjectType>
205 struct nested<TensorRef<PlainObjectType> >
206 {
208 };
209 
210 template <typename PlainObjectType>
211 struct nested<const TensorRef<PlainObjectType> >
212 {
214 };
215 
216 } // end namespace internal
217 
218 // Convolutional layers take in an input tensor of shape (D, R, C, B), or (D, C,
219 // R, B), and convolve it with a set of filters, which can also be presented as
220 // a tensor (D, K, K, M), where M is the number of filters, K is the filter
221 // size, and each 3-dimensional tensor of size (D, K, K) is a filter. For
222 // simplicity we assume that we always use square filters (which is usually the
223 // case in images), hence the two Ks in the tensor dimension. It also takes in
224 // a few additional parameters:
225 // Stride (S): The convolution stride is the offset between locations where we
226 // apply the filters. A larger stride means that the output will be
227 // spatially smaller.
228 // Padding (P): The padding we apply to the input tensor along the R and C
229 // dimensions. This is usually used to make sure that the spatial
230 // dimensions of the output matches our intention.
231 //
232 // Two types of padding are often used:
233 // SAME: The pad value is computed so that the output will have size
234 // R/S and C/S.
235 // VALID: no padding is carried out.
236 // When we do padding, the padded values at the padded locations are usually
237 // zero.
238 //
239 // The output dimensions for convolution, when given all the parameters above,
240 // are as follows:
241 // When Padding = SAME: the output size is (B, R', C', M), where
242 // R' = ceil(float(R) / float(S))
243 // C' = ceil(float(C) / float(S))
244 // where ceil is the ceiling function. The input tensor is padded with 0 as
245 // needed. The number of padded rows and columns are computed as:
246 // Pr = ((R' - 1) * S + K - R) / 2
247 // Pc = ((C' - 1) * S + K - C) / 2
248 // when the stride is 1, we have the simplified case R'=R, C'=C, Pr=Pc=(K-1)/2.
249 // This is where SAME comes from - the output has the same size as the input has.
250 // When Padding = VALID: the output size is computed as
251 // R' = ceil(float(R - K + 1) / float(S))
252 // C' = ceil(float(C - K + 1) / float(S))
253 // and the number of padded rows and columns are computed in the same way as in
254 // the SAME case.
255 // When the stride is 1, we have the simplified case R'=R-K+1, C'=C-K+1, Pr=0,
256 // Pc=0.
257 typedef enum {
260 } PaddingType;
261 
262 } // end namespace Eigen
263 
264 #endif // EIGEN_CXX11_TENSOR_TENSOR_TRAITS_H
Eigen::Tensor
The tensor class.
Definition: Tensor.h:63
Eigen
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
Eigen::internal::traits< Tensor< Scalar_, NumIndices_, Options_, IndexType_ > >::StorageKind
Dense StorageKind
Definition: TensorTraits.h:51
Eigen::PaddingType
PaddingType
Definition: TensorTraits.h:257
Eigen::internal::nested< const TensorFixedSize< Scalar_, Dimensions, Options, IndexType_ > >::type
const typedef TensorFixedSize< Scalar_, Dimensions, Options, IndexType_ > EIGEN_DEVICE_REF type
Definition: TensorTraits.h:200
Eigen::TensorRef
A reference to a tensor expression The expression will be evaluated lazily (as much as possible).
Definition: TensorForwardDeclarations.h:55
Eigen::internal::eval< Tensor< _Scalar, NumIndices_, Options, IndexType_ >, Eigen::Dense >::type
const typedef Tensor< _Scalar, NumIndices_, Options, IndexType_ > EIGEN_DEVICE_REF type
Definition: TensorTraits.h:128
Eigen::internal::traits< Tensor< Scalar_, NumIndices_, Options_, IndexType_ > >::Scalar
Scalar_ Scalar
Definition: TensorTraits.h:50
Eigen::internal::eval< TensorFixedSize< Scalar_, Dimensions, Options, IndexType_ >, Eigen::Dense >::type
const typedef TensorFixedSize< Scalar_, Dimensions, Options, IndexType_ > EIGEN_DEVICE_REF type
Definition: TensorTraits.h:140
Eigen::internal::eval< TensorRef< PlainObjectType >, Eigen::Dense >::type
const typedef TensorRef< PlainObjectType > EIGEN_DEVICE_REF type
Definition: TensorTraits.h:164
Eigen::internal::nested
Definition: TensorTraits.h:174
Eigen::internal::traits< TensorMap< PlainObjectType, Options_, MakePointer_ > >::Index
BaseTraits::Index Index
Definition: TensorTraits.h:92
Eigen::internal::compute_tensor_flags::is_dynamic_size_storage
@ is_dynamic_size_storage
Definition: TensorTraits.h:21
Eigen::internal::packet_traits
Definition: GenericPacketMath.h:106
Eigen::internal::traits< TensorRef< PlainObjectType > >::StorageKind
BaseTraits::StorageKind StorageKind
Definition: TensorTraits.h:113
Eigen::internal::traits< TensorFixedSize< Scalar_, Dimensions, Options_, IndexType_ > >::Index
IndexType_ Index
Definition: TensorTraits.h:71
Eigen::internal::traits< TensorRef< PlainObjectType > >::Index
BaseTraits::Index Index
Definition: TensorTraits.h:114
Eigen::RowMajor
@ RowMajor
Definition: Constants.h:321
Eigen::PADDING_SAME
@ PADDING_SAME
Definition: TensorTraits.h:259
Eigen::internal::nested< Tensor< Scalar_, NumIndices_, Options_, IndexType_ > >::type
const typedef Tensor< Scalar_, NumIndices_, Options_, IndexType_ > EIGEN_DEVICE_REF type
Definition: TensorTraits.h:182
Eigen::DontAlign
@ DontAlign
Definition: Constants.h:325
Eigen::PacketAccessBit
const unsigned int PacketAccessBit
Definition: Constants.h:94
Eigen::internal::traits< TensorFixedSize< Scalar_, Dimensions, Options_, IndexType_ > >::MakePointer::Type
T * Type
Definition: TensorTraits.h:79
Eigen::internal::eval< const TensorFixedSize< Scalar_, Dimensions, Options, IndexType_ >, Eigen::Dense >::type
const typedef TensorFixedSize< Scalar_, Dimensions, Options, IndexType_ > EIGEN_DEVICE_REF type
Definition: TensorTraits.h:146
Eigen::internal::nested< TensorRef< PlainObjectType > >::type
const typedef TensorRef< PlainObjectType > EIGEN_DEVICE_REF type
Definition: TensorTraits.h:207
Eigen::internal::true_type
Definition: Meta.h:96
Eigen::internal::eval< const Tensor< _Scalar, NumIndices_, Options, IndexType_ >, Eigen::Dense >::type
const typedef Tensor< _Scalar, NumIndices_, Options, IndexType_ > EIGEN_DEVICE_REF type
Definition: TensorTraits.h:134
Eigen::internal::compute_tensor_flags::ret
@ ret
Definition: TensorTraits.h:43
Eigen::internal::traits< TensorMap< PlainObjectType, Options_, MakePointer_ > >::BaseTraits
traits< PlainObjectType > BaseTraits
Definition: TensorTraits.h:89
Eigen::internal::traits< Tensor< Scalar_, NumIndices_, Options_, IndexType_ > >::MakePointer::Type
T * Type
Definition: TensorTraits.h:60
Eigen::LvalueBit
const unsigned int LvalueBit
Definition: Constants.h:144
Eigen::internal::traits< TensorRef< PlainObjectType > >::BaseTraits
traits< PlainObjectType > BaseTraits
Definition: TensorTraits.h:111
Eigen::internal::traits< TensorRef< PlainObjectType > >::Scalar
BaseTraits::Scalar Scalar
Definition: TensorTraits.h:112
Eigen::MakePointer
Definition: TensorForwardDeclarations.h:21
Eigen::PADDING_VALID
@ PADDING_VALID
Definition: TensorTraits.h:258
Eigen::Architecture::Type
Type
Definition: Constants.h:471
Eigen::TensorMap
A tensor expression mapping an existing array of data.
Definition: TensorForwardDeclarations.h:52
EIGEN_MAX_ALIGN_BYTES
#define EIGEN_MAX_ALIGN_BYTES
Definition: ConfigureVectorization.h:175
Eigen::Triplet< double >
Eigen::internal::traits< TensorMap< PlainObjectType, Options_, MakePointer_ > >::MakePointer::Type
MakePointerT::Type Type
Definition: TensorTraits.h:102
Eigen::internal::nested< const TensorRef< PlainObjectType > >::type
const typedef TensorRef< PlainObjectType > EIGEN_DEVICE_REF type
Definition: TensorTraits.h:213
Eigen::internal::array_size
Definition: Meta.h:445
Eigen::internal::traits< TensorMap< PlainObjectType, Options_, MakePointer_ > >::MakePointer::MakePointerT
MakePointer_< T > MakePointerT
Definition: TensorTraits.h:101
Eigen::internal::nested< TensorFixedSize< Scalar_, Dimensions, Options, IndexType_ > >::type
const typedef TensorFixedSize< Scalar_, Dimensions, Options, IndexType_ > EIGEN_DEVICE_REF type
Definition: TensorTraits.h:194
Eigen::internal::traits
Definition: ForwardDeclarations.h:17
Eigen::internal::nested::type
ref_selector< T >::type type
Definition: TensorTraits.h:176
Eigen::internal::traits< TensorMap< PlainObjectType, Options_, MakePointer_ > >::Scalar
BaseTraits::Scalar Scalar
Definition: TensorTraits.h:90
Eigen::internal::traits< TensorFixedSize< Scalar_, Dimensions, Options_, IndexType_ > >::StorageKind
Dense StorageKind
Definition: TensorTraits.h:70
Eigen::internal::eval< const TensorMap< PlainObjectType, Options, MakePointer >, Eigen::Dense >::type
const typedef TensorMap< PlainObjectType, Options, MakePointer > EIGEN_DEVICE_REF type
Definition: TensorTraits.h:158
Eigen::internal::compute_tensor_flags::is_aligned
@ is_aligned
Definition: TensorTraits.h:23
Eigen::internal::traits< TensorRef< PlainObjectType > >::PointerType
BaseTraits::PointerType PointerType
Definition: TensorTraits.h:121
EIGEN_DEVICE_REF
#define EIGEN_DEVICE_REF
Definition: TensorMacros.h:50
Eigen::TensorFixedSize
The fixed sized version of the tensor class.
Definition: TensorFixedSize.h:27
internal
Definition: BandTriangularSolver.h:13
Eigen::internal::is_const
Definition: Meta.h:211
Eigen::internal::traits< TensorFixedSize< Scalar_, Dimensions, Options_, IndexType_ > >::Scalar
Scalar_ Scalar
Definition: TensorTraits.h:69
Eigen::ColMajor
@ ColMajor
Definition: Constants.h:319
Eigen::internal::nested< const Tensor< Scalar_, NumIndices_, Options_, IndexType_ > >::type
const typedef Tensor< Scalar_, NumIndices_, Options_, IndexType_ > EIGEN_DEVICE_REF type
Definition: TensorTraits.h:188
Eigen::internal::compute_tensor_flags
Definition: TensorTraits.h:18
Eigen::internal::traits< TensorMap< PlainObjectType, Options_, MakePointer_ > >::PointerType
MakePointer< Scalar >::Type PointerType
Definition: TensorTraits.h:104
Eigen::internal::traits< TensorMap< PlainObjectType, Options_, MakePointer_ > >::StorageKind
BaseTraits::StorageKind StorageKind
Definition: TensorTraits.h:91
Eigen::internal::traits< TensorFixedSize< Scalar_, Dimensions, Options_, IndexType_ > >::PointerType
MakePointer< Scalar >::Type PointerType
Definition: TensorTraits.h:81
Eigen::internal::eval
Definition: XprHelper.h:332
Eigen::internal::eval< const TensorRef< PlainObjectType >, Eigen::Dense >::type
const typedef TensorRef< PlainObjectType > EIGEN_DEVICE_REF type
Definition: TensorTraits.h:170
Eigen::internal::eval< TensorMap< PlainObjectType, Options, MakePointer >, Eigen::Dense >::type
const typedef TensorMap< PlainObjectType, Options, MakePointer > EIGEN_DEVICE_REF type
Definition: TensorTraits.h:152
Eigen::internal::traits< Tensor< Scalar_, NumIndices_, Options_, IndexType_ > >::Index
IndexType_ Index
Definition: TensorTraits.h:52
Eigen::internal::traits< Tensor< Scalar_, NumIndices_, Options_, IndexType_ > >::PointerType
MakePointer< Scalar >::Type PointerType
Definition: TensorTraits.h:62
Eigen::internal::compute_tensor_flags::packet_access_bit
@ packet_access_bit
Definition: TensorTraits.h:39
Scalar
SCALAR Scalar
Definition: bench_gemm.cpp:46
Eigen::Index
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74
Eigen::Dense
Definition: Constants.h:507


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:07:03