10 #ifndef EIGEN_CXX11_TENSOR_TENSOR_CONVERSION_H 11 #define EIGEN_CXX11_TENSOR_TENSOR_CONVERSION_H 23 template<
typename TargetType,
typename XprType>
27 typedef TargetType Scalar;
30 typedef typename XprType::Nested Nested;
37 template<
typename TargetType,
typename XprType>
43 template<
typename TargetType,
typename XprType>
52 template <
typename TensorEvaluator,
typename SrcPacket,
typename TgtPacket,
int SrcCoeffRatio,
int TgtCoeffRatio>
54 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
58 template<
int LoadMode,
typename Index>
59 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TgtPacket packet(
Index index)
const {
60 return internal::pcast<SrcPacket, TgtPacket>(m_impl.template packet<LoadMode>(index));
68 template <
typename TensorEvaluator,
typename SrcPacket,
typename TgtPacket>
70 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
74 template<
int LoadMode,
typename Index>
75 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TgtPacket packet(
Index index)
const {
78 SrcPacket src1 = m_impl.template packet<LoadMode>(index);
79 SrcPacket src2 = m_impl.template packet<LoadMode>(index + SrcPacketSize);
80 TgtPacket result = internal::pcast<SrcPacket, TgtPacket>(src1, src2);
88 template <
typename TensorEvaluator,
typename SrcPacket,
typename TgtPacket>
90 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
94 template<
int LoadMode,
typename Index>
95 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TgtPacket packet(
Index index)
const {
98 SrcPacket src1 = m_impl.template packet<LoadMode>(index);
99 SrcPacket src2 = m_impl.template packet<LoadMode>(index + SrcPacketSize);
100 SrcPacket src3 = m_impl.template packet<LoadMode>(index + 2 * SrcPacketSize);
101 SrcPacket src4 = m_impl.template packet<LoadMode>(index + 3 * SrcPacketSize);
102 TgtPacket result = internal::pcast<SrcPacket, TgtPacket>(src1, src2, src3, src4);
110 template <
typename TensorEvaluator,
typename SrcPacket,
typename TgtPacket>
112 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
114 : m_impl(impl), m_maxIndex(impl.dimensions().TotalSize()) {}
116 template<
int LoadMode,
typename Index>
117 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TgtPacket packet(
Index index)
const {
122 if (m_impl.data() && (index + SrcPacketSize < m_maxIndex)) {
124 return internal::pcast<SrcPacket, TgtPacket>(m_impl.template packet<Unaligned>(index));
131 for (
int i = 0; i < TgtPacketSize; ++i) {
132 values[i] = converter(m_impl.coeff(index+i));
134 TgtPacket rslt = internal::pload<TgtPacket>(values);
141 const typename TensorEvaluator::Index m_maxIndex;
144 template<
typename TargetType,
typename XprType>
152 typedef Scalar CoeffReturnType;
160 expression()
const {
return m_xpr; }
163 typename XprType::Nested m_xpr;
167 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
bool run(Eval& impl, Scalar*) {
168 impl.evalSubExprsIfNeeded(NULL);
174 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
bool run(Eval& impl, Scalar* data) {
175 return impl.evalSubExprsIfNeeded(data);
181 template<
typename TargetType,
typename ArgType,
typename Device>
185 typedef typename XprType::Index
Index;
187 typedef TargetType Scalar;
188 typedef TargetType CoeffReturnType;
201 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
TensorEvaluator(
const XprType& op,
const Device& device)
202 : m_impl(op.expression(), device)
206 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Dimensions& dimensions()
const {
return m_impl.dimensions(); }
208 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
bool evalSubExprsIfNeeded(Scalar* data)
213 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void cleanup()
218 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index)
const 221 return converter(m_impl.coeff(index));
224 template<
int LoadMode>
225 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE PacketReturnType packet(Index index)
const 229 return PacketConv<LoadMode, Vectorizable>::run(m_impl, index);
233 costPerCoeff(
bool vectorized)
const {
234 const double cast_cost = TensorOpCost::CastCost<SrcType, TargetType>();
236 const double SrcCoeffRatio =
238 const double TgtCoeffRatio =
240 return m_impl.costPerCoeff(vectorized) * (SrcCoeffRatio / PacketSize) +
241 TensorOpCost(0, 0, TgtCoeffRatio * (cast_cost / PacketSize));
243 return m_impl.costPerCoeff(vectorized) +
TensorOpCost(0, 0, cast_cost);
247 EIGEN_DEVICE_FUNC Scalar* data()
const {
return NULL; }
250 template <
int LoadMode,
bool ActuallyVectorize>
255 for (
int i = 0; i < PacketSize; ++i) {
256 values[i] = converter(impl.coeff(index+i));
258 PacketReturnType rslt = internal::pload<PacketReturnType>(values);
263 template <
int LoadMode>
264 struct PacketConv<LoadMode, true> {
269 SrcCoeffRatio, TgtCoeffRatio> converter(impl);
270 return converter.template packet<LoadMode>(index);
279 #endif // EIGEN_CXX11_TENSOR_TENSOR_CONVERSION_H Definition: TensorCostModel.h:25
Definition: XprHelper.h:158
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:85
Definition: UnaryFunctors.h:152
A cost model used to limit the number of threads used for evaluating tensor expression.
Definition: TensorEvaluator.h:28
Holds information about the various numeric (i.e.
Definition: NumTraits.h:150
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33
Tensor conversion class.
Definition: TensorConversion.h:145
Definition: GenericPacketMath.h:122
The tensor base class.
Definition: TensorBase.h:827
Definition: PacketMath.h:48
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: TensorConversion.h:53
Definition: TensorConversion.h:166