TensorLayoutSwap.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_LAYOUT_SWAP_H
11 #define EIGEN_CXX11_TENSOR_TENSOR_LAYOUT_SWAP_H
12 
13 // IWYU pragma: private
14 #include "./InternalHeaderCheck.h"
15 
16 namespace Eigen {
17 
40 namespace internal {
41 template <typename XprType>
42 struct traits<TensorLayoutSwapOp<XprType> > : public traits<XprType> {
43  typedef typename XprType::Scalar Scalar;
45  typedef typename XprTraits::StorageKind StorageKind;
46  typedef typename XprTraits::Index Index;
47  typedef typename XprType::Nested Nested;
48  typedef std::remove_reference_t<Nested> Nested_;
49  static constexpr int NumDimensions = traits<XprType>::NumDimensions;
50  static constexpr int Layout = (traits<XprType>::Layout == ColMajor) ? RowMajor : ColMajor;
51  typedef typename XprTraits::PointerType PointerType;
52 };
53 
54 template <typename XprType>
57 };
58 
59 template <typename XprType>
62 };
63 
64 } // end namespace internal
65 
66 template <typename XprType>
67 class TensorLayoutSwapOp : public TensorBase<TensorLayoutSwapOp<XprType>, WriteAccessors> {
68  public:
72  typedef std::remove_const_t<typename XprType::CoeffReturnType> CoeffReturnType;
76 
78 
80 
82  protected:
83  typename XprType::Nested m_xpr;
84 };
85 
86 // Eval as rvalue
87 template <typename ArgType, typename Device>
88 struct TensorEvaluator<const TensorLayoutSwapOp<ArgType>, Device> {
90  typedef typename XprType::Index Index;
93 
94  static constexpr int Layout =
96  enum {
99  BlockAccess = false,
101  CoordAccess = false, // to be implemented
103  };
104 
105  //===- Tensor block evaluation strategy (see TensorBlock.h) -------------===//
107  //===--------------------------------------------------------------------===//
108 
109  EIGEN_STRONG_INLINE TensorEvaluator(const XprType& op, const Device& device) : m_impl(op.expression(), device) {
110  for (int i = 0; i < NumDims; ++i) {
111  m_dimensions[i] = m_impl.dimensions()[NumDims - 1 - i];
112  }
113  }
114 
115  typedef typename XprType::Scalar Scalar;
120 
121  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions& dimensions() const { return m_dimensions; }
122 
123  EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(EvaluatorPointerType data) { return m_impl.evalSubExprsIfNeeded(data); }
124  EIGEN_STRONG_INLINE void cleanup() { m_impl.cleanup(); }
125 
126  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const { return m_impl.coeff(index); }
127 
128  template <int LoadMode>
130  return m_impl.template packet<LoadMode>(index);
131  }
132 
134  return m_impl.costPerCoeff(vectorized);
135  }
136 
137  EIGEN_DEVICE_FUNC typename Storage::Type data() const { return constCast(m_impl.data()); }
138 
139  const TensorEvaluator<ArgType, Device>& impl() const { return m_impl; }
140 
141  protected:
144 };
145 
146 // Eval as lvalue
147 template <typename ArgType, typename Device>
148 struct TensorEvaluator<TensorLayoutSwapOp<ArgType>, Device>
149  : public TensorEvaluator<const TensorLayoutSwapOp<ArgType>, Device> {
152 
153  static constexpr int Layout =
155  enum {
158  BlockAccess = false,
160  CoordAccess = false // to be implemented
161  };
162 
163  //===- Tensor block evaluation strategy (see TensorBlock.h) -------------===//
165  //===--------------------------------------------------------------------===//
166 
167  EIGEN_STRONG_INLINE TensorEvaluator(const XprType& op, const Device& device) : Base(op, device) {}
168 
169  typedef typename XprType::Index Index;
170  typedef typename XprType::Scalar Scalar;
173 
175  return this->m_impl.coeffRef(index);
176  }
177  template <int StoreMode>
179  this->m_impl.template writePacket<StoreMode>(index, x);
180  }
181 };
182 
183 } // end namespace Eigen
184 
185 #endif // EIGEN_CXX11_TENSOR_TENSOR_LAYOUT_SWAP_H
int i
Definition: BiCGSTAB_step_by_step.cpp:9
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:892
#define EIGEN_STRONG_INLINE
Definition: Macros.h:834
#define EIGEN_TENSOR_INHERIT_ASSIGNMENT_OPERATORS(Derived)
Macro to manually inherit assignment operators. This is necessary, because the implicitly defined ass...
Definition: TensorMacros.h:81
SCALAR Scalar
Definition: bench_gemm.cpp:45
Generic expression where a coefficient-wise binary operator is applied to two expressions.
Definition: CwiseBinaryOp.h:79
The tensor base class.
Definition: TensorBase.h:1026
Definition: TensorLayoutSwap.h:67
EIGEN_DEVICE_FUNC const internal::remove_all_t< typename XprType::Nested > & expression() const
Definition: TensorLayoutSwap.h:79
Eigen::internal::traits< TensorLayoutSwapOp >::Scalar Scalar
Definition: TensorLayoutSwap.h:70
XprType::Nested m_xpr
Definition: TensorLayoutSwap.h:83
std::remove_const_t< typename XprType::CoeffReturnType > CoeffReturnType
Definition: TensorLayoutSwap.h:72
Eigen::internal::traits< TensorLayoutSwapOp >::StorageKind StorageKind
Definition: TensorLayoutSwap.h:74
TensorBase< TensorLayoutSwapOp< XprType >, WriteAccessors > Base
Definition: TensorLayoutSwap.h:69
Eigen::internal::nested< TensorLayoutSwapOp >::type Nested
Definition: TensorLayoutSwap.h:73
Eigen::NumTraits< Scalar >::Real RealScalar
Definition: TensorLayoutSwap.h:71
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorLayoutSwapOp(const XprType &expr)
Definition: TensorLayoutSwap.h:77
Eigen::internal::traits< TensorLayoutSwapOp >::Index Index
Definition: TensorLayoutSwap.h:75
Definition: TensorCostModel.h:28
Definition: TensorBlock.h:566
@ WriteAccessors
Definition: Constants.h:374
@ ColMajor
Definition: Constants.h:318
@ RowMajor
Definition: Constants.h:320
char char * op
Definition: level2_impl.h:374
typename remove_all< T >::type remove_all_t
Definition: Meta.h:142
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:70
squared absolute value
Definition: GlobalFunctions.h:87
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:83
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T * constCast(const T *data)
Definition: TensorForwardDeclarations.h:31
Definition: Eigen_Colamd.h:49
list x
Definition: plotDoE.py:28
Definition: Constants.h:519
T Real
Definition: NumTraits.h:183
Definition: TensorForwardDeclarations.h:42
internal::TensorBlockNotImplemented TensorBlock
Definition: TensorLayoutSwap.h:164
EIGEN_STRONG_INLINE TensorEvaluator(const XprType &op, const Device &device)
Definition: TensorLayoutSwap.h:167
PacketType< CoeffReturnType, Device >::type PacketReturnType
Definition: TensorLayoutSwap.h:172
XprType::Scalar Scalar
Definition: TensorLayoutSwap.h:170
XprType::Index Index
Definition: TensorLayoutSwap.h:169
TensorLayoutSwapOp< ArgType > XprType
Definition: TensorLayoutSwap.h:151
TensorEvaluator< const TensorLayoutSwapOp< ArgType >, Device > Base
Definition: TensorLayoutSwap.h:150
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void writePacket(Index index, const PacketReturnType &x) const
Definition: TensorLayoutSwap.h:178
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType & coeffRef(Index index) const
Definition: TensorLayoutSwap.h:174
XprType::CoeffReturnType CoeffReturnType
Definition: TensorLayoutSwap.h:171
Dimensions m_dimensions
Definition: TensorLayoutSwap.h:143
DSizes< Index, NumDims > Dimensions
Definition: TensorLayoutSwap.h:92
EIGEN_STRONG_INLINE void cleanup()
Definition: TensorLayoutSwap.h:124
EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(EvaluatorPointerType data)
Definition: TensorLayoutSwap.h:123
EIGEN_STRONG_INLINE TensorEvaluator(const XprType &op, const Device &device)
Definition: TensorLayoutSwap.h:109
TensorEvaluator< ArgType, Device > m_impl
Definition: TensorLayoutSwap.h:142
XprType::Index Index
Definition: TensorLayoutSwap.h:90
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const
Definition: TensorLayoutSwap.h:129
internal::TensorBlockNotImplemented TensorBlock
Definition: TensorLayoutSwap.h:106
Storage::Type EvaluatorPointerType
Definition: TensorLayoutSwap.h:119
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost costPerCoeff(bool vectorized) const
Definition: TensorLayoutSwap.h:133
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions & dimensions() const
Definition: TensorLayoutSwap.h:121
XprType::CoeffReturnType CoeffReturnType
Definition: TensorLayoutSwap.h:116
TensorLayoutSwapOp< ArgType > XprType
Definition: TensorLayoutSwap.h:89
PacketType< CoeffReturnType, Device >::type PacketReturnType
Definition: TensorLayoutSwap.h:117
XprType::Scalar Scalar
Definition: TensorLayoutSwap.h:115
EIGEN_DEVICE_FUNC Storage::Type data() const
Definition: TensorLayoutSwap.h:137
const TensorEvaluator< ArgType, Device > & impl() const
Definition: TensorLayoutSwap.h:139
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const
Definition: TensorLayoutSwap.h:126
StorageMemory< CoeffReturnType, Device > Storage
Definition: TensorLayoutSwap.h:118
A cost model used to limit the number of threads used for evaluating tensor expression.
Definition: TensorEvaluator.h:31
static constexpr int Layout
Definition: TensorEvaluator.h:46
@ PacketAccess
Definition: TensorEvaluator.h:50
@ IsAligned
Definition: TensorEvaluator.h:49
EIGEN_DEVICE_FUNC EvaluatorPointerType data() const
Definition: TensorEvaluator.h:165
Definition: Meta.h:305
const TensorLayoutSwapOp< XprType > & type
Definition: TensorLayoutSwap.h:56
Definition: XprHelper.h:427
Definition: TensorTraits.h:152
ref_selector< T >::type type
Definition: TensorTraits.h:153
XprTraits::StorageKind StorageKind
Definition: TensorLayoutSwap.h:45
std::remove_reference_t< Nested > Nested_
Definition: TensorLayoutSwap.h:48
XprTraits::PointerType PointerType
Definition: TensorLayoutSwap.h:51
XprTraits::Index Index
Definition: TensorLayoutSwap.h:46
XprType::Scalar Scalar
Definition: TensorLayoutSwap.h:43
traits< XprType > XprTraits
Definition: TensorLayoutSwap.h:44
XprType::Nested Nested
Definition: TensorLayoutSwap.h:47
Definition: ForwardDeclarations.h:21