10 #ifndef EIGEN_SELFCWISEBINARYOP_H
11 #define EIGEN_SELFCWISEBINARYOP_H
31 template<
typename BinaryOp,
typename Lhs,
typename Rhs>
32 struct traits<SelfCwiseBinaryOp<BinaryOp,Lhs,Rhs> >
33 : traits<CwiseBinaryOp<BinaryOp,Lhs,Rhs> >
39 OuterStrideAtCompileTime = Lhs::OuterStrideAtCompileTime,
40 InnerStrideAtCompileTime = Lhs::InnerStrideAtCompileTime
45 template<
typename BinaryOp,
typename Lhs,
typename Rhs>
class SelfCwiseBinaryOp
46 :
public internal::dense_xpr_base< SelfCwiseBinaryOp<BinaryOp, Lhs, Rhs> >::type
50 typedef typename internal::dense_xpr_base<SelfCwiseBinaryOp>::type Base;
51 EIGEN_DENSE_PUBLIC_INTERFACE(SelfCwiseBinaryOp)
53 typedef typename internal::packet_traits<Scalar>::type Packet;
55 inline SelfCwiseBinaryOp(Lhs& xpr, const BinaryOp& func = BinaryOp()) : m_matrix(xpr), m_functor(func) {}
57 inline Index rows()
const {
return m_matrix.rows(); }
58 inline Index cols()
const {
return m_matrix.cols(); }
59 inline Index outerStride()
const {
return m_matrix.outerStride(); }
60 inline Index innerStride()
const {
return m_matrix.innerStride(); }
61 inline const Scalar* data()
const {
return m_matrix.data(); }
65 inline Scalar& coeffRef(Index row, Index col)
67 EIGEN_STATIC_ASSERT_LVALUE(Lhs)
68 return m_matrix.const_cast_derived().coeffRef(row, col);
70 inline const Scalar& coeffRef(Index row, Index col)
const
72 return m_matrix.coeffRef(row, col);
77 inline Scalar& coeffRef(Index index)
79 EIGEN_STATIC_ASSERT_LVALUE(Lhs)
80 return m_matrix.const_cast_derived().coeffRef(index);
82 inline const Scalar& coeffRef(Index index)
const
84 return m_matrix.const_cast_derived().coeffRef(index);
87 template<
typename OtherDerived>
88 void copyCoeff(Index row, Index col,
const DenseBase<OtherDerived>& other)
90 OtherDerived& _other = other.const_cast_derived();
91 eigen_internal_assert(row >= 0 && row < rows()
92 && col >= 0 && col < cols());
93 Scalar& tmp = m_matrix.coeffRef(row,col);
94 tmp = m_functor(tmp, _other.coeff(row,col));
97 template<
typename OtherDerived>
98 void copyCoeff(Index index,
const DenseBase<OtherDerived>& other)
100 OtherDerived& _other = other.const_cast_derived();
101 eigen_internal_assert(index >= 0 && index < m_matrix.size());
102 Scalar& tmp = m_matrix.coeffRef(index);
103 tmp = m_functor(tmp, _other.coeff(index));
106 template<
typename OtherDerived,
int StoreMode,
int LoadMode>
107 void copyPacket(Index row, Index col,
const DenseBase<OtherDerived>& other)
109 OtherDerived& _other = other.const_cast_derived();
110 eigen_internal_assert(row >= 0 && row < rows()
111 && col >= 0 && col < cols());
112 m_matrix.template writePacket<StoreMode>(row, col,
113 m_functor.packetOp(m_matrix.template packet<StoreMode>(row, col),_other.template packet<LoadMode>(row, col)) );
116 template<
typename OtherDerived,
int StoreMode,
int LoadMode>
117 void copyPacket(Index index,
const DenseBase<OtherDerived>& other)
119 OtherDerived& _other = other.const_cast_derived();
120 eigen_internal_assert(index >= 0 && index < m_matrix.size());
121 m_matrix.template writePacket<StoreMode>(index,
122 m_functor.packetOp(m_matrix.template packet<StoreMode>(index),_other.template packet<LoadMode>(index)) );
127 template<
typename RhsDerived>
128 EIGEN_STRONG_INLINE SelfCwiseBinaryOp& lazyAssign(
const DenseBase<RhsDerived>& rhs)
130 EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(Lhs,RhsDerived)
131 EIGEN_CHECK_BINARY_COMPATIBILIY(BinaryOp,typename Lhs::Scalar,typename RhsDerived::Scalar);
133 #ifdef EIGEN_DEBUG_ASSIGN
134 internal::assign_traits<SelfCwiseBinaryOp, RhsDerived>::debug();
136 eigen_assert(rows() == rhs.rows() && cols() == rhs.cols());
137 internal::assign_impl<SelfCwiseBinaryOp, RhsDerived>::run(*
this,rhs.derived());
138 #ifndef EIGEN_NO_DEBUG
139 this->checkTransposeAliasing(rhs.derived());
147 SelfCwiseBinaryOp& operator=(
const Rhs& _rhs)
149 typename internal::nested<Rhs>::type rhs(_rhs);
150 return Base::operator=(rhs);
153 Lhs& expression()
const
158 const BinaryOp& functor()
const
165 const BinaryOp& m_functor;
168 SelfCwiseBinaryOp& operator=(
const SelfCwiseBinaryOp&);
171 template<
typename Derived>
172 inline Derived& DenseBase<Derived>::operator*=(
const Scalar& other)
174 typedef typename Derived::PlainObject PlainObject;
175 SelfCwiseBinaryOp<internal::scalar_product_op<Scalar>, Derived,
typename PlainObject::ConstantReturnType> tmp(derived());
176 tmp = PlainObject::Constant(rows(),cols(),other);
180 template<
typename Derived>
181 inline Derived& DenseBase<Derived>::operator/=(
const Scalar& other)
183 typedef typename Derived::PlainObject PlainObject;
184 SelfCwiseBinaryOp<internal::scalar_quotient_op<Scalar>, Derived,
typename PlainObject::ConstantReturnType> tmp(derived());
185 tmp = PlainObject::Constant(rows(),cols(), other);
191 #endif // EIGEN_SELFCWISEBINARYOP_H
const unsigned int LvalueBit
Definition: Constants.h:131
const unsigned int DirectAccessBit
Definition: Constants.h:142