10 #ifndef EIGEN_CXX11_TENSOR_TENSOR_INFLATION_H 11 #define EIGEN_CXX11_TENSOR_TENSOR_INFLATION_H 23 template<
typename Str
ides,
typename XprType>
26 typedef typename XprType::Scalar Scalar;
28 typedef typename XprTraits::StorageKind StorageKind;
29 typedef typename XprTraits::Index
Index;
30 typedef typename XprType::Nested Nested;
32 static const int NumDimensions = XprTraits::NumDimensions;
33 static const int Layout = XprTraits::Layout;
36 template<
typename Str
ides,
typename XprType>
42 template<
typename Str
ides,
typename XprType>
50 template<
typename Str
ides,
typename XprType>
56 typedef typename XprType::CoeffReturnType CoeffReturnType;
61 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
TensorInflationOp(
const XprType& expr,
const Strides& strides)
62 : m_xpr(expr), m_strides(strides) {}
65 const Strides& strides()
const {
return m_strides; }
69 expression()
const {
return m_xpr; }
72 typename XprType::Nested m_xpr;
73 const Strides m_strides;
77 template<
typename Str
ides,
typename ArgType,
typename Device>
81 typedef typename XprType::Index
Index;
84 typedef typename XprType::Scalar Scalar;
85 typedef typename XprType::CoeffReturnType CoeffReturnType;
98 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
TensorEvaluator(
const XprType& op,
const Device& device)
99 : m_impl(op.expression(), device), m_strides(op.strides())
101 m_dimensions = m_impl.dimensions();
103 for (
int i = 0; i < NumDims; ++i) {
104 m_dimensions[i] = (m_dimensions[i] - 1) * op.strides()[i] + 1;
108 for (
int i = 0; i < NumDims; ++i) {
113 if (static_cast<int>(Layout) == static_cast<int>(
ColMajor)) {
114 m_outputStrides[0] = 1;
115 m_inputStrides[0] = 1;
116 for (
int i = 1; i < NumDims; ++i) {
117 m_outputStrides[i] = m_outputStrides[i-1] * m_dimensions[i-1];
118 m_inputStrides[i] = m_inputStrides[i-1] * input_dims[i-1];
121 m_outputStrides[NumDims-1] = 1;
122 m_inputStrides[NumDims-1] = 1;
123 for (
int i = NumDims - 2; i >= 0; --i) {
124 m_outputStrides[i] = m_outputStrides[i+1] * m_dimensions[i+1];
125 m_inputStrides[i] = m_inputStrides[i+1] * input_dims[i+1];
130 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Dimensions& dimensions()
const {
return m_dimensions; }
132 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
bool evalSubExprsIfNeeded(Scalar* ) {
133 m_impl.evalSubExprsIfNeeded(NULL);
136 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void cleanup() {
142 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
bool getInputIndex(Index index, Index* inputIndex)
const 144 eigen_assert(index < dimensions().TotalSize());
146 if (static_cast<int>(Layout) == static_cast<int>(
ColMajor)) {
147 for (
int i = NumDims - 1; i > 0; --i) {
148 const Index idx = index / m_outputStrides[i];
149 if (idx != idx / m_fastStrides[i] * m_strides[i]) {
152 *inputIndex += idx / m_strides[i] * m_inputStrides[i];
153 index -= idx * m_outputStrides[i];
155 if (index != index / m_fastStrides[0] * m_strides[0]) {
158 *inputIndex += index / m_strides[0];
161 for (
int i = 0; i < NumDims - 1; ++i) {
162 const Index idx = index / m_outputStrides[i];
163 if (idx != idx / m_fastStrides[i] * m_strides[i]) {
166 *inputIndex += idx / m_strides[i] * m_inputStrides[i];
167 index -= idx * m_outputStrides[i];
169 if (index != index / m_fastStrides[NumDims-1] * m_strides[NumDims-1]) {
172 *inputIndex += index / m_strides[NumDims - 1];
177 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index)
const 179 Index inputIndex = 0;
180 if (getInputIndex(index, &inputIndex)) {
181 return m_impl.coeff(inputIndex);
189 template<
int LoadMode>
190 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index)
const 192 EIGEN_STATIC_ASSERT((PacketSize > 1), YOU_MADE_A_PROGRAMMING_MISTAKE)
193 eigen_assert(index+PacketSize-1 < dimensions().TotalSize());
196 for (
int i = 0; i < PacketSize; ++i) {
197 values[i] = coeff(index+i);
199 PacketReturnType rslt = internal::pload<PacketReturnType>(values);
203 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
TensorOpCost costPerCoeff(
bool vectorized)
const {
204 const double compute_cost = NumDims * (3 * TensorOpCost::DivCost<Index>() +
205 3 * TensorOpCost::MulCost<Index>() +
206 2 * TensorOpCost::AddCost<Index>());
207 const double input_size = m_impl.dimensions().TotalSize();
208 const double output_size = m_dimensions.TotalSize();
209 if (output_size == 0)
211 return m_impl.costPerCoeff(vectorized) +
212 TensorOpCost(
sizeof(CoeffReturnType) * input_size / output_size, 0,
213 compute_cost, vectorized, PacketSize);
216 EIGEN_DEVICE_FUNC Scalar* data()
const {
return NULL; }
219 Dimensions m_dimensions;
223 const Strides m_strides;
229 #endif // EIGEN_CXX11_TENSOR_TENSOR_INFLATION_H Definition: TensorCostModel.h:25
Storage order is column major (see TopicStorageOrders).
Definition: Constants.h:320
Definition: XprHelper.h:158
Definition: TensorForwardDeclarations.h:57
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:85
A cost model used to limit the number of threads used for evaluating tensor expression.
Definition: TensorEvaluator.h:28
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33
The tensor base class.
Definition: TensorBase.h:827
Definition: BandTriangularSolver.h:13
Definition: TensorTraits.h:170
The type used to identify a dense storage.
Definition: Constants.h:491
Generic expression where a coefficient-wise unary operator is applied to an expression.
Definition: CwiseUnaryOp.h:55
Definition: ForwardDeclarations.h:17
Definition: XprHelper.h:312
Definition: EmulateArray.h:203