10 #ifndef EIGEN_CXX11_TENSOR_TENSOR_GENERATOR_H 11 #define EIGEN_CXX11_TENSOR_TENSOR_GENERATOR_H 23 template<
typename Generator,
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 Generator,
typename XprType>
42 template<
typename Generator,
typename XprType>
52 template<
typename Generator,
typename XprType>
58 typedef typename XprType::CoeffReturnType CoeffReturnType;
63 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
TensorGeneratorOp(
const XprType& expr,
const Generator& generator)
64 : m_xpr(expr), m_generator(generator) {}
67 const Generator& generator()
const {
return m_generator; }
71 expression()
const {
return m_xpr; }
74 typename XprType::Nested m_xpr;
75 const Generator m_generator;
80 template<
typename Generator,
typename ArgType,
typename Device>
84 typedef typename XprType::Index
Index;
87 typedef typename XprType::Scalar Scalar;
88 typedef typename XprType::CoeffReturnType CoeffReturnType;
99 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
TensorEvaluator(
const XprType& op,
const Device& device)
100 : m_generator(op.generator())
103 m_dimensions = impl.dimensions();
105 if (static_cast<int>(Layout) == static_cast<int>(
ColMajor)) {
107 for (
int i = 1; i < NumDims; ++i) {
108 m_strides[i] = m_strides[i - 1] * m_dimensions[i - 1];
111 m_strides[NumDims - 1] = 1;
112 for (
int i = NumDims - 2; i >= 0; --i) {
113 m_strides[i] = m_strides[i + 1] * m_dimensions[i + 1];
118 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Dimensions& dimensions()
const {
return m_dimensions; }
120 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
bool evalSubExprsIfNeeded(Scalar* ) {
123 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void cleanup() {
126 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index)
const 129 extract_coordinates(index, coords);
130 return m_generator(coords);
133 template<
int LoadMode>
134 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index)
const 137 EIGEN_STATIC_ASSERT((packetSize > 1), YOU_MADE_A_PROGRAMMING_MISTAKE)
138 eigen_assert(index+packetSize-1 < dimensions().TotalSize());
141 for (
int i = 0; i < packetSize; ++i) {
142 values[i] = coeff(index+i);
144 PacketReturnType rslt = internal::pload<PacketReturnType>(values);
149 costPerCoeff(
bool)
const {
152 return TensorOpCost(0, 0, TensorOpCost::AddCost<Scalar>() +
153 TensorOpCost::MulCost<Scalar>());
156 EIGEN_DEVICE_FUNC Scalar* data()
const {
return NULL; }
159 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
161 if (static_cast<int>(Layout) == static_cast<int>(
ColMajor)) {
162 for (
int i = NumDims - 1; i > 0; --i) {
163 const Index idx = index / m_strides[i];
164 index -= idx * m_strides[i];
169 for (
int i = 0; i < NumDims - 1; ++i) {
170 const Index idx = index / m_strides[i];
171 index -= idx * m_strides[i];
174 coords[NumDims-1] = index;
178 Dimensions m_dimensions;
180 Generator m_generator;
185 #endif // EIGEN_CXX11_TENSOR_TENSOR_GENERATOR_H Definition: TensorCostModel.h:25
Storage order is column major (see TopicStorageOrders).
Definition: Constants.h:320
Definition: TensorForwardDeclarations.h:58
Definition: XprHelper.h:158
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