TR-mbed 1.0
Loading...
Searching...
No Matches
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
13namespace Eigen {
14
30namespace internal {
31template<typename NullaryOp, typename 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
51template<typename NullaryOp, typename XprType>
52class 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
79namespace internal {
80template<typename UnaryOp, typename 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.
86 typedef typename result_of<UnaryOp(typename XprType::Scalar)>::type Scalar;
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
98template<typename UnaryOp, typename XprType>
103
104template<typename UnaryOp, typename XprType>
109
110} // end namespace internal
111
112
113
114template<typename UnaryOp, typename XprType>
115class 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.
126
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
144namespace internal {
145template<typename BinaryOp, typename LhsXprType, typename 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,
154 typename RhsXprType::Scalar)>::type Scalar;
156 typedef typename promote_storage_type<
159 typedef typename promote_index_type<
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,
171 typename traits<RhsXprType>::PointerType>::type
172 >::type
174 enum {
175 Flags = 0
176 };
177};
178
179template<typename BinaryOp, typename LhsXprType, typename RhsXprType>
184
185template<typename BinaryOp, typename LhsXprType, typename RhsXprType>
190
191} // end namespace internal
192
193
194
195template<typename BinaryOp, typename LhsXprType, typename RhsXprType>
196class 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.
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
230namespace internal {
231template<typename TernaryOp, typename Arg1XprType, typename Arg2XprType, typename Arg3XprType>
232struct 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,
238 typename Arg3XprType::Scalar)>::type 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
261template<typename TernaryOp, typename Arg1XprType, typename Arg2XprType, typename Arg3XprType>
262struct eval<TensorCwiseTernaryOp<TernaryOp, Arg1XprType, Arg2XprType, Arg3XprType>, Eigen::Dense>
263{
265};
266
267template<typename TernaryOp, typename Arg1XprType, typename Arg2XprType, typename Arg3XprType>
268struct 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
277template<typename TernaryOp, typename Arg1XprType, typename Arg2XprType, typename Arg3XprType>
278class TensorCwiseTernaryOp : public TensorBase<TensorCwiseTernaryOp<TernaryOp, Arg1XprType, Arg2XprType, Arg3XprType>, ReadOnlyAccessors>
279{
280 public:
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
315namespace internal {
316template<typename IfXprType, typename ThenXprType, typename 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
336template<typename IfXprType, typename ThenXprType, typename ElseXprType>
341
342template<typename IfXprType, typename ThenXprType, typename ElseXprType>
347
348} // end namespace internal
349
350
351template<typename IfXprType, typename ThenXprType, typename ElseXprType>
352class 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
#define EIGEN_DEVICE_FUNC
Definition Macros.h:976
#define EIGEN_STRONG_INLINE
Definition Macros.h:917
SCALAR Scalar
Definition bench_gemm.cpp:46
Generic expression where a coefficient-wise binary operator is applied to two expressions.
Definition CwiseBinaryOp.h:84
The tensor base class.
Definition TensorBase.h:973
Definition TensorExpr.h:197
Eigen::internal::traits< TensorCwiseBinaryOp >::Index Index
Definition TensorExpr.h:206
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorCwiseBinaryOp(const LhsXprType &lhs, const RhsXprType &rhs, const BinaryOp &func=BinaryOp())
Definition TensorExpr.h:208
RhsXprType::Nested m_rhs_xpr
Definition TensorExpr.h:225
const BinaryOp m_functor
Definition TensorExpr.h:226
EIGEN_DEVICE_FUNC const BinaryOp & functor() const
Definition TensorExpr.h:212
EIGEN_DEVICE_FUNC const internal::remove_all< typenameLhsXprType::Nested >::type & lhsExpression() const
Definition TensorExpr.h:217
Scalar CoeffReturnType
Definition TensorExpr.h:203
EIGEN_DEVICE_FUNC const internal::remove_all< typenameRhsXprType::Nested >::type & rhsExpression() const
Definition TensorExpr.h:221
Eigen::internal::nested< TensorCwiseBinaryOp >::type Nested
Definition TensorExpr.h:204
Eigen::internal::traits< TensorCwiseBinaryOp >::Scalar Scalar
Definition TensorExpr.h:201
Eigen::internal::traits< TensorCwiseBinaryOp >::StorageKind StorageKind
Definition TensorExpr.h:205
LhsXprType::Nested m_lhs_xpr
Definition TensorExpr.h:224
Eigen::NumTraits< Scalar >::Real RealScalar
Definition TensorExpr.h:202
Definition TensorExpr.h:53
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorCwiseNullaryOp(const XprType &xpr, const NullaryOp &func=NullaryOp())
Definition TensorExpr.h:62
TensorCwiseNullaryOp< NullaryOp, XprType > Nested
Definition TensorExpr.h:58
Eigen::internal::traits< TensorCwiseNullaryOp >::Scalar Scalar
Definition TensorExpr.h:55
Eigen::NumTraits< Scalar >::Real RealScalar
Definition TensorExpr.h:56
Eigen::internal::traits< TensorCwiseNullaryOp >::StorageKind StorageKind
Definition TensorExpr.h:59
XprType::CoeffReturnType CoeffReturnType
Definition TensorExpr.h:57
const NullaryOp m_functor
Definition TensorExpr.h:74
Eigen::internal::traits< TensorCwiseNullaryOp >::Index Index
Definition TensorExpr.h:60
XprType::Nested m_xpr
Definition TensorExpr.h:73
EIGEN_DEVICE_FUNC const internal::remove_all< typenameXprType::Nested >::type & nestedExpression() const
Definition TensorExpr.h:67
EIGEN_DEVICE_FUNC const NullaryOp & functor() const
Definition TensorExpr.h:70
Definition TensorExpr.h:279
Eigen::internal::traits< TensorCwiseTernaryOp >::StorageKind StorageKind
Definition TensorExpr.h:285
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorCwiseTernaryOp(const Arg1XprType &arg1, const Arg2XprType &arg2, const Arg3XprType &arg3, const TernaryOp &func=TernaryOp())
Definition TensorExpr.h:288
Arg3XprType::Nested m_arg3_xpr
Definition TensorExpr.h:310
Scalar CoeffReturnType
Definition TensorExpr.h:283
EIGEN_DEVICE_FUNC const internal::remove_all< typenameArg3XprType::Nested >::type & arg3Expression() const
Definition TensorExpr.h:305
Eigen::NumTraits< Scalar >::Real RealScalar
Definition TensorExpr.h:282
EIGEN_DEVICE_FUNC const internal::remove_all< typenameArg1XprType::Nested >::type & arg1Expression() const
Definition TensorExpr.h:297
Arg2XprType::Nested m_arg2_xpr
Definition TensorExpr.h:309
Eigen::internal::traits< TensorCwiseTernaryOp >::Index Index
Definition TensorExpr.h:286
Eigen::internal::traits< TensorCwiseTernaryOp >::Scalar Scalar
Definition TensorExpr.h:281
EIGEN_DEVICE_FUNC const TernaryOp & functor() const
Definition TensorExpr.h:292
EIGEN_DEVICE_FUNC const internal::remove_all< typenameArg2XprType::Nested >::type & arg2Expression() const
Definition TensorExpr.h:301
const TernaryOp m_functor
Definition TensorExpr.h:311
Arg1XprType::Nested m_arg1_xpr
Definition TensorExpr.h:308
Eigen::internal::nested< TensorCwiseTernaryOp >::type Nested
Definition TensorExpr.h:284
Definition TensorExpr.h:116
Eigen::internal::traits< TensorCwiseUnaryOp >::StorageKind StorageKind
Definition TensorExpr.h:124
XprType::Nested m_xpr
Definition TensorExpr.h:139
const UnaryOp m_functor
Definition TensorExpr.h:140
EIGEN_DEVICE_FUNC const UnaryOp & functor() const
Definition TensorExpr.h:131
EIGEN_DEVICE_FUNC const internal::remove_all< typenameXprType::Nested >::type & nestedExpression() const
Definition TensorExpr.h:136
Eigen::internal::traits< TensorCwiseUnaryOp >::Scalar Scalar
Definition TensorExpr.h:120
Scalar CoeffReturnType
Definition TensorExpr.h:122
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorCwiseUnaryOp(const XprType &xpr, const UnaryOp &func=UnaryOp())
Definition TensorExpr.h:127
Eigen::internal::traits< TensorCwiseUnaryOp >::Index Index
Definition TensorExpr.h:125
Eigen::internal::nested< TensorCwiseUnaryOp >::type Nested
Definition TensorExpr.h:123
Eigen::NumTraits< Scalar >::Real RealScalar
Definition TensorExpr.h:121
Definition TensorExpr.h:353
ThenXprType::Nested m_then
Definition TensorExpr.h:381
Eigen::internal::traits< TensorSelectOp >::Index Index
Definition TensorExpr.h:361
EIGEN_DEVICE_FUNC const IfXprType & ifExpression() const
Definition TensorExpr.h:371
Eigen::NumTraits< Scalar >::Real RealScalar
Definition TensorExpr.h:356
Eigen::internal::nested< TensorSelectOp >::type Nested
Definition TensorExpr.h:359
EIGEN_DEVICE_FUNC TensorSelectOp(const IfXprType &a_condition, const ThenXprType &a_then, const ElseXprType &a_else)
Definition TensorExpr.h:364
Eigen::internal::traits< TensorSelectOp >::StorageKind StorageKind
Definition TensorExpr.h:360
Eigen::internal::traits< TensorSelectOp >::Scalar Scalar
Definition TensorExpr.h:355
EIGEN_DEVICE_FUNC const ThenXprType & thenExpression() const
Definition TensorExpr.h:374
EIGEN_DEVICE_FUNC const ElseXprType & elseExpression() const
Definition TensorExpr.h:377
IfXprType::Nested m_condition
Definition TensorExpr.h:380
internal::promote_storage_type< typenameThenXprType::CoeffReturnType, typenameElseXprType::CoeffReturnType >::ret CoeffReturnType
Definition TensorExpr.h:358
ElseXprType::Nested m_else
Definition TensorExpr.h:382
DenseIndex ret
Definition level1_cplx_impl.h:44
Namespace containing all symbols from the Eigen library.
Definition bench_norm.cpp:85
Definition BandTriangularSolver.h:13
Definition Constants.h:507
Definition TensorForwardDeclarations.h:46
const TensorCwiseBinaryOp< BinaryOp, LhsXprType, RhsXprType > & type
Definition TensorExpr.h:182
const TensorCwiseTernaryOp< TernaryOp, Arg1XprType, Arg2XprType, Arg3XprType > & type
Definition TensorExpr.h:264
const TensorCwiseUnaryOp< UnaryOp, XprType > & type
Definition TensorExpr.h:101
const TensorSelectOp< IfXprType, ThenXprType, ElseXprType > & type
Definition TensorExpr.h:339
Definition XprHelper.h:332
Definition TensorTraits.h:175
Definition XprHelper.h:121
Definition XprHelper.h:518
Definition Meta.h:513
remove_reference< LhsNested >::type _LhsNested
Definition TensorExpr.h:164
TypeConversion< Scalar, typenameconditional< Pointer_type_promotion< typenameLhsXprType::Scalar, Scalar >::val, typenametraits< LhsXprType >::PointerType, typenametraits< RhsXprType >::PointerType >::type >::type PointerType
Definition TensorExpr.h:173
promote_storage_type< typenametraits< LhsXprType >::StorageKind, typenametraits< RhsXprType >::StorageKind >::ret StorageKind
Definition TensorExpr.h:158
remove_reference< RhsNested >::type _RhsNested
Definition TensorExpr.h:165
result_of< BinaryOp(typenameLhsXprType::Scalar, typenameRhsXprType::Scalar)>::type Scalar
Definition TensorExpr.h:154
promote_index_type< typenametraits< LhsXprType >::Index, typenametraits< RhsXprType >::Index >::type Index
Definition TensorExpr.h:161
remove_reference< XprTypeNested >::type _XprTypeNested
Definition TensorExpr.h:38
XprTraits::PointerType PointerType
Definition TensorExpr.h:41
TypeConversion< Scalar, typenameconditional< Pointer_type_promotion< typenameArg2XprType::Scalar, Scalar >::val, typenametraits< Arg2XprType >::PointerType, typenametraits< Arg3XprType >::PointerType >::type >::type PointerType
Definition TensorExpr.h:255
remove_reference< Arg1Nested >::type _Arg1Nested
Definition TensorExpr.h:245
result_of< TernaryOp(typenameArg1XprType::Scalar, typenameArg2XprType::Scalar, typenameArg3XprType::Scalar)>::type Scalar
Definition TensorExpr.h:238
remove_reference< Arg2Nested >::type _Arg2Nested
Definition TensorExpr.h:246
remove_reference< Arg3Nested >::type _Arg3Nested
Definition TensorExpr.h:247
XprType::Nested XprTypeNested
Definition TensorExpr.h:88
TypeConversion< Scalar, typenameXprTraits::PointerType >::type PointerType
Definition TensorExpr.h:95
remove_reference< XprTypeNested >::type _XprTypeNested
Definition TensorExpr.h:89
result_of< UnaryOp(typenameXprType::Scalar)>::type Scalar
Definition TensorExpr.h:86
traits< XprType > XprTraits
Definition TensorExpr.h:87
conditional< Pointer_type_promotion< typenameThenXprType::Scalar, Scalar >::val, typenametraits< ThenXprType >::PointerType, typenametraits< ElseXprType >::PointerType >::type PointerType
Definition TensorExpr.h:333
traits< ThenXprType >::Scalar Scalar
Definition TensorExpr.h:320
promote_storage_type< typenametraits< ThenXprType >::StorageKind, typenametraits< ElseXprType >::StorageKind >::ret StorageKind
Definition TensorExpr.h:323
promote_index_type< typenametraits< ElseXprType >::Index, typenametraits< ThenXprType >::Index >::type Index
Definition TensorExpr.h:325
Definition ForwardDeclarations.h:17
Definition benchGeometry.cpp:23