TensorExpr.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_EXPR_H
11 #define EIGEN_CXX11_TENSOR_TENSOR_EXPR_H
12 
13 namespace Eigen {
14 
30 namespace internal {
31 template<typename NullaryOp, typename XprType>
32 struct traits<TensorCwiseNullaryOp<NullaryOp, XprType> >
33  : traits<XprType>
34 {
36  typedef typename XprType::Scalar Scalar;
37  typedef typename XprType::Nested XprTypeNested;
39  static const int NumDimensions = XprTraits::NumDimensions;
40  static const int Layout = XprTraits::Layout;
41 
42  enum {
43  Flags = 0
44  };
45 };
46 
47 } // end namespace internal
48 
49 
50 
51 template<typename NullaryOp, typename XprType>
52 class TensorCwiseNullaryOp : public TensorBase<TensorCwiseNullaryOp<NullaryOp, XprType>, ReadOnlyAccessors>
53 {
54  public:
57  typedef typename XprType::CoeffReturnType CoeffReturnType;
61 
62  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorCwiseNullaryOp(const XprType& xpr, const NullaryOp& func = NullaryOp())
63  : m_xpr(xpr), m_functor(func) {}
64 
65  EIGEN_DEVICE_FUNC
67  nestedExpression() const { return m_xpr; }
68 
69  EIGEN_DEVICE_FUNC
70  const NullaryOp& functor() const { return m_functor; }
71 
72  protected:
73  typename XprType::Nested m_xpr;
74  const NullaryOp m_functor;
75 };
76 
77 
78 
79 namespace internal {
80 template<typename UnaryOp, typename XprType>
81 struct traits<TensorCwiseUnaryOp<UnaryOp, XprType> >
82  : traits<XprType>
83 {
84  // TODO(phli): Add InputScalar, InputPacket. Check references to
85  // current Scalar/Packet to see if the intent is Input or Output.
88  typedef typename XprType::Nested XprTypeNested;
90  static const int NumDimensions = XprTraits::NumDimensions;
91  static const int Layout = XprTraits::Layout;
92 };
93 
94 template<typename UnaryOp, typename XprType>
95 struct eval<TensorCwiseUnaryOp<UnaryOp, XprType>, Eigen::Dense>
96 {
98 };
99 
100 template<typename UnaryOp, typename XprType>
101 struct nested<TensorCwiseUnaryOp<UnaryOp, XprType>, 1, typename eval<TensorCwiseUnaryOp<UnaryOp, XprType> >::type>
102 {
104 };
105 
106 } // end namespace internal
107 
108 
109 
110 template<typename UnaryOp, typename XprType>
111 class TensorCwiseUnaryOp : public TensorBase<TensorCwiseUnaryOp<UnaryOp, XprType>, ReadOnlyAccessors>
112 {
113  public:
114  // TODO(phli): Add InputScalar, InputPacket. Check references to
115  // current Scalar/Packet to see if the intent is Input or Output.
118  typedef Scalar CoeffReturnType;
122 
123  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorCwiseUnaryOp(const XprType& xpr, const UnaryOp& func = UnaryOp())
124  : m_xpr(xpr), m_functor(func) {}
125 
126  EIGEN_DEVICE_FUNC
127  const UnaryOp& functor() const { return m_functor; }
128 
130  EIGEN_DEVICE_FUNC
132  nestedExpression() const { return m_xpr; }
133 
134  protected:
135  typename XprType::Nested m_xpr;
136  const UnaryOp m_functor;
137 };
138 
139 
140 namespace internal {
141 template<typename BinaryOp, typename LhsXprType, typename RhsXprType>
142 struct traits<TensorCwiseBinaryOp<BinaryOp, LhsXprType, RhsXprType> >
143 {
144  // Type promotion to handle the case where the types of the lhs and the rhs
145  // are different.
146  // TODO(phli): Add Lhs/RhsScalar, Lhs/RhsPacket. Check references to
147  // current Scalar/Packet to see if the intent is Inputs or Output.
148  typedef typename result_of<
149  BinaryOp(typename LhsXprType::Scalar,
150  typename RhsXprType::Scalar)>::type Scalar;
152  typedef typename promote_storage_type<
155  typedef typename promote_index_type<
156  typename traits<LhsXprType>::Index,
158  typedef typename LhsXprType::Nested LhsNested;
159  typedef typename RhsXprType::Nested RhsNested;
162  static const int NumDimensions = XprTraits::NumDimensions;
163  static const int Layout = XprTraits::Layout;
164 
165  enum {
166  Flags = 0
167  };
168 };
169 
170 template<typename BinaryOp, typename LhsXprType, typename RhsXprType>
171 struct eval<TensorCwiseBinaryOp<BinaryOp, LhsXprType, RhsXprType>, Eigen::Dense>
172 {
174 };
175 
176 template<typename BinaryOp, typename LhsXprType, typename RhsXprType>
177 struct nested<TensorCwiseBinaryOp<BinaryOp, LhsXprType, RhsXprType>, 1, typename eval<TensorCwiseBinaryOp<BinaryOp, LhsXprType, RhsXprType> >::type>
178 {
180 };
181 
182 } // end namespace internal
183 
184 
185 
186 template<typename BinaryOp, typename LhsXprType, typename RhsXprType>
187 class TensorCwiseBinaryOp : public TensorBase<TensorCwiseBinaryOp<BinaryOp, LhsXprType, RhsXprType>, ReadOnlyAccessors>
188 {
189  public:
190  // TODO(phli): Add Lhs/RhsScalar, Lhs/RhsPacket. Check references to
191  // current Scalar/Packet to see if the intent is Inputs or Output.
194  typedef Scalar CoeffReturnType;
198 
199  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorCwiseBinaryOp(const LhsXprType& lhs, const RhsXprType& rhs, const BinaryOp& func = BinaryOp())
200  : m_lhs_xpr(lhs), m_rhs_xpr(rhs), m_functor(func) {}
201 
202  EIGEN_DEVICE_FUNC
203  const BinaryOp& functor() const { return m_functor; }
204 
206  EIGEN_DEVICE_FUNC
208  lhsExpression() const { return m_lhs_xpr; }
209 
210  EIGEN_DEVICE_FUNC
212  rhsExpression() const { return m_rhs_xpr; }
213 
214  protected:
215  typename LhsXprType::Nested m_lhs_xpr;
216  typename RhsXprType::Nested m_rhs_xpr;
217  const BinaryOp m_functor;
218 };
219 
220 
221 namespace internal {
222 template<typename TernaryOp, typename Arg1XprType, typename Arg2XprType, typename Arg3XprType>
223 struct traits<TensorCwiseTernaryOp<TernaryOp, Arg1XprType, Arg2XprType, Arg3XprType> >
224 {
225  // Type promotion to handle the case where the types of the args are different.
226  typedef typename result_of<
227  TernaryOp(typename Arg1XprType::Scalar,
228  typename Arg2XprType::Scalar,
229  typename Arg3XprType::Scalar)>::type Scalar;
233  typedef typename Arg1XprType::Nested Arg1Nested;
234  typedef typename Arg2XprType::Nested Arg2Nested;
235  typedef typename Arg3XprType::Nested Arg3Nested;
239  static const int NumDimensions = XprTraits::NumDimensions;
240  static const int Layout = XprTraits::Layout;
241 
242  enum {
243  Flags = 0
244  };
245 };
246 
247 template<typename TernaryOp, typename Arg1XprType, typename Arg2XprType, typename Arg3XprType>
248 struct eval<TensorCwiseTernaryOp<TernaryOp, Arg1XprType, Arg2XprType, Arg3XprType>, Eigen::Dense>
249 {
251 };
252 
253 template<typename TernaryOp, typename Arg1XprType, typename Arg2XprType, typename Arg3XprType>
254 struct nested<TensorCwiseTernaryOp<TernaryOp, Arg1XprType, Arg2XprType, Arg3XprType>, 1, typename eval<TensorCwiseTernaryOp<TernaryOp, Arg1XprType, Arg2XprType, Arg3XprType> >::type>
255 {
257 };
258 
259 } // end namespace internal
260 
261 
262 
263 template<typename TernaryOp, typename Arg1XprType, typename Arg2XprType, typename Arg3XprType>
264 class TensorCwiseTernaryOp : public TensorBase<TensorCwiseTernaryOp<TernaryOp, Arg1XprType, Arg2XprType, Arg3XprType>, ReadOnlyAccessors>
265 {
266  public:
269  typedef Scalar CoeffReturnType;
273 
274  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorCwiseTernaryOp(const Arg1XprType& arg1, const Arg2XprType& arg2, const Arg3XprType& arg3, const TernaryOp& func = TernaryOp())
275  : m_arg1_xpr(arg1), m_arg2_xpr(arg2), m_arg3_xpr(arg3), m_functor(func) {}
276 
277  EIGEN_DEVICE_FUNC
278  const TernaryOp& functor() const { return m_functor; }
279 
281  EIGEN_DEVICE_FUNC
283  arg1Expression() const { return m_arg1_xpr; }
284 
285  EIGEN_DEVICE_FUNC
287  arg2Expression() const { return m_arg2_xpr; }
288 
289  EIGEN_DEVICE_FUNC
291  arg3Expression() const { return m_arg3_xpr; }
292 
293  protected:
294  typename Arg1XprType::Nested m_arg1_xpr;
295  typename Arg2XprType::Nested m_arg2_xpr;
296  typename Arg3XprType::Nested m_arg3_xpr;
297  const TernaryOp m_functor;
298 };
299 
300 
301 namespace internal {
302 template<typename IfXprType, typename ThenXprType, typename ElseXprType>
303 struct traits<TensorSelectOp<IfXprType, ThenXprType, ElseXprType> >
304  : traits<ThenXprType>
305 {
312  typedef typename IfXprType::Nested IfNested;
313  typedef typename ThenXprType::Nested ThenNested;
314  typedef typename ElseXprType::Nested ElseNested;
315  static const int NumDimensions = XprTraits::NumDimensions;
316  static const int Layout = XprTraits::Layout;
317 };
318 
319 template<typename IfXprType, typename ThenXprType, typename ElseXprType>
320 struct eval<TensorSelectOp<IfXprType, ThenXprType, ElseXprType>, Eigen::Dense>
321 {
323 };
324 
325 template<typename IfXprType, typename ThenXprType, typename ElseXprType>
326 struct nested<TensorSelectOp<IfXprType, ThenXprType, ElseXprType>, 1, typename eval<TensorSelectOp<IfXprType, ThenXprType, ElseXprType> >::type>
327 {
329 };
330 
331 } // end namespace internal
332 
333 
334 template<typename IfXprType, typename ThenXprType, typename ElseXprType>
335 class TensorSelectOp : public TensorBase<TensorSelectOp<IfXprType, ThenXprType, ElseXprType>, ReadOnlyAccessors>
336 {
337  public:
340  typedef typename internal::promote_storage_type<typename ThenXprType::CoeffReturnType,
341  typename ElseXprType::CoeffReturnType>::ret CoeffReturnType;
345 
346  EIGEN_DEVICE_FUNC
347  TensorSelectOp(const IfXprType& a_condition,
348  const ThenXprType& a_then,
349  const ElseXprType& a_else)
350  : m_condition(a_condition), m_then(a_then), m_else(a_else)
351  { }
352 
353  EIGEN_DEVICE_FUNC
354  const IfXprType& ifExpression() const { return m_condition; }
355 
356  EIGEN_DEVICE_FUNC
357  const ThenXprType& thenExpression() const { return m_then; }
358 
359  EIGEN_DEVICE_FUNC
360  const ElseXprType& elseExpression() const { return m_else; }
361 
362  protected:
363  typename IfXprType::Nested m_condition;
364  typename ThenXprType::Nested m_then;
365  typename ElseXprType::Nested m_else;
366 };
367 
368 
369 } // end namespace Eigen
370 
371 #endif // EIGEN_CXX11_TENSOR_TENSOR_EXPR_H
const TernaryOp m_functor
Definition: TensorExpr.h:297
IfXprType::Nested m_condition
Definition: TensorExpr.h:363
Eigen::internal::traits< TensorSelectOp >::StorageKind StorageKind
Definition: TensorExpr.h:343
Eigen::internal::traits< TensorCwiseUnaryOp >::StorageKind StorageKind
Definition: TensorExpr.h:120
#define EIGEN_STRONG_INLINE
Definition: Macros.h:493
LhsXprType::Nested m_lhs_xpr
Definition: TensorExpr.h:215
const BinaryOp m_functor
Definition: TensorExpr.h:217
Eigen::internal::traits< TensorCwiseNullaryOp >::Index Index
Definition: TensorExpr.h:60
result_of< BinaryOp(typename LhsXprType::Scalar, typename RhsXprType::Scalar)>::type Scalar
Definition: TensorExpr.h:150
EIGEN_DEVICE_FUNC const BinaryOp & functor() const
Definition: TensorExpr.h:203
Eigen::internal::traits< TensorCwiseBinaryOp >::StorageKind StorageKind
Definition: TensorExpr.h:196
const TensorCwiseTernaryOp< TernaryOp, Arg1XprType, Arg2XprType, Arg3XprType > & type
Definition: TensorExpr.h:250
Eigen::internal::nested< TensorCwiseBinaryOp >::type Nested
Definition: TensorExpr.h:195
Eigen::NumTraits< Scalar >::Real RealScalar
Definition: TensorExpr.h:193
EIGEN_DEVICE_FUNC const internal::remove_all< typename LhsXprType::Nested >::type & lhsExpression() const
Definition: TensorExpr.h:208
remove_reference< XprTypeNested >::type _XprTypeNested
Definition: TensorExpr.h:89
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorCwiseBinaryOp(const LhsXprType &lhs, const RhsXprType &rhs, const BinaryOp &func=BinaryOp())
Definition: TensorExpr.h:199
const TensorCwiseBinaryOp< BinaryOp, LhsXprType, RhsXprType > & type
Definition: TensorExpr.h:173
EIGEN_DEVICE_FUNC TensorSelectOp(const IfXprType &a_condition, const ThenXprType &a_then, const ElseXprType &a_else)
Definition: TensorExpr.h:347
TensorCwiseNullaryOp< NullaryOp, XprType > Nested
Definition: TensorExpr.h:58
Eigen::internal::traits< TensorCwiseTernaryOp >::Index Index
Definition: TensorExpr.h:272
Eigen::internal::nested< TensorSelectOp >::type Nested
Definition: TensorExpr.h:342
result_of< TernaryOp(typename Arg1XprType::Scalar, typename Arg2XprType::Scalar, typename Arg3XprType::Scalar)>::type Scalar
Definition: TensorExpr.h:229
Definition: LDLT.h:16
XprType::CoeffReturnType CoeffReturnType
Definition: TensorExpr.h:57
Eigen::internal::traits< TensorCwiseBinaryOp >::Index Index
Definition: TensorExpr.h:197
Eigen::internal::traits< TensorCwiseUnaryOp >::Scalar Scalar
Definition: TensorExpr.h:116
XprType::Nested m_xpr
Definition: TensorExpr.h:73
EIGEN_DEVICE_FUNC const IfXprType & ifExpression() const
Definition: TensorExpr.h:354
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorCwiseTernaryOp(const Arg1XprType &arg1, const Arg2XprType &arg2, const Arg3XprType &arg3, const TernaryOp &func=TernaryOp())
Definition: TensorExpr.h:274
EIGEN_DEVICE_FUNC const internal::remove_all< typename XprType::Nested >::type & nestedExpression() const
Definition: TensorExpr.h:132
const UnaryOp m_functor
Definition: TensorExpr.h:136
EIGEN_DEVICE_FUNC const TernaryOp & functor() const
Definition: TensorExpr.h:278
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorCwiseUnaryOp(const XprType &xpr, const UnaryOp &func=UnaryOp())
Definition: TensorExpr.h:123
Eigen::NumTraits< Scalar >::Real RealScalar
Definition: TensorExpr.h:339
EIGEN_DEVICE_FUNC const internal::remove_all< typename Arg2XprType::Nested >::type & arg2Expression() const
Definition: TensorExpr.h:287
EIGEN_DEVICE_FUNC const internal::remove_all< typename Arg3XprType::Nested >::type & arg3Expression() const
Definition: TensorExpr.h:291
RhsXprType::Nested m_rhs_xpr
Definition: TensorExpr.h:216
Eigen::internal::traits< TensorCwiseNullaryOp >::Scalar Scalar
Definition: TensorExpr.h:55
XprType::Nested m_xpr
Definition: TensorExpr.h:135
ThenXprType::Nested m_then
Definition: TensorExpr.h:364
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorCwiseNullaryOp(const XprType &xpr, const NullaryOp &func=NullaryOp())
Definition: TensorExpr.h:62
Eigen::internal::traits< TensorCwiseTernaryOp >::Scalar Scalar
Definition: TensorExpr.h:267
EIGEN_DEVICE_FUNC const ThenXprType & thenExpression() const
Definition: TensorExpr.h:357
EIGEN_DEVICE_FUNC const internal::remove_all< typename XprType::Nested >::type & nestedExpression() const
Definition: TensorExpr.h:67
Eigen::internal::traits< TensorSelectOp >::Scalar Scalar
Definition: TensorExpr.h:338
Eigen::NumTraits< Scalar >::Real RealScalar
Definition: TensorExpr.h:117
const TensorSelectOp< IfXprType, ThenXprType, ElseXprType > & type
Definition: TensorExpr.h:322
Eigen::internal::nested< TensorCwiseUnaryOp >::type Nested
Definition: TensorExpr.h:119
Eigen::internal::nested< TensorCwiseTernaryOp >::type Nested
Definition: TensorExpr.h:270
Eigen::internal::traits< TensorCwiseTernaryOp >::StorageKind StorageKind
Definition: TensorExpr.h:271
promote_index_type< typename traits< LhsXprType >::Index, typename traits< RhsXprType >::Index >::type Index
Definition: TensorExpr.h:157
EIGEN_DEVICE_FUNC const NullaryOp & functor() const
Definition: TensorExpr.h:70
Eigen::NumTraits< Scalar >::Real RealScalar
Definition: TensorExpr.h:268
Eigen::NumTraits< Scalar >::Real RealScalar
Definition: TensorExpr.h:56
EIGEN_DEVICE_FUNC const internal::remove_all< typename Arg1XprType::Nested >::type & arg1Expression() const
Definition: TensorExpr.h:283
Eigen::internal::traits< TensorSelectOp >::Index Index
Definition: TensorExpr.h:344
The tensor base class.
Definition: TensorBase.h:827
Eigen::internal::traits< TensorCwiseBinaryOp >::Scalar Scalar
Definition: TensorExpr.h:192
Eigen::internal::traits< TensorCwiseUnaryOp >::Index Index
Definition: TensorExpr.h:121
internal::promote_storage_type< typename ThenXprType::CoeffReturnType, typename ElseXprType::CoeffReturnType >::ret CoeffReturnType
Definition: TensorExpr.h:341
Arg2XprType::Nested m_arg2_xpr
Definition: TensorExpr.h:295
Eigen::internal::traits< TensorCwiseNullaryOp >::StorageKind StorageKind
Definition: TensorExpr.h:59
promote_storage_type< typename traits< ThenXprType >::StorageKind, typename traits< ElseXprType >::StorageKind >::ret StorageKind
Definition: TensorExpr.h:309
Arg3XprType::Nested m_arg3_xpr
Definition: TensorExpr.h:296
ElseXprType::Nested m_else
Definition: TensorExpr.h:365
promote_storage_type< typename traits< LhsXprType >::StorageKind, typename traits< RhsXprType >::StorageKind >::ret StorageKind
Definition: TensorExpr.h:154
promote_index_type< typename traits< ElseXprType >::Index, typename traits< ThenXprType >::Index >::type Index
Definition: TensorExpr.h:311
EIGEN_DEVICE_FUNC const ElseXprType & elseExpression() const
Definition: TensorExpr.h:360
result_of< UnaryOp(typename XprType::Scalar)>::type Scalar
Definition: TensorExpr.h:86
EIGEN_DEVICE_FUNC const internal::remove_all< typename RhsXprType::Nested >::type & rhsExpression() const
Definition: TensorExpr.h:212
EIGEN_DEVICE_FUNC const UnaryOp & functor() const
Definition: TensorExpr.h:127
Arg1XprType::Nested m_arg1_xpr
Definition: TensorExpr.h:294
const NullaryOp m_functor
Definition: TensorExpr.h:74


hebiros
Author(s): Xavier Artache , Matthew Tesch
autogenerated on Thu Sep 3 2020 04:09:19