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 namespace Eigen {
14 
37 namespace internal {
38 template<typename XprType>
39 struct traits<TensorLayoutSwapOp<XprType> > : public traits<XprType>
40 {
41  typedef typename XprType::Scalar Scalar;
43  typedef typename XprTraits::StorageKind StorageKind;
44  typedef typename XprTraits::Index Index;
45  typedef typename XprType::Nested Nested;
47  static const int NumDimensions = traits<XprType>::NumDimensions;
48  static const int Layout = (traits<XprType>::Layout == ColMajor) ? RowMajor : ColMajor;
49  typedef typename XprTraits::PointerType PointerType;
50 };
51 
52 template<typename XprType>
54 {
56 };
57 
58 template<typename XprType>
60 {
62 };
63 
64 } // end namespace internal
65 
66 
67 
68 template<typename XprType>
69 class TensorLayoutSwapOp : public TensorBase<TensorLayoutSwapOp<XprType>, WriteAccessors>
70 {
71  public:
79 
81  : m_xpr(expr) {}
82 
85  expression() const { return m_xpr; }
86 
88  protected:
89  typename XprType::Nested m_xpr;
90 };
91 
92 
93 // Eval as rvalue
94 template<typename ArgType, typename Device>
95 struct TensorEvaluator<const TensorLayoutSwapOp<ArgType>, Device>
96 {
98  typedef typename XprType::Index Index;
101 
102  enum {
105  BlockAccess = false,
107  Layout = (static_cast<int>(TensorEvaluator<ArgType, Device>::Layout) == static_cast<int>(ColMajor)) ? RowMajor : ColMajor,
108  CoordAccess = false, // to be implemented
110  };
111 
112  //===- Tensor block evaluation strategy (see TensorBlock.h) -------------===//
114  //===--------------------------------------------------------------------===//
115 
116  EIGEN_STRONG_INLINE TensorEvaluator(const XprType& op, const Device& device)
117  : m_impl(op.expression(), device)
118  {
119  for(int i = 0; i < NumDims; ++i) {
120  m_dimensions[i] = m_impl.dimensions()[NumDims-1-i];
121  }
122  }
123 
124 #ifdef EIGEN_USE_SYCL
125  // binding placeholder accessors to a command group handler for SYCL
126  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void bind(cl::sycl::handler &cgh) const {
127  m_impl.bind(cgh);
128  }
129 #endif
130 
131  typedef typename XprType::Scalar Scalar;
136 
137  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions& dimensions() const { return m_dimensions; }
138 
140  return m_impl.evalSubExprsIfNeeded(data);
141  }
143  m_impl.cleanup();
144  }
145 
147  {
148  return m_impl.coeff(index);
149  }
150 
151  template<int LoadMode>
153  {
154  return m_impl.template packet<LoadMode>(index);
155  }
156 
158  return m_impl.costPerCoeff(vectorized);
159  }
160 
162  return constCast(m_impl.data());
163  }
164 
165  const TensorEvaluator<ArgType, Device>& impl() const { return m_impl; }
166 
167  protected:
170 };
171 
172 
173 // Eval as lvalue
174 template<typename ArgType, typename Device>
175  struct TensorEvaluator<TensorLayoutSwapOp<ArgType>, Device>
176  : public TensorEvaluator<const TensorLayoutSwapOp<ArgType>, Device>
177 {
180 
181  enum {
184  BlockAccess = false,
186  Layout = (static_cast<int>(TensorEvaluator<ArgType, Device>::Layout) == static_cast<int>(ColMajor)) ? RowMajor : ColMajor,
187  CoordAccess = false // to be implemented
188  };
189 
190  //===- Tensor block evaluation strategy (see TensorBlock.h) -------------===//
192  //===--------------------------------------------------------------------===//
193 
194  EIGEN_STRONG_INLINE TensorEvaluator(const XprType& op, const Device& device)
195  : Base(op, device)
196  { }
197 
198  typedef typename XprType::Index Index;
199  typedef typename XprType::Scalar Scalar;
202 
204  {
205  return this->m_impl.coeffRef(index);
206  }
207  template <int StoreMode> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
208  void writePacket(Index index, const PacketReturnType& x)
209  {
210  this->m_impl.template writePacket<StoreMode>(index, x);
211  }
212 };
213 
214 } // end namespace Eigen
215 
216 #endif // EIGEN_CXX11_TENSOR_TENSOR_LAYOUT_SWAP_H
Eigen::TensorEvaluator< const TensorLayoutSwapOp< ArgType >, Device >::XprType
TensorLayoutSwapOp< ArgType > XprType
Definition: TensorLayoutSwap.h:97
Eigen::internal::traits< TensorLayoutSwapOp< XprType > >::Nested
XprType::Nested Nested
Definition: TensorLayoutSwap.h:45
Eigen::TensorEvaluator< TensorLayoutSwapOp< ArgType >, Device >::Base
TensorEvaluator< const TensorLayoutSwapOp< ArgType >, Device > Base
Definition: TensorLayoutSwap.h:178
EIGEN_DEVICE_FUNC
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:976
Eigen::TensorEvaluator< const TensorLayoutSwapOp< ArgType >, Device >::EvaluatorPointerType
Storage::Type EvaluatorPointerType
Definition: TensorLayoutSwap.h:135
Eigen
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
Eigen::TensorEvaluator< const TensorLayoutSwapOp< ArgType >, Device >::packet
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const
Definition: TensorLayoutSwap.h:152
Eigen::TensorLayoutSwapOp::TensorLayoutSwapOp
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorLayoutSwapOp(const XprType &expr)
Definition: TensorLayoutSwap.h:80
Eigen::internal::traits< TensorLayoutSwapOp< XprType > >::Scalar
XprType::Scalar Scalar
Definition: TensorLayoutSwap.h:41
Eigen::internal::TensorBlockNotImplemented
Definition: TensorBlock.h:617
Eigen::CwiseBinaryOp
Generic expression where a coefficient-wise binary operator is applied to two expressions.
Definition: CwiseBinaryOp.h:77
Eigen::TensorLayoutSwapOp::RealScalar
Eigen::NumTraits< Scalar >::Real RealScalar
Definition: TensorLayoutSwap.h:74
Eigen::TensorEvaluator< const TensorLayoutSwapOp< ArgType >, Device >::coeff
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const
Definition: TensorLayoutSwap.h:146
Eigen::TensorEvaluator< const TensorLayoutSwapOp< ArgType >, Device >::impl
const TensorEvaluator< ArgType, Device > & impl() const
Definition: TensorLayoutSwap.h:165
Eigen::internal::nested< TensorLayoutSwapOp< XprType >, 1, typename eval< TensorLayoutSwapOp< XprType > >::type >::type
TensorLayoutSwapOp< XprType > type
Definition: TensorLayoutSwap.h:61
Eigen::TensorEvaluator< const TensorLayoutSwapOp< ArgType >, Device >::m_impl
TensorEvaluator< ArgType, Device > m_impl
Definition: TensorLayoutSwap.h:168
Eigen::internal::nested
Definition: TensorTraits.h:174
Eigen::TensorEvaluator< TensorLayoutSwapOp< ArgType >, Device >::PacketReturnType
PacketType< CoeffReturnType, Device >::type PacketReturnType
Definition: TensorLayoutSwap.h:201
x
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
Definition: gnuplot_common_settings.hh:12
Eigen::TensorEvaluator< const TensorLayoutSwapOp< ArgType >, Device >::Scalar
XprType::Scalar Scalar
Definition: TensorLayoutSwap.h:131
Eigen::TensorEvaluator< const TensorLayoutSwapOp< ArgType >, Device >::m_dimensions
Dimensions m_dimensions
Definition: TensorLayoutSwap.h:169
Eigen::TensorEvaluator::Layout
@ Layout
Definition: TensorEvaluator.h:50
Eigen::RowMajor
@ RowMajor
Definition: Constants.h:321
Eigen::TensorEvaluator< const TensorLayoutSwapOp< ArgType >, Device >::PacketReturnType
PacketType< CoeffReturnType, Device >::type PacketReturnType
Definition: TensorLayoutSwap.h:133
Eigen::DSizes< Index, NumDims >
Eigen::TensorEvaluator< const TensorLayoutSwapOp< ArgType >, Device >
Definition: TensorLayoutSwap.h:95
Eigen::TensorEvaluator< const TensorLayoutSwapOp< ArgType >, Device >::evalSubExprsIfNeeded
EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(EvaluatorPointerType data)
Definition: TensorLayoutSwap.h:139
Eigen::TensorLayoutSwapOp::StorageKind
Eigen::internal::traits< TensorLayoutSwapOp >::StorageKind StorageKind
Definition: TensorLayoutSwap.h:77
Eigen::internal::true_type
Definition: Meta.h:96
Eigen::TensorEvaluator< TensorLayoutSwapOp< ArgType >, Device >::writePacket
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void writePacket(Index index, const PacketReturnType &x)
Definition: TensorLayoutSwap.h:208
Eigen::internal::traits< TensorLayoutSwapOp< XprType > >::_Nested
remove_reference< Nested >::type _Nested
Definition: TensorLayoutSwap.h:46
Eigen::internal::traits< TensorLayoutSwapOp< XprType > >::XprTraits
traits< XprType > XprTraits
Definition: TensorLayoutSwap.h:42
Eigen::TensorEvaluator::data
EIGEN_DEVICE_FUNC EvaluatorPointerType data() const
Definition: TensorEvaluator.h:181
Eigen::TensorEvaluator< const TensorLayoutSwapOp< ArgType >, Device >::TensorEvaluator
EIGEN_STRONG_INLINE TensorEvaluator(const XprType &op, const Device &device)
Definition: TensorLayoutSwap.h:116
Eigen::TensorEvaluator< const TensorLayoutSwapOp< ArgType >, Device >::Storage
StorageMemory< CoeffReturnType, Device > Storage
Definition: TensorLayoutSwap.h:134
EIGEN_STRONG_INLINE
#define EIGEN_STRONG_INLINE
Definition: Macros.h:917
Eigen::TensorEvaluator::PreferBlockAccess
@ PreferBlockAccess
Definition: TensorEvaluator.h:49
Eigen::internal::traits< TensorLayoutSwapOp< XprType > >::StorageKind
XprTraits::StorageKind StorageKind
Definition: TensorLayoutSwap.h:43
Eigen::TensorLayoutSwapOp::m_xpr
XprType::Nested m_xpr
Definition: TensorLayoutSwap.h:89
Eigen::Triplet< double >
Eigen::TensorEvaluator< const TensorLayoutSwapOp< ArgType >, Device >::data
EIGEN_DEVICE_FUNC Storage::Type data() const
Definition: TensorLayoutSwap.h:161
Eigen::TensorEvaluator< const TensorLayoutSwapOp< ArgType >, Device >::dimensions
EIGEN_DEVICE_FUNC const EIGEN_STRONG_INLINE Dimensions & dimensions() const
Definition: TensorLayoutSwap.h:137
Eigen::StorageMemory
Definition: TensorForwardDeclarations.h:37
Eigen::TensorBase
The tensor base class.
Definition: TensorBase.h:973
Eigen::TensorEvaluator< TensorLayoutSwapOp< ArgType >, Device >::XprType
TensorLayoutSwapOp< ArgType > XprType
Definition: TensorLayoutSwap.h:179
Eigen::TensorEvaluator< TensorLayoutSwapOp< ArgType >, Device >::CoeffReturnType
XprType::CoeffReturnType CoeffReturnType
Definition: TensorLayoutSwap.h:200
Eigen::internal::array_size
Definition: Meta.h:445
Eigen::TensorLayoutSwapOp::Nested
Eigen::internal::nested< TensorLayoutSwapOp >::type Nested
Definition: TensorLayoutSwap.h:76
Eigen::internal::traits< TensorLayoutSwapOp< XprType > >::Index
XprTraits::Index Index
Definition: TensorLayoutSwap.h:44
Eigen::TensorEvaluator::BlockAccess
@ BlockAccess
Definition: TensorEvaluator.h:48
EIGEN_TENSOR_INHERIT_ASSIGNMENT_OPERATORS
#define EIGEN_TENSOR_INHERIT_ASSIGNMENT_OPERATORS(Derived)
Definition: TensorMacros.h:94
Eigen::TensorEvaluator< const TensorLayoutSwapOp< ArgType >, Device >::cleanup
EIGEN_STRONG_INLINE void cleanup()
Definition: TensorLayoutSwap.h:142
Eigen::internal::traits
Definition: ForwardDeclarations.h:17
Eigen::TensorEvaluator< const TensorLayoutSwapOp< ArgType >, Device >::costPerCoeff
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost costPerCoeff(bool vectorized) const
Definition: TensorLayoutSwap.h:157
Eigen::TensorLayoutSwapOp
Definition: TensorForwardDeclarations.h:77
Eigen::TensorEvaluator< TensorLayoutSwapOp< ArgType >, Device >::coeffRef
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType & coeffRef(Index index)
Definition: TensorLayoutSwap.h:203
Eigen::TensorLayoutSwapOp::expression
const EIGEN_DEVICE_FUNC internal::remove_all< typename XprType::Nested >::type & expression() const
Definition: TensorLayoutSwap.h:85
Eigen::TensorEvaluator< TensorLayoutSwapOp< ArgType >, Device >::TensorBlock
internal::TensorBlockNotImplemented TensorBlock
Definition: TensorLayoutSwap.h:191
Eigen::TensorLayoutSwapOp::CoeffReturnType
internal::remove_const< typename XprType::CoeffReturnType >::type CoeffReturnType
Definition: TensorLayoutSwap.h:75
Eigen::TensorEvaluator< const TensorLayoutSwapOp< ArgType >, Device >::Index
XprType::Index Index
Definition: TensorLayoutSwap.h:98
Eigen::TensorEvaluator< const TensorLayoutSwapOp< ArgType >, Device >::CoeffReturnType
XprType::CoeffReturnType CoeffReturnType
Definition: TensorLayoutSwap.h:132
Eigen::TensorEvaluator
A cost model used to limit the number of threads used for evaluating tensor expression.
Definition: TensorEvaluator.h:28
Eigen::TensorEvaluator< TensorLayoutSwapOp< ArgType >, Device >::TensorEvaluator
EIGEN_STRONG_INLINE TensorEvaluator(const XprType &op, const Device &device)
Definition: TensorLayoutSwap.h:194
Eigen::internal::traits< TensorLayoutSwapOp< XprType > >::PointerType
XprTraits::PointerType PointerType
Definition: TensorLayoutSwap.h:49
internal
Definition: BandTriangularSolver.h:13
Eigen::internal::eval< TensorLayoutSwapOp< XprType >, Eigen::Dense >::type
const typedef TensorLayoutSwapOp< XprType > & type
Definition: TensorLayoutSwap.h:55
Eigen::ColMajor
@ ColMajor
Definition: Constants.h:319
Eigen::TensorEvaluator::IsAligned
@ IsAligned
Definition: TensorEvaluator.h:46
Eigen::WriteAccessors
@ WriteAccessors
Definition: Constants.h:378
Eigen::TensorLayoutSwapOp::Scalar
Eigen::internal::traits< TensorLayoutSwapOp >::Scalar Scalar
Definition: TensorLayoutSwap.h:73
Eigen::internal::eval
Definition: XprHelper.h:332
Eigen::TensorEvaluator::PacketAccess
@ PacketAccess
Definition: TensorEvaluator.h:47
Eigen::TensorOpCost
Definition: TensorCostModel.h:25
Eigen::TensorEvaluator< TensorLayoutSwapOp< ArgType >, Device >::Scalar
XprType::Scalar Scalar
Definition: TensorLayoutSwap.h:199
Eigen::constCast
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T * constCast(const T *data)
Definition: TensorForwardDeclarations.h:27
test_callbacks.value
value
Definition: test_callbacks.py:160
Eigen::TensorEvaluator< TensorLayoutSwapOp< ArgType >, Device >::Index
XprType::Index Index
Definition: TensorLayoutSwap.h:198
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9
Eigen::TensorLayoutSwapOp::Index
Eigen::internal::traits< TensorLayoutSwapOp >::Index Index
Definition: TensorLayoutSwap.h:78
Eigen::TensorEvaluator< const TensorLayoutSwapOp< ArgType >, Device >::TensorBlock
internal::TensorBlockNotImplemented TensorBlock
Definition: TensorLayoutSwap.h:113
Eigen::TensorEvaluator< const TensorLayoutSwapOp< ArgType >, Device >::Dimensions
DSizes< Index, NumDims > Dimensions
Definition: TensorLayoutSwap.h:100
Scalar
SCALAR Scalar
Definition: bench_gemm.cpp:46
Eigen::Index
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74
Eigen::Dense
Definition: Constants.h:507
Eigen::TensorLayoutSwapOp::Base
TensorBase< TensorLayoutSwapOp< XprType >, WriteAccessors > Base
Definition: TensorLayoutSwap.h:72


gtsam
Author(s):
autogenerated on Sun Dec 22 2024 04:15:08