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 };
50 
51 template<typename XprType>
52 struct eval<TensorLayoutSwapOp<XprType>, Eigen::Dense>
53 {
55 };
56 
57 template<typename XprType>
58 struct nested<TensorLayoutSwapOp<XprType>, 1, typename eval<TensorLayoutSwapOp<XprType> >::type>
59 {
61 };
62 
63 } // end namespace internal
64 
65 
66 
67 template<typename XprType>
68 class TensorLayoutSwapOp : public TensorBase<TensorLayoutSwapOp<XprType>, WriteAccessors>
69 {
70  public:
77 
78  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorLayoutSwapOp(const XprType& expr)
79  : m_xpr(expr) {}
80 
81  EIGEN_DEVICE_FUNC
83  expression() const { return m_xpr; }
84 
85  EIGEN_DEVICE_FUNC
87  {
89  Assign assign(*this, other);
91  return *this;
92  }
93 
94  template<typename OtherDerived>
95  EIGEN_DEVICE_FUNC
96  EIGEN_STRONG_INLINE TensorLayoutSwapOp& operator = (const OtherDerived& other)
97  {
99  Assign assign(*this, other);
101  return *this;
102  }
103 
104  protected:
105  typename XprType::Nested m_xpr;
106 };
107 
108 
109 // Eval as rvalue
110 template<typename ArgType, typename Device>
111 struct TensorEvaluator<const TensorLayoutSwapOp<ArgType>, Device>
112 {
114  typedef typename XprType::Index Index;
117 
118  enum {
121  Layout = (static_cast<int>(TensorEvaluator<ArgType, Device>::Layout) == static_cast<int>(ColMajor)) ? RowMajor : ColMajor,
122  CoordAccess = false, // to be implemented
124  };
125 
126  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvaluator(const XprType& op, const Device& device)
127  : m_impl(op.expression(), device)
128  {
129  for(int i = 0; i < NumDims; ++i) {
130  m_dimensions[i] = m_impl.dimensions()[NumDims-1-i];
131  }
132  }
133 
134  typedef typename XprType::Scalar Scalar;
137 
138  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions& dimensions() const { return m_dimensions; }
139 
140  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(CoeffReturnType* data) {
141  return m_impl.evalSubExprsIfNeeded(data);
142  }
143  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void cleanup() {
144  m_impl.cleanup();
145  }
146 
147  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const
148  {
149  return m_impl.coeff(index);
150  }
151 
152  template<int LoadMode>
153  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const
154  {
155  return m_impl.template packet<LoadMode>(index);
156  }
157 
158  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost costPerCoeff(bool vectorized) const {
159  return m_impl.costPerCoeff(vectorized);
160  }
161 
162  EIGEN_DEVICE_FUNC Scalar* data() const { return m_impl.data(); }
163 
164  const TensorEvaluator<ArgType, Device>& impl() const { return m_impl; }
165 
166  protected:
168  Dimensions m_dimensions;
169 };
170 
171 
172 // Eval as lvalue
173 template<typename ArgType, typename Device>
174  struct TensorEvaluator<TensorLayoutSwapOp<ArgType>, Device>
175  : public TensorEvaluator<const TensorLayoutSwapOp<ArgType>, Device>
176 {
179 
180  enum {
183  Layout = (static_cast<int>(TensorEvaluator<ArgType, Device>::Layout) == static_cast<int>(ColMajor)) ? RowMajor : ColMajor,
184  CoordAccess = false // to be implemented
185  };
186 
187  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvaluator(const XprType& op, const Device& device)
188  : Base(op, device)
189  { }
190 
191  typedef typename XprType::Index Index;
192  typedef typename XprType::Scalar Scalar;
195 
196  EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType& coeffRef(Index index)
197  {
198  return this->m_impl.coeffRef(index);
199  }
200  template <int StoreMode> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
201  void writePacket(Index index, const PacketReturnType& x)
202  {
203  this->m_impl.template writePacket<StoreMode>(index, x);
204  }
205 };
206 
207 } // end namespace Eigen
208 
209 #endif // EIGEN_CXX11_TENSOR_TENSOR_LAYOUT_SWAP_H
Eigen::internal::traits< TensorLayoutSwapOp >::Scalar Scalar
SCALAR Scalar
Definition: bench_gemm.cpp:33
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(CoeffReturnType *data)
#define EIGEN_STRONG_INLINE
Definition: Macros.h:494
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions & dimensions() 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
EIGEN_DEVICE_FUNC const internal::remove_all< typename XprType::Nested >::type & expression() const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvaluator(const XprType &op, const Device &device)
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 TensorEvaluator(const XprType &op, const Device &device)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost costPerCoeff(bool vectorized) const
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:33
int data[]
static EIGEN_DEVICE_FUNC void run(const Expression &expr, const Device &device=Device())
TensorEvaluator< const TensorLayoutSwapOp< ArgType >, Device > Base
The tensor base class.
Definition: TensorBase.h:829
PacketType< CoeffReturnType, Device >::type PacketReturnType
Eigen::NumTraits< Scalar >::Real RealScalar
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void writePacket(Index index, const PacketReturnType &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
const TensorEvaluator< ArgType, Device > & impl() const


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:45:32