00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef EIGEN_SELFCWISEBINARYOP_H
00026 #define EIGEN_SELFCWISEBINARYOP_H
00027
00043 namespace internal {
00044 template<typename BinaryOp, typename Lhs, typename Rhs>
00045 struct traits<SelfCwiseBinaryOp<BinaryOp,Lhs,Rhs> >
00046 : traits<CwiseBinaryOp<BinaryOp,Lhs,Rhs> >
00047 {
00048 enum {
00049
00050
00051 Flags = traits<CwiseBinaryOp<BinaryOp,Lhs,Rhs> >::Flags | (Lhs::Flags&DirectAccessBit) | (Lhs::Flags&LvalueBit),
00052 OuterStrideAtCompileTime = Lhs::OuterStrideAtCompileTime,
00053 InnerStrideAtCompileTime = Lhs::InnerStrideAtCompileTime
00054 };
00055 };
00056 }
00057
00058 template<typename BinaryOp, typename Lhs, typename Rhs> class SelfCwiseBinaryOp
00059 : public internal::dense_xpr_base< SelfCwiseBinaryOp<BinaryOp, Lhs, Rhs> >::type
00060 {
00061 public:
00062
00063 typedef typename internal::dense_xpr_base<SelfCwiseBinaryOp>::type Base;
00064 EIGEN_DENSE_PUBLIC_INTERFACE(SelfCwiseBinaryOp)
00065
00066 typedef typename internal::packet_traits<Scalar>::type Packet;
00067
00068 inline SelfCwiseBinaryOp(Lhs& xpr, const BinaryOp& func = BinaryOp()) : m_matrix(xpr), m_functor(func) {}
00069
00070 inline Index rows() const { return m_matrix.rows(); }
00071 inline Index cols() const { return m_matrix.cols(); }
00072 inline Index outerStride() const { return m_matrix.outerStride(); }
00073 inline Index innerStride() const { return m_matrix.innerStride(); }
00074 inline const Scalar* data() const { return m_matrix.data(); }
00075
00076
00077
00078 inline Scalar& coeffRef(Index row, Index col)
00079 {
00080 EIGEN_STATIC_ASSERT_LVALUE(Lhs)
00081 return m_matrix.const_cast_derived().coeffRef(row, col);
00082 }
00083 inline const Scalar& coeffRef(Index row, Index col) const
00084 {
00085 return m_matrix.coeffRef(row, col);
00086 }
00087
00088
00089
00090 inline Scalar& coeffRef(Index index)
00091 {
00092 EIGEN_STATIC_ASSERT_LVALUE(Lhs)
00093 return m_matrix.const_cast_derived().coeffRef(index);
00094 }
00095 inline const Scalar& coeffRef(Index index) const
00096 {
00097 return m_matrix.const_cast_derived().coeffRef(index);
00098 }
00099
00100 template<typename OtherDerived>
00101 void copyCoeff(Index row, Index col, const DenseBase<OtherDerived>& other)
00102 {
00103 OtherDerived& _other = other.const_cast_derived();
00104 eigen_internal_assert(row >= 0 && row < rows()
00105 && col >= 0 && col < cols());
00106 Scalar& tmp = m_matrix.coeffRef(row,col);
00107 tmp = m_functor(tmp, _other.coeff(row,col));
00108 }
00109
00110 template<typename OtherDerived>
00111 void copyCoeff(Index index, const DenseBase<OtherDerived>& other)
00112 {
00113 OtherDerived& _other = other.const_cast_derived();
00114 eigen_internal_assert(index >= 0 && index < m_matrix.size());
00115 Scalar& tmp = m_matrix.coeffRef(index);
00116 tmp = m_functor(tmp, _other.coeff(index));
00117 }
00118
00119 template<typename OtherDerived, int StoreMode, int LoadMode>
00120 void copyPacket(Index row, Index col, const DenseBase<OtherDerived>& other)
00121 {
00122 OtherDerived& _other = other.const_cast_derived();
00123 eigen_internal_assert(row >= 0 && row < rows()
00124 && col >= 0 && col < cols());
00125 m_matrix.template writePacket<StoreMode>(row, col,
00126 m_functor.packetOp(m_matrix.template packet<StoreMode>(row, col),_other.template packet<LoadMode>(row, col)) );
00127 }
00128
00129 template<typename OtherDerived, int StoreMode, int LoadMode>
00130 void copyPacket(Index index, const DenseBase<OtherDerived>& other)
00131 {
00132 OtherDerived& _other = other.const_cast_derived();
00133 eigen_internal_assert(index >= 0 && index < m_matrix.size());
00134 m_matrix.template writePacket<StoreMode>(index,
00135 m_functor.packetOp(m_matrix.template packet<StoreMode>(index),_other.template packet<LoadMode>(index)) );
00136 }
00137
00138
00139
00140 template<typename RhsDerived>
00141 EIGEN_STRONG_INLINE SelfCwiseBinaryOp& lazyAssign(const DenseBase<RhsDerived>& rhs)
00142 {
00143 EIGEN_STATIC_ASSERT_SAME_MATRIX_SIZE(Lhs,RhsDerived)
00144 EIGEN_CHECK_BINARY_COMPATIBILIY(BinaryOp,typename Lhs::Scalar,typename RhsDerived::Scalar);
00145
00146 #ifdef EIGEN_DEBUG_ASSIGN
00147 internal::assign_traits<SelfCwiseBinaryOp, RhsDerived>::debug();
00148 #endif
00149 eigen_assert(rows() == rhs.rows() && cols() == rhs.cols());
00150 internal::assign_impl<SelfCwiseBinaryOp, RhsDerived>::run(*this,rhs.derived());
00151 #ifndef EIGEN_NO_DEBUG
00152 this->checkTransposeAliasing(rhs.derived());
00153 #endif
00154 return *this;
00155 }
00156
00157
00158
00159
00160 SelfCwiseBinaryOp& operator=(const Rhs& _rhs)
00161 {
00162 typename internal::nested<Rhs>::type rhs(_rhs);
00163 return Base::operator=(rhs);
00164 }
00165
00166 protected:
00167 Lhs& m_matrix;
00168 const BinaryOp& m_functor;
00169
00170 private:
00171 SelfCwiseBinaryOp& operator=(const SelfCwiseBinaryOp&);
00172 };
00173
00174 template<typename Derived>
00175 inline Derived& DenseBase<Derived>::operator*=(const Scalar& other)
00176 {
00177 typedef typename Derived::PlainObject PlainObject;
00178 SelfCwiseBinaryOp<internal::scalar_product_op<Scalar>, Derived, typename PlainObject::ConstantReturnType> tmp(derived());
00179 tmp = PlainObject::Constant(rows(),cols(),other);
00180 return derived();
00181 }
00182
00183 template<typename Derived>
00184 inline Derived& DenseBase<Derived>::operator/=(const Scalar& other)
00185 {
00186 typedef typename internal::conditional<NumTraits<Scalar>::IsInteger,
00187 internal::scalar_quotient_op<Scalar>,
00188 internal::scalar_product_op<Scalar> >::type BinOp;
00189 typedef typename Derived::PlainObject PlainObject;
00190 SelfCwiseBinaryOp<BinOp, Derived, typename PlainObject::ConstantReturnType> tmp(derived());
00191 tmp = PlainObject::Constant(rows(),cols(), NumTraits<Scalar>::IsInteger ? other : Scalar(1)/other);
00192 return derived();
00193 }
00194
00195 #endif // EIGEN_SELFCWISEBINARYOP_H