TR-mbed 1.0
Loading...
Searching...
No Matches
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
13namespace Eigen {
14namespace internal {
15
16
17template<typename Scalar, int Options>
19{
20 enum {
21 is_dynamic_size_storage = 1,
22
23 is_aligned =
24 (
25 ((Options&DontAlign)==0) && (
26#if EIGEN_MAX_STATIC_ALIGN_BYTES>0
27 (!is_dynamic_size_storage)
28#else
29 0
30#endif
31 |
33 is_dynamic_size_storage
34#else
35 0
36#endif
37 )
38 ),
39 packet_access_bit = packet_traits<Scalar>::Vectorizable && is_aligned ? PacketAccessBit : 0
40 };
41
42 public:
43 enum { ret = packet_access_bit };
44};
45
46
47template<typename Scalar_, int NumIndices_, int Options_, typename IndexType_>
49{
50 typedef Scalar_ Scalar;
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
66template<typename Scalar_, typename Dimensions, int Options_, typename IndexType_>
68{
69 typedef Scalar_ Scalar;
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
85template<typename PlainObjectType, int Options_, template <class> class MakePointer_>
86struct 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.
102 typedef typename MakePointerT::Type Type;
103 };
105};
106
107template<typename PlainObjectType>
108struct 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
125template<typename _Scalar, int NumIndices_, int Options, typename IndexType_>
130
131template<typename _Scalar, int NumIndices_, int Options, typename IndexType_>
136
137template<typename Scalar_, typename Dimensions, int Options, typename IndexType_>
142
143template<typename Scalar_, typename Dimensions, int Options, typename IndexType_>
148
149template<typename PlainObjectType, int Options, template <class> class MakePointer>
154
155template<typename PlainObjectType, int Options, template <class> class MakePointer>
160
161template<typename PlainObjectType>
162struct eval<TensorRef<PlainObjectType>, Eigen::Dense>
163{
165};
166
167template<typename PlainObjectType>
168struct 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.
174template<typename T, int n=1, typename PlainObject = void> struct nested
175{
176 typedef typename ref_selector<T>::type type;
177};
178
179template <typename Scalar_, int NumIndices_, int Options_, typename IndexType_>
184
185template <typename Scalar_, int NumIndices_, int Options_, typename IndexType_>
190
191template <typename Scalar_, typename Dimensions, int Options, typename IndexType_>
196
197template <typename Scalar_, typename Dimensions, int Options, typename IndexType_>
202
203
204template <typename PlainObjectType>
205struct nested<TensorRef<PlainObjectType> >
206{
208};
209
210template <typename PlainObjectType>
211struct 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.
257typedef enum {
259 PADDING_SAME = 2
261
262} // end namespace Eigen
263
264#endif // EIGEN_CXX11_TENSOR_TENSOR_TRAITS_H
#define EIGEN_MAX_ALIGN_BYTES
Definition ConfigureVectorization.h:175
#define EIGEN_DEVICE_REF
Definition TensorMacros.h:50
The fixed sized version of the tensor class.
Definition TensorFixedSize.h:28
A tensor expression mapping an existing array of data.
Definition TensorMap.h:30
A reference to a tensor expression The expression will be evaluated lazily (as much as possible).
Definition TensorRef.h:125
The tensor class.
Definition Tensor.h:64
Definition TensorTraits.h:19
@ ret
Definition TensorTraits.h:43
@ ColMajor
Definition Constants.h:319
@ DontAlign
Definition Constants.h:325
@ RowMajor
Definition Constants.h:321
const unsigned int PacketAccessBit
Definition Constants.h:94
const unsigned int LvalueBit
Definition Constants.h:144
Namespace containing all symbols from the Eigen library.
Definition bench_norm.cpp:85
PaddingType
Definition TensorTraits.h:257
@ PADDING_VALID
Definition TensorTraits.h:258
@ PADDING_SAME
Definition TensorTraits.h:259
Definition BandTriangularSolver.h:13
Definition Constants.h:507
Definition TensorForwardDeclarations.h:21
Definition Meta.h:445
const TensorFixedSize< Scalar_, Dimensions, Options, IndexType_ > EIGEN_DEVICE_REF type
Definition TensorTraits.h:140
const TensorMap< PlainObjectType, Options, MakePointer > EIGEN_DEVICE_REF type
Definition TensorTraits.h:152
const TensorRef< PlainObjectType > EIGEN_DEVICE_REF type
Definition TensorTraits.h:164
const Tensor< _Scalar, NumIndices_, Options, IndexType_ > EIGEN_DEVICE_REF type
Definition TensorTraits.h:128
const TensorFixedSize< Scalar_, Dimensions, Options, IndexType_ > EIGEN_DEVICE_REF type
Definition TensorTraits.h:146
const TensorMap< PlainObjectType, Options, MakePointer > EIGEN_DEVICE_REF type
Definition TensorTraits.h:158
const TensorRef< PlainObjectType > EIGEN_DEVICE_REF type
Definition TensorTraits.h:170
const Tensor< _Scalar, NumIndices_, Options, IndexType_ > EIGEN_DEVICE_REF type
Definition TensorTraits.h:134
Definition XprHelper.h:332
Definition Meta.h:211
const TensorFixedSize< Scalar_, Dimensions, Options, IndexType_ > EIGEN_DEVICE_REF type
Definition TensorTraits.h:194
const TensorRef< PlainObjectType > EIGEN_DEVICE_REF type
Definition TensorTraits.h:207
const Tensor< Scalar_, NumIndices_, Options_, IndexType_ > EIGEN_DEVICE_REF type
Definition TensorTraits.h:182
const TensorFixedSize< Scalar_, Dimensions, Options, IndexType_ > EIGEN_DEVICE_REF type
Definition TensorTraits.h:200
const TensorRef< PlainObjectType > EIGEN_DEVICE_REF type
Definition TensorTraits.h:213
const Tensor< Scalar_, NumIndices_, Options_, IndexType_ > EIGEN_DEVICE_REF type
Definition TensorTraits.h:188
Definition TensorTraits.h:175
ref_selector< T >::type type
Definition TensorTraits.h:176
Definition GenericPacketMath.h:107
MakePointer< Scalar >::Type PointerType
Definition TensorTraits.h:81
traits< PlainObjectType > BaseTraits
Definition TensorTraits.h:89
BaseTraits::StorageKind StorageKind
Definition TensorTraits.h:91
MakePointer< Scalar >::Type PointerType
Definition TensorTraits.h:104
BaseTraits::StorageKind StorageKind
Definition TensorTraits.h:113
traits< PlainObjectType > BaseTraits
Definition TensorTraits.h:111
BaseTraits::Index Index
Definition TensorTraits.h:114
BaseTraits::PointerType PointerType
Definition TensorTraits.h:121
BaseTraits::Scalar Scalar
Definition TensorTraits.h:112
MakePointer< Scalar >::Type PointerType
Definition TensorTraits.h:62
Definition ForwardDeclarations.h:17