10 #ifndef EIGEN_CXX11_TENSOR_TENSOR_INFLATION_H
11 #define EIGEN_CXX11_TENSOR_TENSOR_INFLATION_H
13 #include "./InternalHeaderCheck.h"
25 template<
typename Str
ides,
typename XprType>
26 struct traits<TensorInflationOp<Strides, XprType> > :
public traits<XprType>
28 typedef typename XprType::Scalar Scalar;
29 typedef traits<XprType> XprTraits;
30 typedef typename XprTraits::StorageKind StorageKind;
31 typedef typename XprTraits::Index
Index;
32 typedef typename XprType::Nested Nested;
33 typedef std::remove_reference_t<Nested> Nested_;
34 static constexpr
int NumDimensions = XprTraits::NumDimensions;
35 static constexpr
int Layout = XprTraits::Layout;
36 typedef typename XprTraits::PointerType PointerType;
39 template<
typename Str
ides,
typename XprType>
40 struct eval<TensorInflationOp<Strides, XprType>,
Eigen::Dense>
42 typedef const TensorInflationOp<Strides, XprType>& type;
45 template<
typename Str
ides,
typename XprType>
46 struct nested<TensorInflationOp<Strides, XprType>, 1, typename eval<TensorInflationOp<Strides, XprType> >::type>
48 typedef TensorInflationOp<Strides, XprType> type;
53 template<
typename Str
ides,
typename XprType>
54 class TensorInflationOp :
public TensorBase<TensorInflationOp<Strides, XprType>, ReadOnlyAccessors>
57 typedef typename Eigen::internal::traits<TensorInflationOp>::Scalar Scalar;
59 typedef typename XprType::CoeffReturnType CoeffReturnType;
60 typedef typename Eigen::internal::nested<TensorInflationOp>::type Nested;
61 typedef typename Eigen::internal::traits<TensorInflationOp>::StorageKind StorageKind;
62 typedef typename Eigen::internal::traits<TensorInflationOp>::Index
Index;
64 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorInflationOp(
const XprType& expr,
const Strides& strides)
65 : m_xpr(expr), m_strides(strides) {}
68 const Strides& strides()
const {
return m_strides; }
71 const internal::remove_all_t<typename XprType::Nested>&
72 expression()
const {
return m_xpr; }
75 typename XprType::Nested m_xpr;
76 const Strides m_strides;
80 template<
typename Str
ides,
typename ArgType,
typename Device>
81 struct TensorEvaluator<const TensorInflationOp<Strides, ArgType>, Device>
83 typedef TensorInflationOp<Strides, ArgType> XprType;
84 typedef typename XprType::Index Index;
85 static constexpr
int NumDims = internal::array_size<typename TensorEvaluator<ArgType, Device>::Dimensions>::value;
86 typedef DSizes<Index, NumDims> Dimensions;
87 typedef typename XprType::Scalar Scalar;
88 typedef typename XprType::CoeffReturnType CoeffReturnType;
89 typedef typename PacketType<CoeffReturnType, Device>::type PacketReturnType;
90 static constexpr
int PacketSize = PacketType<CoeffReturnType, Device>::size;
91 typedef StorageMemory<CoeffReturnType, Device> Storage;
92 typedef typename Storage::Type EvaluatorPointerType;
94 static constexpr
int Layout = TensorEvaluator<ArgType, Device>::Layout;
97 PacketAccess = TensorEvaluator<ArgType, Device>::PacketAccess,
99 PreferBlockAccess =
false,
105 typedef internal::TensorBlockNotImplemented TensorBlock;
108 EIGEN_STRONG_INLINE TensorEvaluator(
const XprType& op,
const Device& device)
109 : m_impl(op.expression(), device), m_strides(op.strides())
111 m_dimensions = m_impl.dimensions();
113 for (
int i = 0; i < NumDims; ++i) {
114 m_dimensions[i] = (m_dimensions[i] - 1) * op.strides()[i] + 1;
118 for (
int i = 0; i < NumDims; ++i) {
119 m_fastStrides[i] = internal::TensorIntDivisor<Index>(m_strides[i]);
122 const typename TensorEvaluator<ArgType, Device>::Dimensions& input_dims = m_impl.dimensions();
123 if (
static_cast<int>(Layout) ==
static_cast<int>(
ColMajor)) {
124 m_outputStrides[0] = 1;
125 m_inputStrides[0] = 1;
126 for (
int i = 1; i < NumDims; ++i) {
127 m_outputStrides[i] = m_outputStrides[i-1] * m_dimensions[i-1];
128 m_inputStrides[i] = m_inputStrides[i-1] * input_dims[i-1];
131 m_outputStrides[NumDims-1] = 1;
132 m_inputStrides[NumDims-1] = 1;
133 for (
int i = NumDims - 2; i >= 0; --i) {
134 m_outputStrides[i] = m_outputStrides[i+1] * m_dimensions[i+1];
135 m_inputStrides[i] = m_inputStrides[i+1] * input_dims[i+1];
140 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Dimensions& dimensions()
const {
return m_dimensions; }
142 EIGEN_STRONG_INLINE
bool evalSubExprsIfNeeded(EvaluatorPointerType ) {
143 m_impl.evalSubExprsIfNeeded(NULL);
146 EIGEN_STRONG_INLINE
void cleanup() {
152 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
bool getInputIndex(Index index, Index* inputIndex)
const
154 eigen_assert(index < dimensions().TotalSize());
156 if (
static_cast<int>(Layout) ==
static_cast<int>(
ColMajor)) {
158 for (
int i = NumDims - 1; i > 0; --i) {
159 const Index idx = index / m_outputStrides[i];
160 if (idx != idx / m_fastStrides[i] * m_strides[i]) {
163 *inputIndex += idx / m_strides[i] * m_inputStrides[i];
164 index -= idx * m_outputStrides[i];
166 if (index != index / m_fastStrides[0] * m_strides[0]) {
169 *inputIndex += index / m_strides[0];
173 for (
int i = 0; i < NumDims - 1; ++i) {
174 const Index idx = index / m_outputStrides[i];
175 if (idx != idx / m_fastStrides[i] * m_strides[i]) {
178 *inputIndex += idx / m_strides[i] * m_inputStrides[i];
179 index -= idx * m_outputStrides[i];
181 if (index != index / m_fastStrides[NumDims-1] * m_strides[NumDims-1]) {
184 *inputIndex += index / m_strides[NumDims - 1];
189 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index)
const
191 Index inputIndex = 0;
192 if (getInputIndex(index, &inputIndex)) {
193 return m_impl.coeff(inputIndex);
201 template<
int LoadMode>
202 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index)
const
204 EIGEN_STATIC_ASSERT((PacketSize > 1), YOU_MADE_A_PROGRAMMING_MISTAKE)
205 eigen_assert(index+PacketSize-1 < dimensions().TotalSize());
207 EIGEN_ALIGN_MAX std::remove_const_t<CoeffReturnType> values[PacketSize];
209 for (
int i = 0; i < PacketSize; ++i) {
210 values[i] = coeff(index+i);
212 PacketReturnType rslt = internal::pload<PacketReturnType>(values);
216 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost costPerCoeff(
bool vectorized)
const {
217 const double compute_cost = NumDims * (3 * TensorOpCost::DivCost<Index>() +
218 3 * TensorOpCost::MulCost<Index>() +
219 2 * TensorOpCost::AddCost<Index>());
220 const double input_size = m_impl.dimensions().TotalSize();
221 const double output_size = m_dimensions.TotalSize();
222 if (output_size == 0)
223 return TensorOpCost();
224 return m_impl.costPerCoeff(vectorized) +
225 TensorOpCost(
sizeof(CoeffReturnType) * input_size / output_size, 0,
226 compute_cost, vectorized, PacketSize);
229 EIGEN_DEVICE_FUNC EvaluatorPointerType data()
const {
return NULL; }
231 #ifdef EIGEN_USE_SYCL
233 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void bind(cl::sycl::handler &cgh)
const {
239 Dimensions m_dimensions;
240 array<Index, NumDims> m_outputStrides;
241 array<Index, NumDims> m_inputStrides;
242 TensorEvaluator<ArgType, Device> m_impl;
243 const Strides m_strides;
244 array<internal::TensorIntDivisor<Index>, NumDims> m_fastStrides;
Namespace containing all symbols from the Eigen library.
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index