10 #ifndef EIGEN_CXX11_TENSOR_TENSOR_INFLATION_H 11 #define EIGEN_CXX11_TENSOR_TENSOR_INFLATION_H 23 template<
typename Str
ides,
typename XprType>
24 struct traits<TensorInflationOp<Strides, XprType> > :
public traits<XprType>
26 typedef typename XprType::Scalar Scalar;
27 typedef traits<XprType> XprTraits;
28 typedef typename XprTraits::StorageKind StorageKind;
29 typedef typename XprTraits::Index
Index;
30 typedef typename XprType::Nested Nested;
31 typedef typename remove_reference<Nested>::type _Nested;
32 static const int NumDimensions = XprTraits::NumDimensions;
33 static const int Layout = XprTraits::Layout;
34 typedef typename XprTraits::PointerType PointerType;
37 template<
typename Str
ides,
typename XprType>
38 struct eval<TensorInflationOp<Strides, XprType>,
Eigen::Dense>
40 typedef const TensorInflationOp<Strides, XprType>& type;
43 template<
typename Str
ides,
typename XprType>
44 struct nested<TensorInflationOp<Strides, XprType>, 1, typename eval<TensorInflationOp<Strides, XprType> >::type>
46 typedef TensorInflationOp<Strides, XprType> type;
51 template<
typename Str
ides,
typename XprType>
52 class TensorInflationOp :
public TensorBase<TensorInflationOp<Strides, XprType>, ReadOnlyAccessors>
55 typedef typename Eigen::internal::traits<TensorInflationOp>::Scalar Scalar;
57 typedef typename XprType::CoeffReturnType CoeffReturnType;
58 typedef typename Eigen::internal::nested<TensorInflationOp>::type Nested;
59 typedef typename Eigen::internal::traits<TensorInflationOp>::StorageKind StorageKind;
60 typedef typename Eigen::internal::traits<TensorInflationOp>::Index
Index;
62 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorInflationOp(
const XprType& expr,
const Strides& strides)
63 : m_xpr(expr), m_strides(strides) {}
66 const Strides& strides()
const {
return m_strides; }
69 const typename internal::remove_all<typename XprType::Nested>::type&
70 expression()
const {
return m_xpr; }
73 typename XprType::Nested m_xpr;
74 const Strides m_strides;
78 template<
typename Str
ides,
typename ArgType,
typename Device>
79 struct TensorEvaluator<const TensorInflationOp<Strides, ArgType>, Device>
81 typedef TensorInflationOp<Strides, ArgType> XprType;
82 typedef typename XprType::Index
Index;
83 static const int NumDims = internal::array_size<typename TensorEvaluator<ArgType, Device>::Dimensions>::value;
84 typedef DSizes<Index, NumDims> Dimensions;
85 typedef typename XprType::Scalar Scalar;
86 typedef typename XprType::CoeffReturnType CoeffReturnType;
87 typedef typename PacketType<CoeffReturnType, Device>::type PacketReturnType;
88 static const int PacketSize = PacketType<CoeffReturnType, Device>::size;
89 typedef StorageMemory<CoeffReturnType, Device> Storage;
90 typedef typename Storage::Type EvaluatorPointerType;
94 PacketAccess = TensorEvaluator<ArgType, Device>::PacketAccess,
96 PreferBlockAccess =
false,
97 Layout = TensorEvaluator<ArgType, Device>::Layout,
103 typedef internal::TensorBlockNotImplemented TensorBlock;
106 EIGEN_STRONG_INLINE TensorEvaluator(
const XprType& op,
const Device& device)
107 : m_impl(op.expression(), device), m_strides(op.strides())
109 m_dimensions = m_impl.dimensions();
111 for (
int i = 0; i < NumDims; ++i) {
112 m_dimensions[i] = (m_dimensions[i] - 1) * op.strides()[i] + 1;
116 for (
int i = 0; i < NumDims; ++i) {
117 m_fastStrides[i] = internal::TensorIntDivisor<Index>(m_strides[i]);
120 const typename TensorEvaluator<ArgType, Device>::Dimensions& input_dims = m_impl.dimensions();
121 if (static_cast<int>(Layout) == static_cast<int>(
ColMajor)) {
122 m_outputStrides[0] = 1;
123 m_inputStrides[0] = 1;
124 for (
int i = 1; i < NumDims; ++i) {
125 m_outputStrides[i] = m_outputStrides[i-1] * m_dimensions[i-1];
126 m_inputStrides[i] = m_inputStrides[i-1] * input_dims[i-1];
129 m_outputStrides[NumDims-1] = 1;
130 m_inputStrides[NumDims-1] = 1;
131 for (
int i = NumDims - 2; i >= 0; --i) {
132 m_outputStrides[i] = m_outputStrides[i+1] * m_dimensions[i+1];
133 m_inputStrides[i] = m_inputStrides[i+1] * input_dims[i+1];
138 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Dimensions& dimensions()
const {
return m_dimensions; }
140 EIGEN_STRONG_INLINE
bool evalSubExprsIfNeeded(EvaluatorPointerType ) {
141 m_impl.evalSubExprsIfNeeded(NULL);
144 EIGEN_STRONG_INLINE
void cleanup() {
150 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
bool getInputIndex(Index index, Index* inputIndex)
const 152 eigen_assert(index < dimensions().TotalSize());
154 if (static_cast<int>(Layout) == static_cast<int>(
ColMajor)) {
156 for (
int i = NumDims - 1; i > 0; --i) {
157 const Index idx = index / m_outputStrides[i];
158 if (idx != idx / m_fastStrides[i] * m_strides[i]) {
161 *inputIndex += idx / m_strides[i] * m_inputStrides[i];
162 index -= idx * m_outputStrides[i];
164 if (index != index / m_fastStrides[0] * m_strides[0]) {
167 *inputIndex += index / m_strides[0];
171 for (
int i = 0; i < NumDims - 1; ++i) {
172 const Index idx = index / m_outputStrides[i];
173 if (idx != idx / m_fastStrides[i] * m_strides[i]) {
176 *inputIndex += idx / m_strides[i] * m_inputStrides[i];
177 index -= idx * m_outputStrides[i];
179 if (index != index / m_fastStrides[NumDims-1] * m_strides[NumDims-1]) {
182 *inputIndex += index / m_strides[NumDims - 1];
187 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index)
const 189 Index inputIndex = 0;
190 if (getInputIndex(index, &inputIndex)) {
191 return m_impl.coeff(inputIndex);
199 template<
int LoadMode>
200 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index)
const 202 EIGEN_STATIC_ASSERT((PacketSize > 1), YOU_MADE_A_PROGRAMMING_MISTAKE)
203 eigen_assert(index+PacketSize-1 < dimensions().TotalSize());
205 EIGEN_ALIGN_MAX
typename internal::remove_const<CoeffReturnType>::type values[PacketSize];
207 for (
int i = 0; i < PacketSize; ++i) {
208 values[i] = coeff(index+i);
210 PacketReturnType rslt = internal::pload<PacketReturnType>(values);
214 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost costPerCoeff(
bool vectorized)
const {
215 const double compute_cost = NumDims * (3 * TensorOpCost::DivCost<Index>() +
216 3 * TensorOpCost::MulCost<Index>() +
217 2 * TensorOpCost::AddCost<Index>());
218 const double input_size = m_impl.dimensions().TotalSize();
219 const double output_size = m_dimensions.TotalSize();
220 if (output_size == 0)
221 return TensorOpCost();
222 return m_impl.costPerCoeff(vectorized) +
223 TensorOpCost(
sizeof(CoeffReturnType) * input_size / output_size, 0,
224 compute_cost, vectorized, PacketSize);
227 EIGEN_DEVICE_FUNC EvaluatorPointerType data()
const {
return NULL; }
229 #ifdef EIGEN_USE_SYCL 231 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void bind(cl::sycl::handler &cgh)
const {
237 Dimensions m_dimensions;
238 array<Index, NumDims> m_outputStrides;
239 array<Index, NumDims> m_inputStrides;
240 TensorEvaluator<ArgType, Device> m_impl;
241 const Strides m_strides;
242 array<internal::TensorIntDivisor<Index>, NumDims> m_fastStrides;
247 #endif // EIGEN_CXX11_TENSOR_TENSOR_INFLATION_H
Namespace containing all symbols from the Eigen library.
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index