11#ifndef EIGEN_CWISE_HETERO_BINARY_OP_H
12#define EIGEN_CWISE_HETERO_BINARY_OP_H
16 template<
typename BinaryOp,
typename LhsType,
typename RhsType>
17 class CwiseHeteroBinaryOp;
20 template<
typename BinaryOp,
typename Lhs,
typename Rhs>
21 struct traits<CwiseHeteroBinaryOp<BinaryOp, Lhs, Rhs> >
25 typedef typename remove_all<Lhs>::type Ancestor;
26 typedef typename traits<Ancestor>::XprKind XprKind;
28 RowsAtCompileTime = traits<Ancestor>::RowsAtCompileTime,
29 ColsAtCompileTime = traits<Ancestor>::ColsAtCompileTime,
30 MaxRowsAtCompileTime = traits<Ancestor>::MaxRowsAtCompileTime,
31 MaxColsAtCompileTime = traits<Ancestor>::MaxColsAtCompileTime
36 typedef typename result_of<
38 const typename Lhs::Scalar&,
39 const typename Rhs::Scalar&
42 typedef typename cwise_promote_storage_type<typename traits<Lhs>::StorageKind,
43 typename traits<Rhs>::StorageKind,
44 BinaryOp>::ret StorageKind;
45 typedef typename promote_index_type<typename traits<Lhs>::StorageIndex,
46 typename traits<Rhs>::StorageIndex>::type StorageIndex;
47 typedef typename Lhs::Nested LhsNested;
48 typedef typename Rhs::Nested RhsNested;
49 typedef typename remove_reference<LhsNested>::type _LhsNested;
50 typedef typename remove_reference<RhsNested>::type _RhsNested;
52 Flags = cwise_promote_storage_order<typename traits<Lhs>::StorageKind,
typename traits<Rhs>::StorageKind, _LhsNested::Flags& RowMajorBit, _RhsNested::Flags& RowMajorBit>::value
57 template<
typename BinaryOp,
typename Lhs,
typename Rhs,
typename StorageKind>
58 class CwiseHeteroBinaryOpImpl;
79 template<
typename BinaryOp,
typename LhsType,
typename RhsType>
81 public CwiseHeteroBinaryOpImpl<
82 BinaryOp, LhsType, RhsType,
83 typename internal::cwise_promote_storage_type<typename internal::traits<LhsType>::StorageKind,
84 typename internal::traits<RhsType>::StorageKind,
86 internal::no_assignment_operator
90 typedef typename internal::remove_all<BinaryOp>::type Functor;
91 typedef typename internal::remove_all<LhsType>::type Lhs;
92 typedef typename internal::remove_all<RhsType>::type Rhs;
94 typedef typename CwiseHeteroBinaryOpImpl<
95 BinaryOp, LhsType, RhsType,
96 typename internal::cwise_promote_storage_type<typename internal::traits<LhsType>::StorageKind,
97 typename internal::traits<Rhs>::StorageKind,
98 BinaryOp>::ret>::Base Base;
101 typedef typename internal::ref_selector<LhsType>::type LhsNested;
102 typedef typename internal::ref_selector<RhsType>::type RhsNested;
103 typedef typename internal::remove_reference<LhsNested>::type _LhsNested;
104 typedef typename internal::remove_reference<RhsNested>::type _RhsNested;
106#if EIGEN_COMP_MSVC && EIGEN_HAS_CXX11
112 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
114 : m_lhs(aLhs), m_rhs(aRhs), m_functor(func)
117 EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(Lhs, Rhs)
118 eigen_assert(aLhs.rows() == aRhs.rows() && aLhs.cols() == aRhs.cols());
121 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
constexpr
122 Index rows()
const EIGEN_NOEXCEPT {
124 return internal::traits<typename internal::remove_all<LhsNested>::type>::RowsAtCompileTime == Dynamic ? m_rhs.rows() : m_lhs.rows();
126 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
constexpr
127 Index cols()
const EIGEN_NOEXCEPT {
129 return internal::traits<typename internal::remove_all<LhsNested>::type>::ColsAtCompileTime == Dynamic ? m_rhs.cols() : m_lhs.cols();
133 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
134 const _LhsNested&
lhs()
const {
return m_lhs; }
136 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
137 const _RhsNested&
rhs()
const {
return m_rhs; }
139 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
140 const BinaryOp&
functor()
const {
return m_functor; }
145 const BinaryOp m_functor;
149 template<
typename BinaryOp,
typename Lhs,
typename Rhs,
typename StorageKind>
150 class CwiseHeteroBinaryOpImpl
151 :
public internal::generic_xpr_base<CwiseHeteroBinaryOp<BinaryOp, Lhs, Rhs> >::type
154 typedef typename internal::generic_xpr_base<CwiseHeteroBinaryOp<BinaryOp, Lhs, Rhs> >::type Base;
162 template<
typename BinaryOp,
typename Lhs,
typename Rhs>
163 struct evaluator<CwiseHeteroBinaryOp<BinaryOp, Lhs, Rhs> >
164 :
public binary_evaluator<CwiseHeteroBinaryOp<BinaryOp, Lhs, Rhs> >
166 typedef CwiseHeteroBinaryOp<BinaryOp, Lhs, Rhs> XprType;
167 typedef binary_evaluator<CwiseHeteroBinaryOp<BinaryOp, Lhs, Rhs> > Base;
169 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
170 explicit evaluator(
const XprType& xpr) : Base(xpr) {}
173 template<
typename BinaryOp,
typename Lhs,
typename Rhs>
174 struct binary_evaluator<CwiseHeteroBinaryOp<BinaryOp, Lhs, Rhs>, IndexBased, IndexBased>
175 : evaluator_base<CwiseHeteroBinaryOp<BinaryOp, Lhs, Rhs> >
177 typedef CwiseHeteroBinaryOp<BinaryOp, Lhs, Rhs> XprType;
178 using LhsScalar =
typename Lhs::Scalar;
179 using RhsScalar =
typename Rhs::Scalar;
182 CoeffReadCost = int(evaluator<Lhs>::CoeffReadCost) + int(evaluator<Rhs>::CoeffReadCost) + int(functor_traits<BinaryOp>::Cost),
184 LhsFlags = evaluator<Lhs>::Flags,
185 RhsFlags = evaluator<Rhs>::Flags,
186 SameType = is_same<typename Lhs::Scalar, typename Rhs::Scalar>::value,
187 StorageOrdersAgree = (int(LhsFlags) & RowMajorBit) == (
int(RhsFlags) & RowMajorBit),
188 Flags0 = (
int(LhsFlags) | int(RhsFlags)) & (
190 | (
int(LhsFlags) &
int(RhsFlags) &
191 ((StorageOrdersAgree ? LinearAccessBit : 0)
192 | (functor_traits<BinaryOp>::PacketAccess && StorageOrdersAgree ? PacketAccessBit : 0)
196 Flags = (Flags0 & ~RowMajorBit) | (LhsFlags & RowMajorBit),
197 Alignment = EIGEN_PLAIN_ENUM_MIN(evaluator<Lhs>::Alignment, evaluator<Rhs>::Alignment)
200 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
201 explicit binary_evaluator(
const XprType& xpr) : m_d(xpr)
203 EIGEN_INTERNAL_CHECK_COST_VALUE(functor_traits<BinaryOp>::Cost);
204 EIGEN_INTERNAL_CHECK_COST_VALUE(CoeffReadCost);
207 typedef typename XprType::CoeffReturnType CoeffReturnType;
209 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
210 CoeffReturnType coeff(Index row, Index col)
const
212 return m_d.func()(m_d.lhsImpl.coeff(row, col), m_d.rhsImpl.coeff(row, col));
215 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
216 CoeffReturnType coeff(Index index)
const
218 return m_d.func()(m_d.lhsImpl.coeff(index), m_d.rhsImpl.coeff(index));
221 template<
int LoadMode,
typename PacketType>
223 PacketType packet(Index row, Index col)
const
225 using IPacketType =
decltype(reinterpret_to_float(std::declval<PacketType>()));
226 using FPacketType =
decltype(reinterpret_to_float(std::declval<PacketType>()));
227 using RhsPacket =
typename std::conditional<std::is_same<RhsScalar, float>::value, FPacketType, IPacketType>::type;
229 return m_d.func().packetOp(m_d.lhsImpl.template packet<LoadMode, PacketType>(row, col),
230 m_d.rhsImpl.template packet<LoadMode, RhsPacket>(row, col));
233 template<
int LoadMode,
typename PacketType>
235 PacketType packet(Index index)
const
237 using IPacketType =
decltype(reinterpret_to_float(std::declval<PacketType>()));
238 using FPacketType =
decltype(reinterpret_to_float(std::declval<PacketType>()));
239 using RhsPacket =
typename std::conditional<std::is_same<RhsScalar, float>::value, FPacketType, IPacketType>::type;
241 return m_d.func().packetOp(m_d.lhsImpl.template packet<LoadMode, PacketType>(index),
242 m_d.rhsImpl.template packet<LoadMode, RhsPacket>(index));
250 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
251 Data(
const XprType& xpr) : op(xpr.functor()), lhsImpl(xpr.lhs()), rhsImpl(xpr.rhs()) {}
252 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
253 const BinaryOp& func()
const {
return op; }
255 evaluator<Lhs> lhsImpl;
256 evaluator<Rhs> rhsImpl;
Generic expression where a coefficient-wise binary operator is applied to two expressions.
Definition: CwiseHeteroBinaryOp.h:87
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const BinaryOp & functor() const
Definition: CwiseHeteroBinaryOp.h:140
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const _RhsNested & rhs() const
Definition: CwiseHeteroBinaryOp.h:137
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const _LhsNested & lhs() const
Definition: CwiseHeteroBinaryOp.h:134