10 #ifndef EIGEN_CXX11_TENSOR_TENSOR_CUSTOM_OP_H 11 #define EIGEN_CXX11_TENSOR_TENSOR_CUSTOM_OP_H 23 template<
typename CustomUnaryFunc,
typename XprType>
24 struct traits<TensorCustomUnaryOp<CustomUnaryFunc, XprType> >
26 typedef typename XprType::Scalar Scalar;
27 typedef typename packet_traits<Scalar>::type Packet;
28 typedef typename XprType::StorageKind StorageKind;
29 typedef typename XprType::Index Index;
30 typedef typename XprType::Nested Nested;
31 typedef typename remove_reference<Nested>::type _Nested;
32 static const int NumDimensions = traits<XprType>::NumDimensions;
33 static const int Layout = traits<XprType>::Layout;
36 template<
typename CustomUnaryFunc,
typename XprType>
37 struct eval<TensorCustomUnaryOp<CustomUnaryFunc, XprType>,
Eigen::Dense>
39 typedef const TensorCustomUnaryOp<CustomUnaryFunc, XprType>& type;
42 template<
typename CustomUnaryFunc,
typename XprType>
43 struct nested<TensorCustomUnaryOp<CustomUnaryFunc, XprType> >
45 typedef TensorCustomUnaryOp<CustomUnaryFunc, XprType> type;
52 template<
typename CustomUnaryFunc,
typename XprType>
56 typedef typename internal::traits<TensorCustomUnaryOp>::Scalar Scalar;
57 typedef typename internal::traits<TensorCustomUnaryOp>::Packet Packet;
58 typedef typename Eigen::NumTraits<Scalar>::Real RealScalar;
59 typedef typename XprType::CoeffReturnType CoeffReturnType;
60 typedef typename XprType::PacketReturnType PacketReturnType;
61 typedef typename internal::nested<TensorCustomUnaryOp>::type Nested;
62 typedef typename internal::traits<TensorCustomUnaryOp>::StorageKind StorageKind;
63 typedef typename internal::traits<TensorCustomUnaryOp>::Index Index;
65 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
TensorCustomUnaryOp(
const XprType& expr,
const CustomUnaryFunc& func)
66 : m_expr(expr), m_func(func) {}
69 const CustomUnaryFunc& func()
const {
return m_func; }
72 const typename internal::remove_all<typename XprType::Nested>::type&
73 expression()
const {
return m_expr; }
76 typename XprType::Nested m_expr;
77 const CustomUnaryFunc m_func;
82 template<
typename CustomUnaryFunc,
typename XprType,
typename Device>
83 struct TensorEvaluator<const TensorCustomUnaryOp<CustomUnaryFunc, XprType>, Device>
86 typedef typename internal::traits<ArgType>::Index Index;
87 static const int NumDims = internal::traits<ArgType>::NumDimensions;
88 typedef DSizes<Index, NumDims> Dimensions;
90 typename internal::remove_const<typename ArgType::Scalar>::type Scalar;
94 PacketAccess = (internal::packet_traits<Scalar>::size > 1),
100 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
TensorEvaluator(
const ArgType& op,
const Device& device)
101 : m_op(op), m_device(device), m_result(NULL)
103 m_dimensions = op.func().dimensions(op.expression());
106 typedef typename internal::remove_const<typename XprType::CoeffReturnType>::type CoeffReturnType;
107 typedef typename XprType::PacketReturnType PacketReturnType;
109 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Dimensions& dimensions()
const {
return m_dimensions; }
111 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
bool evalSubExprsIfNeeded(CoeffReturnType* data) {
116 m_result =
static_cast<CoeffReturnType*
>(
117 m_device.allocate(dimensions().TotalSize() *
sizeof(Scalar)));
123 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void cleanup() {
124 if (m_result != NULL) {
125 m_device.deallocate(m_result);
130 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index)
const {
131 return m_result[index];
134 template<
int LoadMode>
135 EIGEN_DEVICE_FUNC PacketReturnType packet(Index index)
const {
136 return internal::ploadt<PacketReturnType, LoadMode>(m_result + index);
139 EIGEN_DEVICE_FUNC CoeffReturnType* data()
const {
return m_result; }
142 EIGEN_DEVICE_FUNC
void evalTo(Scalar* data) {
145 m_op.func().eval(m_op.expression(), result, m_device);
148 Dimensions m_dimensions;
150 const Device& m_device;
151 CoeffReturnType* m_result;
164 template<
typename CustomBinaryFunc,
typename LhsXprType,
typename RhsXprType>
165 struct traits<TensorCustomBinaryOp<CustomBinaryFunc, LhsXprType, RhsXprType> >
167 typedef typename internal::promote_storage_type<
typename LhsXprType::Scalar,
168 typename RhsXprType::Scalar>::ret Scalar;
169 typedef typename packet_traits<Scalar>::type Packet;
170 typedef typename internal::promote_storage_type<
typename LhsXprType::CoeffReturnType,
171 typename RhsXprType::CoeffReturnType>::ret CoeffReturnType;
172 typedef typename internal::promote_storage_type<
typename LhsXprType::PacketReturnType,
173 typename RhsXprType::PacketReturnType>::ret PacketReturnType;
174 typedef typename promote_storage_type<typename traits<LhsXprType>::StorageKind,
175 typename traits<RhsXprType>::StorageKind>::ret StorageKind;
176 typedef typename promote_index_type<typename traits<LhsXprType>::Index,
177 typename traits<RhsXprType>::Index>::type Index;
178 typedef typename LhsXprType::Nested LhsNested;
179 typedef typename RhsXprType::Nested RhsNested;
180 typedef typename remove_reference<LhsNested>::type _LhsNested;
181 typedef typename remove_reference<RhsNested>::type _RhsNested;
182 static const int NumDimensions = traits<LhsXprType>::NumDimensions;
183 static const int Layout = traits<LhsXprType>::Layout;
186 template<
typename CustomBinaryFunc,
typename LhsXprType,
typename RhsXprType>
187 struct eval<TensorCustomBinaryOp<CustomBinaryFunc, LhsXprType, RhsXprType>, Eigen::Dense>
192 template<
typename CustomBinaryFunc,
typename LhsXprType,
typename RhsXprType>
193 struct nested<TensorCustomBinaryOp<CustomBinaryFunc, LhsXprType, RhsXprType> >
202 template<
typename CustomBinaryFunc,
typename LhsXprType,
typename RhsXprType>
206 typedef typename internal::traits<TensorCustomBinaryOp>::Scalar Scalar;
207 typedef typename internal::traits<TensorCustomBinaryOp>::Packet Packet;
208 typedef typename Eigen::NumTraits<Scalar>::Real RealScalar;
209 typedef typename internal::traits<TensorCustomBinaryOp>::CoeffReturnType CoeffReturnType;
210 typedef typename internal::traits<TensorCustomBinaryOp>::PacketReturnType PacketReturnType;
211 typedef typename internal::nested<TensorCustomBinaryOp>::type Nested;
212 typedef typename internal::traits<TensorCustomBinaryOp>::StorageKind StorageKind;
213 typedef typename internal::traits<TensorCustomBinaryOp>::Index Index;
215 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
TensorCustomBinaryOp(
const LhsXprType& lhs,
const RhsXprType& rhs,
const CustomBinaryFunc& func)
217 : m_lhs_xpr(lhs), m_rhs_xpr(rhs), m_func(func) {}
220 const CustomBinaryFunc& func()
const {
return m_func; }
223 const typename internal::remove_all<typename LhsXprType::Nested>::type&
224 lhsExpression()
const {
return m_lhs_xpr; }
227 const typename internal::remove_all<typename RhsXprType::Nested>::type&
228 rhsExpression()
const {
return m_rhs_xpr; }
231 typename LhsXprType::Nested m_lhs_xpr;
232 typename RhsXprType::Nested m_rhs_xpr;
233 const CustomBinaryFunc m_func;
238 template<
typename CustomBinaryFunc,
typename LhsXprType,
typename RhsXprType,
typename Device>
239 struct TensorEvaluator<const TensorCustomBinaryOp<CustomBinaryFunc, LhsXprType, RhsXprType>, Device>
242 typedef typename internal::traits<XprType>::Index Index;
243 static const int NumDims = internal::traits<XprType>::NumDimensions;
244 typedef DSizes<Index, NumDims> Dimensions;
245 typedef typename XprType::Scalar Scalar;
249 PacketAccess = (internal::packet_traits<Scalar>::size > 1),
255 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
TensorEvaluator(
const XprType& op,
const Device& device)
256 : m_op(op), m_device(device), m_result(NULL)
258 m_dimensions = op.func().dimensions(op.lhsExpression(), op.rhsExpression());
261 typedef typename internal::remove_const<typename XprType::CoeffReturnType>::type CoeffReturnType;
262 typedef typename XprType::PacketReturnType PacketReturnType;
264 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
const Dimensions& dimensions()
const {
return m_dimensions; }
266 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
bool evalSubExprsIfNeeded(CoeffReturnType* data) {
271 m_result =
static_cast<Scalar *
>(m_device.allocate(dimensions().TotalSize() *
sizeof(Scalar)));
277 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void cleanup() {
278 if (m_result != NULL) {
279 m_device.deallocate(m_result);
284 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE CoeffReturnType coeff(Index index)
const {
285 return m_result[index];
288 template<
int LoadMode>
289 EIGEN_DEVICE_FUNC PacketReturnType packet(Index index)
const {
290 return internal::ploadt<PacketReturnType, LoadMode>(m_result + index);
293 EIGEN_DEVICE_FUNC CoeffReturnType* data()
const {
return m_result; }
296 EIGEN_DEVICE_FUNC
void evalTo(Scalar* data) {
298 m_op.func().eval(m_op.lhsExpression(), m_op.rhsExpression(), result, m_device);
301 Dimensions m_dimensions;
303 const Device& m_device;
304 CoeffReturnType* m_result;
310 #endif // EIGEN_CXX11_TENSOR_TENSOR_CUSTOM_OP_H Tensor custom class.
Definition: TensorCustomOp.h:53
Tensor custom class.
Definition: TensorCustomOp.h:203
Namespace containing all symbols from the Eigen library.
Definition: CXX11Meta.h:13
The tensor evaluator classes.
Definition: TensorEvaluator.h:28
A tensor expression mapping an existing array of data.
Definition: TensorForwardDeclarations.h:17
The tensor base class.
Definition: TensorForwardDeclarations.h:19