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  typedef typename XprTraits::PointerType PointerType;
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 
67  nestedExpression() const { return m_xpr; }
68 
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  typedef typename TypeConversion<Scalar,
93  typename XprTraits::PointerType
94  >::type
96 };
97 
98 template<typename UnaryOp, typename XprType>
100 {
102 };
103 
104 template<typename UnaryOp, typename XprType>
105 struct nested<TensorCwiseUnaryOp<UnaryOp, XprType>, 1, typename eval<TensorCwiseUnaryOp<UnaryOp, XprType> >::type>
106 {
108 };
109 
110 } // end namespace internal
111 
112 
113 
114 template<typename UnaryOp, typename XprType>
115 class TensorCwiseUnaryOp : public TensorBase<TensorCwiseUnaryOp<UnaryOp, XprType>, ReadOnlyAccessors>
116 {
117  public:
118  // TODO(phli): Add InputScalar, InputPacket. Check references to
119  // current Scalar/Packet to see if the intent is Input or Output.
122  typedef Scalar CoeffReturnType;
126 
127  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorCwiseUnaryOp(const XprType& xpr, const UnaryOp& func = UnaryOp())
128  : m_xpr(xpr), m_functor(func) {}
129 
131  const UnaryOp& functor() const { return m_functor; }
132 
136  nestedExpression() const { return m_xpr; }
137 
138  protected:
139  typename XprType::Nested m_xpr;
140  const UnaryOp m_functor;
141 };
142 
143 
144 namespace internal {
145 template<typename BinaryOp, typename LhsXprType, typename RhsXprType>
146 struct traits<TensorCwiseBinaryOp<BinaryOp, LhsXprType, RhsXprType> >
147 {
148  // Type promotion to handle the case where the types of the lhs and the rhs
149  // are different.
150  // TODO(phli): Add Lhs/RhsScalar, Lhs/RhsPacket. Check references to
151  // current Scalar/Packet to see if the intent is Inputs or Output.
152  typedef typename result_of<
153  BinaryOp(typename LhsXprType::Scalar,
156  typedef typename promote_storage_type<
159  typedef typename promote_index_type<
160  typename traits<LhsXprType>::Index,
162  typedef typename LhsXprType::Nested LhsNested;
163  typedef typename RhsXprType::Nested RhsNested;
166  static const int NumDimensions = XprTraits::NumDimensions;
167  static const int Layout = XprTraits::Layout;
168  typedef typename TypeConversion<Scalar,
172  >::type
174  enum {
175  Flags = 0
176  };
177 };
178 
179 template<typename BinaryOp, typename LhsXprType, typename RhsXprType>
180 struct eval<TensorCwiseBinaryOp<BinaryOp, LhsXprType, RhsXprType>, Eigen::Dense>
181 {
183 };
184 
185 template<typename BinaryOp, typename LhsXprType, typename RhsXprType>
186 struct nested<TensorCwiseBinaryOp<BinaryOp, LhsXprType, RhsXprType>, 1, typename eval<TensorCwiseBinaryOp<BinaryOp, LhsXprType, RhsXprType> >::type>
187 {
189 };
190 
191 } // end namespace internal
192 
193 
194 
195 template<typename BinaryOp, typename LhsXprType, typename RhsXprType>
196 class TensorCwiseBinaryOp : public TensorBase<TensorCwiseBinaryOp<BinaryOp, LhsXprType, RhsXprType>, ReadOnlyAccessors>
197 {
198  public:
199  // TODO(phli): Add Lhs/RhsScalar, Lhs/RhsPacket. Check references to
200  // current Scalar/Packet to see if the intent is Inputs or Output.
203  typedef Scalar CoeffReturnType;
207 
208  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorCwiseBinaryOp(const LhsXprType& lhs, const RhsXprType& rhs, const BinaryOp& func = BinaryOp())
209  : m_lhs_xpr(lhs), m_rhs_xpr(rhs), m_functor(func) {}
210 
212  const BinaryOp& functor() const { return m_functor; }
213 
217  lhsExpression() const { return m_lhs_xpr; }
218 
221  rhsExpression() const { return m_rhs_xpr; }
222 
223  protected:
224  typename LhsXprType::Nested m_lhs_xpr;
225  typename RhsXprType::Nested m_rhs_xpr;
226  const BinaryOp m_functor;
227 };
228 
229 
230 namespace internal {
231 template<typename TernaryOp, typename Arg1XprType, typename Arg2XprType, typename Arg3XprType>
232 struct traits<TensorCwiseTernaryOp<TernaryOp, Arg1XprType, Arg2XprType, Arg3XprType> >
233 {
234  // Type promotion to handle the case where the types of the args are different.
235  typedef typename result_of<
236  TernaryOp(typename Arg1XprType::Scalar,
237  typename Arg2XprType::Scalar,
242  typedef typename Arg1XprType::Nested Arg1Nested;
243  typedef typename Arg2XprType::Nested Arg2Nested;
244  typedef typename Arg3XprType::Nested Arg3Nested;
248  static const int NumDimensions = XprTraits::NumDimensions;
249  static const int Layout = XprTraits::Layout;
250  typedef typename TypeConversion<Scalar,
254  >::type
256  enum {
257  Flags = 0
258  };
259 };
260 
261 template<typename TernaryOp, typename Arg1XprType, typename Arg2XprType, typename Arg3XprType>
262 struct eval<TensorCwiseTernaryOp<TernaryOp, Arg1XprType, Arg2XprType, Arg3XprType>, Eigen::Dense>
263 {
265 };
266 
267 template<typename TernaryOp, typename Arg1XprType, typename Arg2XprType, typename Arg3XprType>
268 struct nested<TensorCwiseTernaryOp<TernaryOp, Arg1XprType, Arg2XprType, Arg3XprType>, 1, typename eval<TensorCwiseTernaryOp<TernaryOp, Arg1XprType, Arg2XprType, Arg3XprType> >::type>
269 {
271 };
272 
273 } // end namespace internal
274 
275 
276 
277 template<typename TernaryOp, typename Arg1XprType, typename Arg2XprType, typename Arg3XprType>
278 class TensorCwiseTernaryOp : public TensorBase<TensorCwiseTernaryOp<TernaryOp, Arg1XprType, Arg2XprType, Arg3XprType>, ReadOnlyAccessors>
279 {
280  public:
283  typedef Scalar CoeffReturnType;
287 
288  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorCwiseTernaryOp(const Arg1XprType& arg1, const Arg2XprType& arg2, const Arg3XprType& arg3, const TernaryOp& func = TernaryOp())
289  : m_arg1_xpr(arg1), m_arg2_xpr(arg2), m_arg3_xpr(arg3), m_functor(func) {}
290 
292  const TernaryOp& functor() const { return m_functor; }
293 
297  arg1Expression() const { return m_arg1_xpr; }
298 
301  arg2Expression() const { return m_arg2_xpr; }
302 
305  arg3Expression() const { return m_arg3_xpr; }
306 
307  protected:
308  typename Arg1XprType::Nested m_arg1_xpr;
309  typename Arg2XprType::Nested m_arg2_xpr;
310  typename Arg3XprType::Nested m_arg3_xpr;
311  const TernaryOp m_functor;
312 };
313 
314 
315 namespace internal {
316 template<typename IfXprType, typename ThenXprType, typename ElseXprType>
317 struct traits<TensorSelectOp<IfXprType, ThenXprType, ElseXprType> >
318  : traits<ThenXprType>
319 {
326  typedef typename IfXprType::Nested IfNested;
327  typedef typename ThenXprType::Nested ThenNested;
328  typedef typename ElseXprType::Nested ElseNested;
329  static const int NumDimensions = XprTraits::NumDimensions;
330  static const int Layout = XprTraits::Layout;
334 };
335 
336 template<typename IfXprType, typename ThenXprType, typename ElseXprType>
337 struct eval<TensorSelectOp<IfXprType, ThenXprType, ElseXprType>, Eigen::Dense>
338 {
340 };
341 
342 template<typename IfXprType, typename ThenXprType, typename ElseXprType>
343 struct nested<TensorSelectOp<IfXprType, ThenXprType, ElseXprType>, 1, typename eval<TensorSelectOp<IfXprType, ThenXprType, ElseXprType> >::type>
344 {
346 };
347 
348 } // end namespace internal
349 
350 
351 template<typename IfXprType, typename ThenXprType, typename ElseXprType>
352 class TensorSelectOp : public TensorBase<TensorSelectOp<IfXprType, ThenXprType, ElseXprType>, ReadOnlyAccessors>
353 {
354  public:
357  typedef typename internal::promote_storage_type<typename ThenXprType::CoeffReturnType,
358  typename ElseXprType::CoeffReturnType>::ret CoeffReturnType;
362 
364  TensorSelectOp(const IfXprType& a_condition,
365  const ThenXprType& a_then,
366  const ElseXprType& a_else)
367  : m_condition(a_condition), m_then(a_then), m_else(a_else)
368  { }
369 
371  const IfXprType& ifExpression() const { return m_condition; }
372 
374  const ThenXprType& thenExpression() const { return m_then; }
375 
377  const ElseXprType& elseExpression() const { return m_else; }
378 
379  protected:
380  typename IfXprType::Nested m_condition;
381  typename ThenXprType::Nested m_then;
382  typename ElseXprType::Nested m_else;
383 };
384 
385 
386 } // end namespace Eigen
387 
388 #endif // EIGEN_CXX11_TENSOR_TENSOR_EXPR_H
const TernaryOp m_functor
Definition: TensorExpr.h:311
SCALAR Scalar
Definition: bench_gemm.cpp:46
IfXprType::Nested m_condition
Definition: TensorExpr.h:380
Eigen::internal::traits< TensorSelectOp >::StorageKind StorageKind
Definition: TensorExpr.h:360
Eigen::internal::traits< TensorCwiseUnaryOp >::StorageKind StorageKind
Definition: TensorExpr.h:124
#define EIGEN_STRONG_INLINE
Definition: Macros.h:917
EIGEN_DEVICE_FUNC const IfXprType & ifExpression() const
Definition: TensorExpr.h:371
LhsXprType::Nested m_lhs_xpr
Definition: TensorExpr.h:224
const BinaryOp m_functor
Definition: TensorExpr.h:226
Eigen::internal::traits< TensorCwiseNullaryOp >::Index Index
Definition: TensorExpr.h:60
result_of< BinaryOp(typename LhsXprType::Scalar, typename RhsXprType::Scalar)>::type Scalar
Definition: TensorExpr.h:154
Eigen::internal::traits< TensorCwiseBinaryOp >::StorageKind StorageKind
Definition: TensorExpr.h:205
const TensorCwiseTernaryOp< TernaryOp, Arg1XprType, Arg2XprType, Arg3XprType > & type
Definition: TensorExpr.h:264
Eigen::internal::nested< TensorCwiseBinaryOp >::type Nested
Definition: TensorExpr.h:204
Eigen::NumTraits< Scalar >::Real RealScalar
Definition: TensorExpr.h:202
EIGEN_DEVICE_FUNC const internal::remove_all< typename LhsXprType::Nested >::type & lhsExpression() const
Definition: TensorExpr.h:217
EIGEN_DEVICE_FUNC const BinaryOp & functor() const
Definition: TensorExpr.h:212
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:208
const TensorCwiseBinaryOp< BinaryOp, LhsXprType, RhsXprType > & type
Definition: TensorExpr.h:182
EIGEN_DEVICE_FUNC TensorSelectOp(const IfXprType &a_condition, const ThenXprType &a_then, const ElseXprType &a_else)
Definition: TensorExpr.h:364
TensorCwiseNullaryOp< NullaryOp, XprType > Nested
Definition: TensorExpr.h:58
Eigen::internal::traits< TensorCwiseTernaryOp >::Index Index
Definition: TensorExpr.h:286
Eigen::internal::nested< TensorSelectOp >::type Nested
Definition: TensorExpr.h:359
result_of< TernaryOp(typename Arg1XprType::Scalar, typename Arg2XprType::Scalar, typename Arg3XprType::Scalar)>::type Scalar
Definition: TensorExpr.h:238
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
EIGEN_DEVICE_FUNC const ThenXprType & thenExpression() const
Definition: TensorExpr.h:374
XprType::CoeffReturnType CoeffReturnType
Definition: TensorExpr.h:57
EIGEN_DEVICE_FUNC const internal::remove_all< typename Arg1XprType::Nested >::type & arg1Expression() const
Definition: TensorExpr.h:297
Eigen::internal::traits< TensorCwiseBinaryOp >::Index Index
Definition: TensorExpr.h:206
EIGEN_DEVICE_FUNC const ElseXprType & elseExpression() const
Definition: TensorExpr.h:377
EIGEN_DEVICE_FUNC const TernaryOp & functor() const
Definition: TensorExpr.h:292
TypeConversion< Scalar, typename XprTraits::PointerType >::type PointerType
Definition: TensorExpr.h:95
Eigen::internal::traits< TensorCwiseUnaryOp >::Scalar Scalar
Definition: TensorExpr.h:120
EIGEN_DEVICE_FUNC const internal::remove_all< typename XprType::Nested >::type & nestedExpression() const
Definition: TensorExpr.h:67
conditional< Pointer_type_promotion< typename ThenXprType::Scalar, Scalar >::val, typename traits< ThenXprType >::PointerType, typename traits< ElseXprType >::PointerType >::type PointerType
Definition: TensorExpr.h:333
XprType::Nested m_xpr
Definition: TensorExpr.h:73
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorCwiseTernaryOp(const Arg1XprType &arg1, const Arg2XprType &arg2, const Arg3XprType &arg3, const TernaryOp &func=TernaryOp())
Definition: TensorExpr.h:288
const UnaryOp m_functor
Definition: TensorExpr.h:140
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorCwiseUnaryOp(const XprType &xpr, const UnaryOp &func=UnaryOp())
Definition: TensorExpr.h:127
Eigen::NumTraits< Scalar >::Real RealScalar
Definition: TensorExpr.h:356
Generic expression where a coefficient-wise binary operator is applied to two expressions.
Definition: CwiseBinaryOp.h:77
RhsXprType::Nested m_rhs_xpr
Definition: TensorExpr.h:225
Eigen::internal::traits< TensorCwiseNullaryOp >::Scalar Scalar
Definition: TensorExpr.h:55
XprType::Nested m_xpr
Definition: TensorExpr.h:139
ThenXprType::Nested m_then
Definition: TensorExpr.h:381
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:281
Eigen::internal::traits< TensorSelectOp >::Scalar Scalar
Definition: TensorExpr.h:355
EIGEN_DEVICE_FUNC const internal::remove_all< typename RhsXprType::Nested >::type & rhsExpression() const
Definition: TensorExpr.h:221
Eigen::NumTraits< Scalar >::Real RealScalar
Definition: TensorExpr.h:121
const TensorSelectOp< IfXprType, ThenXprType, ElseXprType > & type
Definition: TensorExpr.h:339
Eigen::internal::nested< TensorCwiseUnaryOp >::type Nested
Definition: TensorExpr.h:123
EIGEN_DEVICE_FUNC const UnaryOp & functor() const
Definition: TensorExpr.h:131
Eigen::internal::nested< TensorCwiseTernaryOp >::type Nested
Definition: TensorExpr.h:284
Eigen::internal::traits< TensorCwiseTernaryOp >::StorageKind StorageKind
Definition: TensorExpr.h:285
promote_index_type< typename traits< LhsXprType >::Index, typename traits< RhsXprType >::Index >::type Index
Definition: TensorExpr.h:161
EIGEN_DEVICE_FUNC const internal::remove_all< typename Arg2XprType::Nested >::type & arg2Expression() const
Definition: TensorExpr.h:301
Eigen::NumTraits< Scalar >::Real RealScalar
Definition: TensorExpr.h:282
Eigen::NumTraits< Scalar >::Real RealScalar
Definition: TensorExpr.h:56
DenseIndex ret
Eigen::internal::traits< TensorSelectOp >::Index Index
Definition: TensorExpr.h:361
The tensor base class.
Definition: TensorBase.h:973
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:976
TypeConversion< Scalar, typename conditional< Pointer_type_promotion< typename LhsXprType::Scalar, Scalar >::val, typename traits< LhsXprType >::PointerType, typename traits< RhsXprType >::PointerType >::type >::type PointerType
Definition: TensorExpr.h:173
Eigen::internal::traits< TensorCwiseBinaryOp >::Scalar Scalar
Definition: TensorExpr.h:201
TypeConversion< Scalar, typename conditional< Pointer_type_promotion< typename Arg2XprType::Scalar, Scalar >::val, typename traits< Arg2XprType >::PointerType, typename traits< Arg3XprType >::PointerType >::type >::type PointerType
Definition: TensorExpr.h:255
Eigen::internal::traits< TensorCwiseUnaryOp >::Index Index
Definition: TensorExpr.h:125
internal::promote_storage_type< typename ThenXprType::CoeffReturnType, typename ElseXprType::CoeffReturnType >::ret CoeffReturnType
Definition: TensorExpr.h:358
Arg2XprType::Nested m_arg2_xpr
Definition: TensorExpr.h:309
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:323
Arg3XprType::Nested m_arg3_xpr
Definition: TensorExpr.h:310
ElseXprType::Nested m_else
Definition: TensorExpr.h:382
EIGEN_DEVICE_FUNC const NullaryOp & functor() const
Definition: TensorExpr.h:70
EIGEN_DEVICE_FUNC const internal::remove_all< typename Arg3XprType::Nested >::type & arg3Expression() const
Definition: TensorExpr.h:305
promote_storage_type< typename traits< LhsXprType >::StorageKind, typename traits< RhsXprType >::StorageKind >::ret StorageKind
Definition: TensorExpr.h:158
promote_index_type< typename traits< ElseXprType >::Index, typename traits< ThenXprType >::Index >::type Index
Definition: TensorExpr.h:325
Generic expression where a coefficient-wise unary operator is applied to an expression.
Definition: CwiseUnaryOp.h:55
result_of< UnaryOp(typename XprType::Scalar)>::type Scalar
Definition: TensorExpr.h:86
Arg1XprType::Nested m_arg1_xpr
Definition: TensorExpr.h:308
Definition: pytypes.h:1370
const NullaryOp m_functor
Definition: TensorExpr.h:74
EIGEN_DEVICE_FUNC const internal::remove_all< typename XprType::Nested >::type & nestedExpression() const
Definition: TensorExpr.h:136


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:36:55