10 #ifndef EIGEN_CXX11_TENSOR_TENSOR_CUSTOM_OP_H 11 #define EIGEN_CXX11_TENSOR_TENSOR_CUSTOM_OP_H 23 template<
typename CustomUnaryFunc,
typename XprType>
29 typedef typename XprType::Nested
Nested;
35 template<
typename CustomUnaryFunc,
typename XprType>
41 template<
typename CustomUnaryFunc,
typename XprType>
51 template<
typename CustomUnaryFunc,
typename XprType>
63 : m_expr(expr), m_func(func) {}
66 const CustomUnaryFunc&
func()
const {
return m_func; }
79 template<
typename CustomUnaryFunc,
typename XprType,
typename Device>
101 : m_op(op), m_device(device), m_result(
NULL)
113 m_result =
static_cast<CoeffReturnType*
>(
114 m_device.allocate(
dimensions().TotalSize() *
sizeof(Scalar)));
121 if (m_result !=
NULL) {
122 m_device.deallocate(m_result);
128 return m_result[index];
131 template<
int LoadMode>
132 EIGEN_DEVICE_FUNC PacketReturnType
packet(Index index)
const {
133 return internal::ploadt<PacketReturnType, LoadMode>(m_result + index);
138 return TensorOpCost(
sizeof(CoeffReturnType), 0, 0, vectorized, PacketSize);
141 EIGEN_DEVICE_FUNC CoeffReturnType*
data()
const {
return m_result; }
147 m_op.func().eval(m_op.expression(),
result, m_device);
166 template<
typename CustomBinaryFunc,
typename LhsXprType,
typename RhsXprType>
185 template<
typename CustomBinaryFunc,
typename LhsXprType,
typename RhsXprType>
191 template<
typename CustomBinaryFunc,
typename LhsXprType,
typename RhsXprType>
201 template<
typename CustomBinaryFunc,
typename LhsXprType,
typename RhsXprType>
214 : m_lhs_xpr(lhs), m_rhs_xpr(rhs), m_func(func) {}
217 const CustomBinaryFunc&
func()
const {
return m_func; }
235 template<
typename CustomBinaryFunc,
typename LhsXprType,
typename RhsXprType,
typename Device>
257 : m_op(op), m_device(device), m_result(
NULL)
269 m_result =
static_cast<Scalar *
>(m_device.allocate(
dimensions().TotalSize() *
sizeof(Scalar)));
276 if (m_result !=
NULL) {
277 m_device.deallocate(m_result);
283 return m_result[index];
286 template<
int LoadMode>
287 EIGEN_DEVICE_FUNC PacketReturnType
packet(Index index)
const {
288 return internal::ploadt<PacketReturnType, LoadMode>(m_result + index);
293 return TensorOpCost(
sizeof(CoeffReturnType), 0, 0, vectorized, PacketSize);
296 EIGEN_DEVICE_FUNC CoeffReturnType*
data()
const {
return m_result; }
301 m_op.func().eval(m_op.lhsExpression(), m_op.rhsExpression(),
result, m_device);
313 #endif // EIGEN_CXX11_TENSOR_TENSOR_CUSTOM_OP_H
EIGEN_DEVICE_FUNC void evalTo(Scalar *data)
remove_reference< RhsNested >::type _RhsNested
LhsXprType::Nested LhsNested
internal::traits< XprType >::Index Index
DSizes< Index, NumDims > Dimensions
#define EIGEN_STRONG_INLINE
PacketType< CoeffReturnType, Device >::type PacketReturnType
internal::traits< TensorCustomBinaryOp >::StorageKind StorageKind
internal::nested< TensorCustomBinaryOp >::type Nested
internal::traits< TensorCustomBinaryOp >::Scalar Scalar
TensorCustomBinaryOp< CustomBinaryFunc, LhsXprType, RhsXprType > XprType
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorCustomUnaryOp(const XprType &expr, const CustomUnaryFunc &func)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(CoeffReturnType *data)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost costPerCoeff(bool vectorized) const
EIGEN_DEVICE_FUNC CoeffReturnType * data() const
internal::remove_const< typename ArgType::Scalar >::type Scalar
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorCustomBinaryOp(const LhsXprType &lhs, const RhsXprType &rhs, const CustomBinaryFunc &func)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions & dimensions() const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const
Namespace containing all symbols from the Eigen library.
A cost model used to limit the number of threads used for evaluating tensor expression.
TensorCustomUnaryOp< CustomUnaryFunc, XprType > type
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions & dimensions() const
EIGEN_DEVICE_FUNC const internal::remove_all< typename RhsXprType::Nested >::type & rhsExpression() const
RhsXprType::Nested m_rhs_xpr
vector< size_t > dimensions(L.begin(), L.end())
XprType::CoeffReturnType CoeffReturnType
internal::traits< TensorCustomBinaryOp >::CoeffReturnType CoeffReturnType
EIGEN_DEVICE_FUNC PacketReturnType packet(Index index) const
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorOpCost costPerCoeff(bool vectorized) const
remove_reference< Nested >::type _Nested
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void cleanup()
const CustomUnaryFunc m_func
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index) const
XprType::StorageKind StorageKind
TensorCustomBinaryOp< CustomBinaryFunc, LhsXprType, RhsXprType > type
A tensor expression mapping an existing array of data.
TensorCustomUnaryOp< CustomUnaryFunc, XprType > ArgType
const CustomBinaryFunc m_func
EIGEN_DEVICE_FUNC const internal::remove_all< typename XprType::Nested >::type & expression() const
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void cleanup()
remove_reference< LhsNested >::type _LhsNested
internal::traits< ArgType >::Index Index
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvaluator(const XprType &op, const Device &device)
EIGEN_DEVICE_FUNC const CustomUnaryFunc & func() const
CoeffReturnType * m_result
internal::traits< TensorCustomBinaryOp >::Index Index
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE bool evalSubExprsIfNeeded(CoeffReturnType *data)
Eigen::NumTraits< Scalar >::Real RealScalar
RhsXprType::Nested RhsNested
internal::promote_storage_type< typename LhsXprType::CoeffReturnType, typename RhsXprType::CoeffReturnType >::ret CoeffReturnType
PacketType< CoeffReturnType, Device >::type PacketReturnType
LhsXprType::Nested m_lhs_xpr
const TensorCustomUnaryOp< CustomUnaryFunc, XprType > & type
internal::promote_storage_type< typename LhsXprType::Scalar, typename RhsXprType::Scalar >::ret Scalar
const TensorCustomBinaryOp< CustomBinaryFunc, LhsXprType, RhsXprType > & type
internal::nested< TensorCustomUnaryOp >::type Nested
internal::remove_const< typename XprType::CoeffReturnType >::type CoeffReturnType
EIGEN_DEVICE_FUNC CoeffReturnType * data() const
EIGEN_DEVICE_FUNC const CustomBinaryFunc & func() const
internal::traits< TensorCustomUnaryOp >::StorageKind StorageKind
EIGEN_DEVICE_FUNC void evalTo(Scalar *data)
EIGEN_DEVICE_FUNC const internal::remove_all< typename LhsXprType::Nested >::type & lhsExpression() const
CoeffReturnType * m_result
Eigen::NumTraits< Scalar >::Real RealScalar
internal::remove_const< typename XprType::CoeffReturnType >::type CoeffReturnType
internal::traits< TensorCustomUnaryOp >::Scalar Scalar
promote_index_type< typename traits< LhsXprType >::Index, typename traits< RhsXprType >::Index >::type Index
EIGEN_DEVICE_FUNC PacketReturnType packet(Index index) const
DSizes< Index, NumDims > Dimensions
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorEvaluator(const ArgType &op, const Device &device)
promote_storage_type< typename traits< LhsXprType >::StorageKind, typename traits< RhsXprType >::StorageKind >::ret StorageKind
internal::traits< TensorCustomUnaryOp >::Index Index