10 #ifndef EIGEN_DEVICEWRAPPER_H 11 #define EIGEN_DEVICEWRAPPER_H 14 template <
typename Derived,
typename Device>
15 struct DeviceWrapper {
16 using Base = EigenBase<internal::remove_all_t<Derived>>;
17 using Scalar =
typename Derived::Scalar;
19 EIGEN_DEVICE_FUNC DeviceWrapper(Base& xpr, Device& device) : m_xpr(xpr.derived()), m_device(device) {}
20 EIGEN_DEVICE_FUNC DeviceWrapper(
const Base& xpr, Device& device) : m_xpr(xpr.derived()), m_device(device) {}
22 template <
typename OtherDerived>
23 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator=(
const EigenBase<OtherDerived>& other) {
24 using AssignOp = internal::assign_op<Scalar, typename OtherDerived::Scalar>;
25 internal::call_assignment(*
this, other.derived(), AssignOp());
28 template <
typename OtherDerived>
29 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator+=(
const EigenBase<OtherDerived>& other) {
30 using AddAssignOp = internal::add_assign_op<Scalar, typename OtherDerived::Scalar>;
31 internal::call_assignment(*
this, other.derived(), AddAssignOp());
34 template <
typename OtherDerived>
35 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& operator-=(
const EigenBase<OtherDerived>& other) {
36 using SubAssignOp = internal::sub_assign_op<Scalar, typename OtherDerived::Scalar>;
37 internal::call_assignment(*
this, other.derived(), SubAssignOp());
41 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Derived& derived() {
return m_xpr; }
42 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Device& device() {
return m_device; }
43 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE NoAlias<DeviceWrapper, EigenBase> noalias() {
44 return NoAlias<DeviceWrapper, EigenBase>(*this);
54 template <
typename DstXprType,
typename SrcXprType,
typename Functor,
typename Device,
55 typename Kind =
typename AssignmentKind<typename evaluator_traits<DstXprType>::Shape,
56 typename evaluator_traits<SrcXprType>::Shape>::Kind,
57 typename EnableIf =
void>
58 struct AssignmentWithDevice;
61 template <
typename DstXprType,
typename Lhs,
typename Rhs,
int Options,
typename Functor,
typename Device,
63 struct AssignmentWithDevice<DstXprType, Product<Lhs, Rhs, Options>, Functor, Device, Dense2Dense, Weak> {
64 using SrcXprType = Product<Lhs, Rhs, Options>;
65 using Base = Assignment<DstXprType, SrcXprType, Functor>;
66 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void run(DstXprType& dst,
const SrcXprType& src,
const Functor& func,
68 Base::run(dst, src, func);
73 template <
typename DstXprType,
typename SrcXprType,
typename Functor,
typename Device,
typename Weak>
74 struct AssignmentWithDevice<DstXprType, SrcXprType, Functor, Device, Dense2Dense, Weak> {
75 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
void run(DstXprType& dst,
const SrcXprType& src,
const Functor& func,
77 #ifndef EIGEN_NO_DEBUG 78 internal::check_for_aliasing(dst, src);
81 call_dense_assignment_loop(dst, src, func, device);
86 template <
typename Kernel,
typename Device,
int Traversal = Kernel::AssignmentTraits::Traversal,
87 int Unrolling = Kernel::AssignmentTraits::Unrolling>
88 struct dense_assignment_loop_with_device {
89 using Base = dense_assignment_loop<Kernel, Traversal, Unrolling>;
90 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr
void run(Kernel& kernel, Device&) { Base::run(kernel); }
94 template <
typename Dst,
typename Src,
typename Func,
typename Device>
95 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr
void call_assignment_no_alias(DeviceWrapper<Dst, Device> dst,
96 const Src& src,
const Func& func) {
98 NeedToTranspose = ((int(Dst::RowsAtCompileTime) == 1 && int(Src::ColsAtCompileTime) == 1) ||
99 (
int(Dst::ColsAtCompileTime) == 1 && int(Src::RowsAtCompileTime) == 1)) &&
100 int(Dst::SizeAtCompileTime) != 1
103 using ActualDstTypeCleaned = std::conditional_t<NeedToTranspose, Transpose<Dst>, Dst>;
104 using ActualDstType = std::conditional_t<NeedToTranspose, Transpose<Dst>, Dst&>;
105 ActualDstType actualDst(dst.derived());
108 EIGEN_STATIC_ASSERT_LVALUE(Dst)
109 EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(ActualDstTypeCleaned, Src)
110 EIGEN_CHECK_BINARY_COMPATIBILIY(Func,
typename ActualDstTypeCleaned::Scalar,
typename Src::Scalar);
113 AssignmentWithDevice<ActualDstTypeCleaned, Src, Func, Device>::run(actualDst, src, func, dst.device());
117 template <
typename DstXprType,
typename SrcXprType,
typename Functor,
typename Device>
118 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE constexpr
void call_dense_assignment_loop(DstXprType& dst,
const SrcXprType& src,
119 const Functor& func, Device& device) {
120 using DstEvaluatorType = evaluator<DstXprType>;
121 using SrcEvaluatorType = evaluator<SrcXprType>;
123 SrcEvaluatorType srcEvaluator(src);
127 resize_if_allowed(dst, src, func);
129 DstEvaluatorType dstEvaluator(dst);
131 using Kernel = generic_dense_assignment_kernel<DstEvaluatorType, SrcEvaluatorType, Functor>;
133 Kernel kernel(dstEvaluator, srcEvaluator, func, dst.const_cast_derived());
135 dense_assignment_loop_with_device<Kernel, Device>::run(kernel, device);
140 template <
typename Derived>
141 template <
typename Device>
142 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE DeviceWrapper<Derived, Device> EigenBase<Derived>::device(Device& device) {
143 return DeviceWrapper<Derived, Device>(derived(), device);
146 template <
typename Derived>
147 template <
typename Device>
148 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE DeviceWrapper<const Derived, Device> EigenBase<Derived>::device(
149 Device& device)
const {
150 return DeviceWrapper<const Derived, Device>(derived(), device);
Namespace containing all symbols from the Eigen library.
Definition: B01_Experimental.dox:1