10 #ifndef EIGEN_CXX11_TENSOR_TENSOR_INFLATION_H 11 #define EIGEN_CXX11_TENSOR_TENSOR_INFLATION_H 23 template<
typename Str
ides,
typename XprType>
30 typedef typename XprType::Nested
Nested;
32 static const int NumDimensions = XprTraits::NumDimensions;
33 static const int Layout = XprTraits::Layout;
37 template<
typename Str
ides,
typename XprType>
43 template<
typename Str
ides,
typename XprType>
51 template<
typename Str
ides,
typename XprType>
63 : m_xpr(expr), m_strides(strides) {}
66 const Strides&
strides()
const {
return m_strides; }
78 template<
typename Str
ides,
typename ArgType,
typename Device>
96 PreferBlockAccess =
false,
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) {
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];
141 m_impl.evalSubExprsIfNeeded(
NULL);
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];
189 Index inputIndex = 0;
190 if (getInputIndex(index, &inputIndex)) {
191 return m_impl.coeff(inputIndex);
199 template<
int LoadMode>
207 for (
int i = 0;
i < PacketSize; ++
i) {
208 values[
i] = coeff(index+
i);
210 PacketReturnType rslt = internal::pload<PacketReturnType>(
values);
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)
222 return m_impl.costPerCoeff(vectorized) +
223 TensorOpCost(
sizeof(CoeffReturnType) * input_size / output_size, 0,
224 compute_cost, vectorized, PacketSize);
229 #ifdef EIGEN_USE_SYCL 247 #endif // EIGEN_CXX11_TENSOR_TENSOR_INFLATION_H
#define EIGEN_STRONG_INLINE
Eigen::internal::traits< TensorInflationOp >::Index Index
remove_reference< Nested >::type _Nested
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorInflationOp(const XprType &expr, const Strides &strides)
EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(EvaluatorPointerType)
XprTraits::PointerType PointerType
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool getInputIndex(Index index, Index *inputIndex) const
const TensorInflationOp< Strides, XprType > & type
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index) const
PacketType< CoeffReturnType, Device >::type PacketReturnType
StorageMemory< CoeffReturnType, Device > Storage
traits< XprType > XprTraits
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions & dimensions() const
Namespace containing all symbols from the Eigen library.
A cost model used to limit the number of threads used for evaluating tensor expression.
#define EIGEN_STATIC_ASSERT(CONDITION, MSG)
array< Index, NumDims > m_inputStrides
EIGEN_DEVICE_FUNC const internal::remove_all< typename XprType::Nested >::type & expression() const
DSizes< Index, NumDims > Dimensions
Eigen::internal::traits< TensorInflationOp >::Scalar Scalar
internal::TensorBlockNotImplemented TensorBlock
Generic expression where a coefficient-wise binary operator is applied to two expressions.
TensorInflationOp< Strides, ArgType > XprType
array< Index, NumDims > m_outputStrides
Eigen::NumTraits< Scalar >::Real RealScalar
EIGEN_ALWAYS_INLINE DSizes< IndexType, NumDims > strides(const DSizes< IndexType, NumDims > &dimensions)
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
EIGEN_STRONG_INLINE TensorEvaluator(const XprType &op, const Device &device)
EIGEN_DEVICE_FUNC EvaluatorPointerType data() const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions & dimensions() const
TensorInflationOp< Strides, XprType > type
array< internal::TensorIntDivisor< Index >, NumDims > m_fastStrides
Eigen::internal::traits< TensorInflationOp >::StorageKind StorageKind
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost costPerCoeff(bool vectorized) const
#define EIGEN_DEVICE_FUNC
XprType::CoeffReturnType CoeffReturnType
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const
XprType::CoeffReturnType CoeffReturnType
EIGEN_STRONG_INLINE void cleanup()
Eigen::internal::nested< TensorInflationOp >::type Nested
Storage::Type EvaluatorPointerType
TensorEvaluator< ArgType, Device > m_impl
EIGEN_DEVICE_FUNC const Strides & strides() const
Generic expression where a coefficient-wise unary operator is applied to an expression.
const std::vector< size_t > dimensions
#define EIGEN_UNROLL_LOOP
XprTraits::StorageKind StorageKind