Eigen-unsupported  3.4.1 (git rev 28ded8800c26864e537852658428ab44c8399e87)
 
Loading...
Searching...
No Matches
TensorLayoutSwap.h
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
13namespace Eigen {
14
15namespace internal {
16template<typename XprType>
17struct traits<TensorLayoutSwapOp<XprType> > : public traits<XprType>
18{
19 typedef typename XprType::Scalar Scalar;
20 typedef traits<XprType> XprTraits;
21 typedef typename XprTraits::StorageKind StorageKind;
22 typedef typename XprTraits::Index Index;
23 typedef typename XprType::Nested Nested;
24 typedef typename remove_reference<Nested>::type _Nested;
25 static const int NumDimensions = traits<XprType>::NumDimensions;
26 static const int Layout = (traits<XprType>::Layout == ColMajor) ? RowMajor : ColMajor;
27 typedef typename XprTraits::PointerType PointerType;
28};
29
30template<typename XprType>
31struct eval<TensorLayoutSwapOp<XprType>, Eigen::Dense>
32{
33 typedef const TensorLayoutSwapOp<XprType>& type;
34};
35
36template<typename XprType>
37struct nested<TensorLayoutSwapOp<XprType>, 1, typename eval<TensorLayoutSwapOp<XprType> >::type>
38{
39 typedef TensorLayoutSwapOp<XprType> type;
40};
41
42} // end namespace internal
43
66template <typename XprType>
67class TensorLayoutSwapOp : public TensorBase<TensorLayoutSwapOp<XprType>, WriteAccessors> {
68 public:
69 typedef TensorBase<TensorLayoutSwapOp<XprType>, WriteAccessors> Base;
70 typedef typename Eigen::internal::traits<TensorLayoutSwapOp>::Scalar Scalar;
71 typedef typename Eigen::NumTraits<Scalar>::Real RealScalar;
72 typedef typename internal::remove_const<typename XprType::CoeffReturnType>::type CoeffReturnType;
73 typedef typename Eigen::internal::nested<TensorLayoutSwapOp>::type Nested;
74 typedef typename Eigen::internal::traits<TensorLayoutSwapOp>::StorageKind StorageKind;
75 typedef typename Eigen::internal::traits<TensorLayoutSwapOp>::Index Index;
76
77 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorLayoutSwapOp(const XprType& expr)
78 : m_xpr(expr) {}
79
80 EIGEN_DEVICE_FUNC
81 const typename internal::remove_all<typename XprType::Nested>::type&
82 expression() const { return m_xpr; }
83
84 EIGEN_TENSOR_INHERIT_ASSIGNMENT_OPERATORS(TensorLayoutSwapOp)
85 protected:
86 typename XprType::Nested m_xpr;
87};
88
89
90// Eval as rvalue
91template<typename ArgType, typename Device>
92struct TensorEvaluator<const TensorLayoutSwapOp<ArgType>, Device>
93{
94 typedef TensorLayoutSwapOp<ArgType> XprType;
95 typedef typename XprType::Index Index;
96 static const int NumDims = internal::array_size<typename TensorEvaluator<ArgType, Device>::Dimensions>::value;
97 typedef DSizes<Index, NumDims> Dimensions;
98
99 enum {
100 IsAligned = TensorEvaluator<ArgType, Device>::IsAligned,
101 PacketAccess = TensorEvaluator<ArgType, Device>::PacketAccess,
102 BlockAccess = false,
103 PreferBlockAccess = TensorEvaluator<ArgType, Device>::PreferBlockAccess,
104 Layout = (static_cast<int>(TensorEvaluator<ArgType, Device>::Layout) == static_cast<int>(ColMajor)) ? RowMajor : ColMajor,
105 CoordAccess = false, // to be implemented
106 RawAccess = TensorEvaluator<ArgType, Device>::RawAccess
107 };
108
109 //===- Tensor block evaluation strategy (see TensorBlock.h) -------------===//
110 typedef internal::TensorBlockNotImplemented TensorBlock;
111 //===--------------------------------------------------------------------===//
112
113 EIGEN_STRONG_INLINE TensorEvaluator(const XprType& op, const Device& device)
114 : m_impl(op.expression(), device)
115 {
116 for(int i = 0; i < NumDims; ++i) {
117 m_dimensions[i] = m_impl.dimensions()[NumDims-1-i];
118 }
119 }
120
121#ifdef EIGEN_USE_SYCL
122 // binding placeholder accessors to a command group handler for SYCL
123 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void bind(cl::sycl::handler &cgh) const {
124 m_impl.bind(cgh);
125 }
126#endif
127
128 typedef typename XprType::Scalar Scalar;
129 typedef typename XprType::CoeffReturnType CoeffReturnType;
130 typedef typename PacketType<CoeffReturnType, Device>::type PacketReturnType;
131 typedef StorageMemory<CoeffReturnType, Device> Storage;
132 typedef typename Storage::Type EvaluatorPointerType;
133
134 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions& dimensions() const { return m_dimensions; }
135
136 EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(EvaluatorPointerType data) {
137 return m_impl.evalSubExprsIfNeeded(data);
138 }
139 EIGEN_STRONG_INLINE void cleanup() {
140 m_impl.cleanup();
141 }
142
143 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const
144 {
145 return m_impl.coeff(index);
146 }
147
148 template<int LoadMode>
149 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const
150 {
151 return m_impl.template packet<LoadMode>(index);
152 }
153
154 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost costPerCoeff(bool vectorized) const {
155 return m_impl.costPerCoeff(vectorized);
156 }
157
158 EIGEN_DEVICE_FUNC typename Storage::Type data() const {
159 return constCast(m_impl.data());
160 }
161
162 const TensorEvaluator<ArgType, Device>& impl() const { return m_impl; }
163
164 protected:
165 TensorEvaluator<ArgType, Device> m_impl;
166 Dimensions m_dimensions;
167};
168
169
170// Eval as lvalue
171template<typename ArgType, typename Device>
172 struct TensorEvaluator<TensorLayoutSwapOp<ArgType>, Device>
173 : public TensorEvaluator<const TensorLayoutSwapOp<ArgType>, Device>
174{
175 typedef TensorEvaluator<const TensorLayoutSwapOp<ArgType>, Device> Base;
176 typedef TensorLayoutSwapOp<ArgType> XprType;
177
178 enum {
179 IsAligned = TensorEvaluator<ArgType, Device>::IsAligned,
180 PacketAccess = TensorEvaluator<ArgType, Device>::PacketAccess,
181 BlockAccess = false,
182 PreferBlockAccess = TensorEvaluator<ArgType, Device>::PreferBlockAccess,
183 Layout = (static_cast<int>(TensorEvaluator<ArgType, Device>::Layout) == static_cast<int>(ColMajor)) ? RowMajor : ColMajor,
184 CoordAccess = false // to be implemented
185 };
186
187 //===- Tensor block evaluation strategy (see TensorBlock.h) -------------===//
188 typedef internal::TensorBlockNotImplemented TensorBlock;
189 //===--------------------------------------------------------------------===//
190
191 EIGEN_STRONG_INLINE TensorEvaluator(const XprType& op, const Device& device)
192 : Base(op, device)
193 { }
194
195 typedef typename XprType::Index Index;
196 typedef typename XprType::Scalar Scalar;
197 typedef typename XprType::CoeffReturnType CoeffReturnType;
198 typedef typename PacketType<CoeffReturnType, Device>::type PacketReturnType;
199
200 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType& coeffRef(Index index)
201 {
202 return this->m_impl.coeffRef(index);
203 }
204 template <int StoreMode> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
205 void writePacket(Index index, const PacketReturnType& x)
206 {
207 this->m_impl.template writePacket<StoreMode>(index, x);
208 }
209};
210
211} // end namespace Eigen
212
213#endif // EIGEN_CXX11_TENSOR_TENSOR_LAYOUT_SWAP_H
The tensor base class.
Definition TensorForwardDeclarations.h:56
WriteAccessors
Namespace containing all symbols from the Eigen library.
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The tensor evaluator class.
Definition TensorEvaluator.h:27