10 #ifndef EIGEN_CXX11_TENSOR_TENSOR_FORCED_EVAL_H 11 #define EIGEN_CXX11_TENSOR_TENSOR_FORCED_EVAL_H 29 template<
typename XprType,
template <
class>
class MakePointer_>
30 struct traits<TensorForcedEvalOp<XprType, MakePointer_> >
33 typedef typename XprType::Scalar Scalar;
34 typedef traits<XprType> XprTraits;
35 typedef typename traits<XprType>::StorageKind StorageKind;
36 typedef typename traits<XprType>::Index Index;
37 typedef typename XprType::Nested Nested;
38 typedef typename remove_reference<Nested>::type _Nested;
39 static const int NumDimensions = XprTraits::NumDimensions;
40 static const int Layout = XprTraits::Layout;
45 template <
class T>
struct MakePointer {
47 typedef MakePointer_<T> MakePointerT;
48 typedef typename MakePointerT::Type Type;
52 template<
typename XprType,
template <
class>
class MakePointer_>
53 struct eval<TensorForcedEvalOp<XprType, MakePointer_>,
Eigen::Dense>
55 typedef const TensorForcedEvalOp<XprType, MakePointer_>& type;
58 template<
typename XprType,
template <
class>
class MakePointer_>
59 struct nested<TensorForcedEvalOp<XprType, MakePointer_>, 1, typename eval<TensorForcedEvalOp<XprType, MakePointer_> >::type>
61 typedef TensorForcedEvalOp<XprType, MakePointer_> type;
68 template<
typename XprType,
template <
class>
class MakePointer_>
69 class TensorForcedEvalOp :
public TensorBase<TensorForcedEvalOp<XprType, MakePointer_>, ReadOnlyAccessors>
72 typedef typename Eigen::internal::traits<TensorForcedEvalOp>::Scalar Scalar;
73 typedef typename Eigen::NumTraits<Scalar>::Real RealScalar;
74 typedef typename internal::remove_const<typename XprType::CoeffReturnType>::type CoeffReturnType;
75 typedef typename Eigen::internal::nested<TensorForcedEvalOp>::type Nested;
76 typedef typename Eigen::internal::traits<TensorForcedEvalOp>::StorageKind StorageKind;
77 typedef typename Eigen::internal::traits<TensorForcedEvalOp>::Index Index;
79 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorForcedEvalOp(
const XprType& expr)
83 const typename internal::remove_all<typename XprType::Nested>::type&
84 expression()
const {
return m_xpr; }
87 typename XprType::Nested m_xpr;
91 template<
typename ArgType,
typename Device,
template <
class>
class MakePointer_>
92 struct TensorEvaluator<const TensorForcedEvalOp<ArgType, MakePointer_>, Device>
94 typedef TensorForcedEvalOp<ArgType, MakePointer_> XprType;
95 typedef typename ArgType::Scalar Scalar;
96 typedef typename TensorEvaluator<ArgType, Device>::Dimensions Dimensions;
97 typedef typename XprType::Index Index;
98 typedef typename XprType::CoeffReturnType CoeffReturnType;
99 typedef typename PacketType<CoeffReturnType, Device>::type PacketReturnType;
100 static const int PacketSize = internal::unpacket_traits<PacketReturnType>::size;
104 PacketAccess = (PacketSize > 1),
105 Layout = TensorEvaluator<ArgType, Device>::Layout,
109 EIGEN_DEVICE_FUNC TensorEvaluator(
const XprType& op,
const Device& device)
111 : m_impl(op.expression(), device), m_op(op.expression()), m_device(device), m_buffer(NULL)
114 EIGEN_DEVICE_FUNC
const Dimensions& dimensions()
const {
return m_impl.dimensions(); }
116 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
bool evalSubExprsIfNeeded(CoeffReturnType*) {
117 const Index numValues = internal::array_prod(m_impl.dimensions());
118 m_buffer = (CoeffReturnType*)m_device.allocate(numValues *
sizeof(CoeffReturnType));
120 if (NumTraits<CoeffReturnType>::RequireInitialization) {
121 for (Index i = 0; i < numValues; ++i) {
122 new(m_buffer+i) CoeffReturnType();
125 typedef TensorEvalToOp< const typename internal::remove_const<ArgType>::type > EvalTo;
126 EvalTo evalToTmp(m_buffer, m_op);
127 const bool PacketAccess = internal::IsVectorizable<Device, const ArgType>::value;
128 internal::TensorExecutor<const EvalTo, typename internal::remove_const<Device>::type, PacketAccess>::run(evalToTmp, m_device);
131 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void cleanup() {
132 m_device.deallocate(m_buffer);
136 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index)
const 138 return m_buffer[index];
141 template<
int LoadMode>
142 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index)
const 144 return internal::ploadt<PacketReturnType, LoadMode>(m_buffer + index);
147 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost costPerCoeff(
bool vectorized)
const {
148 return TensorOpCost(
sizeof(CoeffReturnType), 0, 0, vectorized, PacketSize);
151 EIGEN_DEVICE_FUNC
typename MakePointer<Scalar>::Type data()
const {
return m_buffer; }
154 const TensorEvaluator<ArgType, Device>& impl() {
return m_impl; }
156 const Device& device()
const{
return m_device;}
158 TensorEvaluator<ArgType, Device> m_impl;
160 const Device& m_device;
161 typename MakePointer<CoeffReturnType>::Type m_buffer;
167 #endif // EIGEN_CXX11_TENSOR_TENSOR_FORCED_EVAL_H Namespace containing all symbols from the Eigen library.
Definition: AdolcForward:45