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 
139  EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(EvaluatorPointerType data) {
140  return m_impl.evalSubExprsIfNeeded(data);
141  }
143  m_impl.cleanup();
144  }
145 
146  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const
147  {
148  return m_impl.coeff(index);
149  }
150 
151  template<int LoadMode>
152  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const
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:
169  Dimensions m_dimensions;
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 
203  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType& coeffRef(Index index)
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::internal::traits< TensorLayoutSwapOp >::Scalar Scalar
SCALAR Scalar
Definition: bench_gemm.cpp:46
#define EIGEN_STRONG_INLINE
Definition: Macros.h:917
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost costPerCoeff(bool vectorized) const
EIGEN_DEVICE_FUNC const internal::remove_all< typename XprType::Nested >::type & expression() const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType & coeffRef(Index index)
internal::remove_const< typename XprType::CoeffReturnType >::type CoeffReturnType
Eigen::internal::traits< TensorLayoutSwapOp >::StorageKind StorageKind
Eigen::internal::traits< TensorLayoutSwapOp >::Index Index
Namespace containing all symbols from the Eigen library.
Definition: jet.h:637
A cost model used to limit the number of threads used for evaluating tensor expression.
Eigen::internal::nested< TensorLayoutSwapOp >::type Nested
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions & dimensions() const
EIGEN_STRONG_INLINE TensorEvaluator(const XprType &op, const Device &device)
Generic expression where a coefficient-wise binary operator is applied to two expressions.
Definition: CwiseBinaryOp.h:77
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T * constCast(const T *data)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorLayoutSwapOp(const XprType &expr)
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const
const TensorEvaluator< ArgType, Device > & impl() const
int data[]
TensorBase< TensorLayoutSwapOp< XprType >, WriteAccessors > Base
EIGEN_STRONG_INLINE TensorEvaluator(const XprType &op, const Device &device)
TensorEvaluator< const TensorLayoutSwapOp< ArgType >, Device > Base
The tensor base class.
Definition: TensorBase.h:973
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:976
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const
PacketType< CoeffReturnType, Device >::type PacketReturnType
Eigen::NumTraits< Scalar >::Real RealScalar
#define EIGEN_TENSOR_INHERIT_ASSIGNMENT_OPERATORS(Derived)
Definition: TensorMacros.h:94
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void writePacket(Index index, const PacketReturnType &x)
EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(EvaluatorPointerType data)
Generic expression where a coefficient-wise unary operator is applied to an expression.
Definition: CwiseUnaryOp.h:55
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


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:37:05