10#ifndef EIGEN_CXX11_TENSOR_TENSOR_INFLATION_H
11#define EIGEN_CXX11_TENSOR_TENSOR_INFLATION_H
16template<
typename Str
ides,
typename XprType>
17struct traits<TensorInflationOp<Strides, XprType> > :
public traits<XprType>
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 = XprTraits::NumDimensions;
26 static const int Layout = XprTraits::Layout;
27 typedef typename XprTraits::PointerType PointerType;
30template<
typename Str
ides,
typename XprType>
31struct eval<TensorInflationOp<Strides, XprType>, Eigen::Dense>
33 typedef const TensorInflationOp<Strides, XprType>& type;
36template<
typename Str
ides,
typename XprType>
37struct nested<TensorInflationOp<Strides, XprType>, 1, typename eval<TensorInflationOp<Strides, XprType> >::type>
39 typedef TensorInflationOp<Strides, XprType> type;
49template <
typename Str
ides,
typename XprType>
50class TensorInflationOp :
public TensorBase<TensorInflationOp<Strides, XprType>, ReadOnlyAccessors> {
52 typedef typename Eigen::internal::traits<TensorInflationOp>::Scalar Scalar;
54 typedef typename XprType::CoeffReturnType CoeffReturnType;
55 typedef typename Eigen::internal::nested<TensorInflationOp>::type Nested;
56 typedef typename Eigen::internal::traits<TensorInflationOp>::StorageKind StorageKind;
57 typedef typename Eigen::internal::traits<TensorInflationOp>::Index Index;
59 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorInflationOp(
const XprType& expr,
const Strides& strides)
60 : m_xpr(expr), m_strides(strides) {}
63 const Strides& strides()
const {
return m_strides; }
66 const typename internal::remove_all<typename XprType::Nested>::type&
67 expression()
const {
return m_xpr; }
70 typename XprType::Nested m_xpr;
71 const Strides m_strides;
75template<
typename Str
ides,
typename ArgType,
typename Device>
79 typedef typename XprType::Index
Index;
80 static const int NumDims = internal::array_size<typename TensorEvaluator<ArgType, Device>::Dimensions>::value;
82 typedef typename XprType::Scalar
Scalar;
84 typedef typename PacketType<CoeffReturnType, Device>::type PacketReturnType;
85 static const int PacketSize = PacketType<CoeffReturnType, Device>::size;
86 typedef StorageMemory<CoeffReturnType, Device> Storage;
87 typedef typename Storage::Type EvaluatorPointerType;
91 PacketAccess = TensorEvaluator<ArgType, Device>::PacketAccess,
93 PreferBlockAccess =
false,
94 Layout = TensorEvaluator<ArgType, Device>::Layout,
100 typedef internal::TensorBlockNotImplemented TensorBlock;
103 EIGEN_STRONG_INLINE TensorEvaluator(
const XprType& op,
const Device& device)
104 : m_impl(op.expression(), device), m_strides(op.strides())
106 m_dimensions = m_impl.dimensions();
108 for (
int i = 0; i < NumDims; ++i) {
109 m_dimensions[i] = (m_dimensions[i] - 1) * op.strides()[i] + 1;
113 for (
int i = 0; i < NumDims; ++i) {
114 m_fastStrides[i] = internal::TensorIntDivisor<Index>(m_strides[i]);
117 const typename TensorEvaluator<ArgType, Device>::Dimensions& input_dims = m_impl.dimensions();
118 if (
static_cast<int>(Layout) ==
static_cast<int>(
ColMajor)) {
119 m_outputStrides[0] = 1;
120 m_inputStrides[0] = 1;
121 for (
int i = 1; i < NumDims; ++i) {
122 m_outputStrides[i] = m_outputStrides[i-1] * m_dimensions[i-1];
123 m_inputStrides[i] = m_inputStrides[i-1] * input_dims[i-1];
126 m_outputStrides[NumDims-1] = 1;
127 m_inputStrides[NumDims-1] = 1;
128 for (
int i = NumDims - 2; i >= 0; --i) {
129 m_outputStrides[i] = m_outputStrides[i+1] * m_dimensions[i+1];
130 m_inputStrides[i] = m_inputStrides[i+1] * input_dims[i+1];
135 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Dimensions& dimensions()
const {
return m_dimensions; }
137 EIGEN_STRONG_INLINE
bool evalSubExprsIfNeeded(EvaluatorPointerType ) {
138 m_impl.evalSubExprsIfNeeded(NULL);
141 EIGEN_STRONG_INLINE
void cleanup() {
147 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
bool getInputIndex(Index index, Index* inputIndex)
const
149 eigen_assert(index < dimensions().TotalSize());
151 if (
static_cast<int>(Layout) ==
static_cast<int>(
ColMajor)) {
153 for (
int i = NumDims - 1; i > 0; --i) {
154 const Index idx = index / m_outputStrides[i];
155 if (idx != idx / m_fastStrides[i] * m_strides[i]) {
158 *inputIndex += idx / m_strides[i] * m_inputStrides[i];
159 index -= idx * m_outputStrides[i];
161 if (index != index / m_fastStrides[0] * m_strides[0]) {
164 *inputIndex += index / m_strides[0];
168 for (
int i = 0; i < NumDims - 1; ++i) {
169 const Index idx = index / m_outputStrides[i];
170 if (idx != idx / m_fastStrides[i] * m_strides[i]) {
173 *inputIndex += idx / m_strides[i] * m_inputStrides[i];
174 index -= idx * m_outputStrides[i];
176 if (index != index / m_fastStrides[NumDims-1] * m_strides[NumDims-1]) {
179 *inputIndex += index / m_strides[NumDims - 1];
184 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index)
const
186 Index inputIndex = 0;
187 if (getInputIndex(index, &inputIndex)) {
188 return m_impl.coeff(inputIndex);
196 template<
int LoadMode>
197 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index)
const
199 EIGEN_STATIC_ASSERT((PacketSize > 1), YOU_MADE_A_PROGRAMMING_MISTAKE)
200 eigen_assert(index+PacketSize-1 < dimensions().TotalSize());
202 EIGEN_ALIGN_MAX
typename internal::remove_const<CoeffReturnType>::type values[PacketSize];
204 for (
int i = 0; i < PacketSize; ++i) {
205 values[i] = coeff(index+i);
207 PacketReturnType rslt = internal::pload<PacketReturnType>(values);
211 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost costPerCoeff(
bool vectorized)
const {
212 const double compute_cost = NumDims * (3 * TensorOpCost::DivCost<Index>() +
213 3 * TensorOpCost::MulCost<Index>() +
214 2 * TensorOpCost::AddCost<Index>());
215 const double input_size = m_impl.dimensions().TotalSize();
216 const double output_size = m_dimensions.TotalSize();
217 if (output_size == 0)
218 return TensorOpCost();
219 return m_impl.costPerCoeff(vectorized) +
220 TensorOpCost(
sizeof(CoeffReturnType) * input_size / output_size, 0,
221 compute_cost, vectorized, PacketSize);
224 EIGEN_DEVICE_FUNC EvaluatorPointerType data()
const {
return NULL; }
228 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void bind(cl::sycl::handler &cgh)
const {
234 Dimensions m_dimensions;
235 array<Index, NumDims> m_outputStrides;
236 array<Index, NumDims> m_inputStrides;
237 TensorEvaluator<ArgType, Device> m_impl;
238 const Strides m_strides;
239 array<internal::TensorIntDivisor<Index>, NumDims> m_fastStrides;
The tensor base class.
Definition TensorForwardDeclarations.h:56
Tensor inflation class.
Definition TensorInflation.h:50
Namespace containing all symbols from the Eigen library.
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The tensor evaluator class.
Definition TensorEvaluator.h:27