11#ifndef EIGEN_CWISE_BINARY_OP_H
12#define EIGEN_CWISE_BINARY_OP_H
37template<
typename BinaryOp,
typename Lhs,
typename Rhs>
38struct traits<CwiseBinaryOp<BinaryOp, Lhs, Rhs> >
42 typedef typename remove_all<Lhs>::type Ancestor;
43 typedef typename traits<Ancestor>::XprKind XprKind;
45 RowsAtCompileTime = traits<Ancestor>::RowsAtCompileTime,
46 ColsAtCompileTime = traits<Ancestor>::ColsAtCompileTime,
47 MaxRowsAtCompileTime = traits<Ancestor>::MaxRowsAtCompileTime,
48 MaxColsAtCompileTime = traits<Ancestor>::MaxColsAtCompileTime
53 typedef typename result_of<
59 typedef typename promote_storage_type<typename traits<Lhs>::StorageKind,
60 typename traits<Rhs>::StorageKind>::ret StorageKind;
61 typedef typename promote_index_type<typename traits<Lhs>::Index,
62 typename traits<Rhs>::Index>::type Index;
63 typedef typename Lhs::Nested LhsNested;
64 typedef typename Rhs::Nested RhsNested;
65 typedef typename remove_reference<LhsNested>::type _LhsNested;
66 typedef typename remove_reference<RhsNested>::type _RhsNested;
68 LhsCoeffReadCost = _LhsNested::CoeffReadCost,
69 RhsCoeffReadCost = _RhsNested::CoeffReadCost,
70 LhsFlags = _LhsNested::Flags,
71 RhsFlags = _RhsNested::Flags,
72 SameType = is_same<typename _LhsNested::Scalar,typename _RhsNested::Scalar>::value,
74 Flags0 = (int(LhsFlags) | int(RhsFlags)) & (
76 | (
int(LhsFlags) &
int(RhsFlags) &
79 | (functor_traits<BinaryOp>::PacketAccess && StorageOrdersAgree && SameType ?
PacketAccessBit : 0)
83 Flags = (Flags0 & ~RowMajorBit) | (LhsFlags &
RowMajorBit),
84 CoeffReadCost = LhsCoeffReadCost + RhsCoeffReadCost + functor_traits<BinaryOp>::Cost
96#define EIGEN_CHECK_BINARY_COMPATIBILIY(BINOP,LHS,RHS) \
97 EIGEN_STATIC_ASSERT((internal::functor_allows_mixing_real_and_complex<BINOP>::ret \
98 ? int(internal::is_same<typename NumTraits<LHS>::Real, typename NumTraits<RHS>::Real>::value) \
99 : int(internal::is_same<LHS, RHS>::value)), \
100 YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)
102template<
typename BinaryOp,
typename Lhs,
typename Rhs,
typename StorageKind>
103class CwiseBinaryOpImpl;
105template<
typename BinaryOp,
typename Lhs,
typename Rhs>
106class CwiseBinaryOp : internal::no_assignment_operator,
107 public CwiseBinaryOpImpl<
109 typename internal::promote_storage_type<typename internal::traits<Lhs>::StorageKind,
110 typename internal::traits<Rhs>::StorageKind>::ret>
114 typedef typename CwiseBinaryOpImpl<
116 typename internal::promote_storage_type<typename internal::traits<Lhs>::StorageKind,
117 typename internal::traits<Rhs>::StorageKind>::ret>::Base Base;
118 EIGEN_GENERIC_PUBLIC_INTERFACE(CwiseBinaryOp)
120 typedef typename internal::nested<Lhs>::type LhsNested;
121 typedef typename internal::nested<Rhs>::type RhsNested;
122 typedef typename internal::remove_reference<LhsNested>::type _LhsNested;
123 typedef typename internal::remove_reference<RhsNested>::type _RhsNested;
125 EIGEN_STRONG_INLINE CwiseBinaryOp(
const Lhs&
lhs,
const Rhs&
rhs,
const BinaryOp& func = BinaryOp())
126 : m_lhs(
lhs), m_rhs(
rhs), m_functor(func)
128 EIGEN_CHECK_BINARY_COMPATIBILIY(BinaryOp,
typename Lhs::Scalar,
typename Rhs::Scalar);
130 EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(Lhs, Rhs)
131 eigen_assert(
lhs.rows() ==
rhs.rows() &&
lhs.cols() ==
rhs.cols());
134 EIGEN_STRONG_INLINE Index rows()
const {
136 if (internal::traits<
typename internal::remove_all<LhsNested>::type>::RowsAtCompileTime==Dynamic)
141 EIGEN_STRONG_INLINE Index cols()
const {
143 if (internal::traits<
typename internal::remove_all<LhsNested>::type>::ColsAtCompileTime==Dynamic)
150 const _LhsNested&
lhs()
const {
return m_lhs; }
152 const _RhsNested&
rhs()
const {
return m_rhs; }
154 const BinaryOp&
functor()
const {
return m_functor; }
159 const BinaryOp m_functor;
162template<
typename BinaryOp,
typename Lhs,
typename Rhs>
163class CwiseBinaryOpImpl<BinaryOp, Lhs, Rhs,
Dense>
164 :
public internal::dense_xpr_base<CwiseBinaryOp<BinaryOp, Lhs, Rhs> >::type
169 typedef typename internal::dense_xpr_base<CwiseBinaryOp<BinaryOp, Lhs, Rhs> >::type Base;
170 EIGEN_DENSE_PUBLIC_INTERFACE( Derived )
172 EIGEN_STRONG_INLINE
const Scalar coeff(Index row, Index col)
const
174 return derived().
functor()(derived().lhs().coeff(row, col),
175 derived().rhs().coeff(row, col));
178 template<
int LoadMode>
179 EIGEN_STRONG_INLINE PacketScalar packet(Index row, Index col)
const
181 return derived().functor().packetOp(derived().lhs().
template packet<LoadMode>(row, col),
182 derived().rhs().
template packet<LoadMode>(row, col));
185 EIGEN_STRONG_INLINE
const Scalar coeff(Index index)
const
187 return derived().functor()(derived().lhs().coeff(index),
188 derived().rhs().coeff(index));
191 template<
int LoadMode>
192 EIGEN_STRONG_INLINE PacketScalar packet(Index index)
const
194 return derived().functor().packetOp(derived().lhs().
template packet<LoadMode>(index),
195 derived().rhs().
template packet<LoadMode>(index));
203template<
typename Derived>
204template<
typename OtherDerived>
205EIGEN_STRONG_INLINE Derived &
208 SelfCwiseBinaryOp<internal::scalar_difference_op<Scalar>, Derived, OtherDerived> tmp(derived());
209 tmp = other.derived();
217template<
typename Derived>
218template<
typename OtherDerived>
219EIGEN_STRONG_INLINE Derived &
222 SelfCwiseBinaryOp<internal::scalar_sum_op<Scalar>, Derived, OtherDerived> tmp(derived());
223 tmp = other.derived();
Generic expression where a coefficient-wise binary operator is applied to two expressions.
Definition CwiseBinaryOp.h:111
const _LhsNested & lhs() const
Definition CwiseBinaryOp.h:150
const BinaryOp & functor() const
Definition CwiseBinaryOp.h:154
const _RhsNested & rhs() const
Definition CwiseBinaryOp.h:152
Derived & operator-=(const MatrixBase< OtherDerived > &other)
Definition CwiseBinaryOp.h:206
Derived & operator+=(const MatrixBase< OtherDerived > &other)
Definition CwiseBinaryOp.h:220
const unsigned int RowMajorBit
Definition Constants.h:48
const unsigned int AlignedBit
Definition Constants.h:142
const unsigned int PacketAccessBit
Definition Constants.h:76
const unsigned int LinearAccessBit
Definition Constants.h:112
Definition Constants.h:421