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
00026 #ifndef EIGEN_CWISE_UNARY_OP_H
00027 #define EIGEN_CWISE_UNARY_OP_H
00028
00042 template<typename UnaryOp, typename MatrixType>
00043 struct ei_traits<CwiseUnaryOp<UnaryOp, MatrixType> >
00044 : ei_traits<MatrixType>
00045 {
00046 typedef typename ei_result_of<
00047 UnaryOp(typename MatrixType::Scalar)
00048 >::type Scalar;
00049 typedef typename MatrixType::Nested MatrixTypeNested;
00050 typedef typename ei_unref<MatrixTypeNested>::type _MatrixTypeNested;
00051 enum {
00052 Flags = (_MatrixTypeNested::Flags & (
00053 HereditaryBits | LinearAccessBit | AlignedBit
00054 | (ei_functor_traits<UnaryOp>::PacketAccess ? PacketAccessBit : 0))),
00055 CoeffReadCost = _MatrixTypeNested::CoeffReadCost + ei_functor_traits<UnaryOp>::Cost
00056 };
00057 };
00058
00059 template<typename UnaryOp, typename MatrixType>
00060 class CwiseUnaryOp : ei_no_assignment_operator,
00061 public MatrixBase<CwiseUnaryOp<UnaryOp, MatrixType> >
00062 {
00063 public:
00064
00065 EIGEN_GENERIC_PUBLIC_INTERFACE(CwiseUnaryOp)
00066
00067 inline CwiseUnaryOp(const MatrixType& mat, const UnaryOp& func = UnaryOp())
00068 : m_matrix(mat), m_functor(func) {}
00069
00070 EIGEN_STRONG_INLINE int rows() const { return m_matrix.rows(); }
00071 EIGEN_STRONG_INLINE int cols() const { return m_matrix.cols(); }
00072
00073 EIGEN_STRONG_INLINE const Scalar coeff(int row, int col) const
00074 {
00075 return m_functor(m_matrix.coeff(row, col));
00076 }
00077
00078 template<int LoadMode>
00079 EIGEN_STRONG_INLINE PacketScalar packet(int row, int col) const
00080 {
00081 return m_functor.packetOp(m_matrix.template packet<LoadMode>(row, col));
00082 }
00083
00084 EIGEN_STRONG_INLINE const Scalar coeff(int index) const
00085 {
00086 return m_functor(m_matrix.coeff(index));
00087 }
00088
00089 template<int LoadMode>
00090 EIGEN_STRONG_INLINE PacketScalar packet(int index) const
00091 {
00092 return m_functor.packetOp(m_matrix.template packet<LoadMode>(index));
00093 }
00094
00095 protected:
00096 const typename MatrixType::Nested m_matrix;
00097 const UnaryOp m_functor;
00098 };
00099
00113 template<typename Derived>
00114 template<typename CustomUnaryOp>
00115 EIGEN_STRONG_INLINE const CwiseUnaryOp<CustomUnaryOp, Derived>
00116 MatrixBase<Derived>::unaryExpr(const CustomUnaryOp& func) const
00117 {
00118 return CwiseUnaryOp<CustomUnaryOp, Derived>(derived(), func);
00119 }
00120
00123 template<typename Derived>
00124 EIGEN_STRONG_INLINE const CwiseUnaryOp<ei_scalar_opposite_op<typename ei_traits<Derived>::Scalar>,Derived>
00125 MatrixBase<Derived>::operator-() const
00126 {
00127 return derived();
00128 }
00129
00137 template<typename ExpressionType>
00138 EIGEN_STRONG_INLINE const EIGEN_CWISE_UNOP_RETURN_TYPE(ei_scalar_abs_op)
00139 Cwise<ExpressionType>::abs() const
00140 {
00141 return _expression();
00142 }
00143
00151 template<typename ExpressionType>
00152 EIGEN_STRONG_INLINE const EIGEN_CWISE_UNOP_RETURN_TYPE(ei_scalar_abs2_op)
00153 Cwise<ExpressionType>::abs2() const
00154 {
00155 return _expression();
00156 }
00157
00161 template<typename Derived>
00162 EIGEN_STRONG_INLINE typename MatrixBase<Derived>::ConjugateReturnType
00163 MatrixBase<Derived>::conjugate() const
00164 {
00165 return ConjugateReturnType(derived());
00166 }
00167
00171 template<typename Derived>
00172 EIGEN_STRONG_INLINE const typename MatrixBase<Derived>::RealReturnType
00173 MatrixBase<Derived>::real() const { return derived(); }
00174
00178 template<typename Derived>
00179 EIGEN_STRONG_INLINE const typename MatrixBase<Derived>::ImagReturnType
00180 MatrixBase<Derived>::imag() const { return derived(); }
00181
00189 template<typename Derived>
00190 template<typename NewType>
00191 EIGEN_STRONG_INLINE const CwiseUnaryOp<ei_scalar_cast_op<typename ei_traits<Derived>::Scalar, NewType>, Derived>
00192 MatrixBase<Derived>::cast() const
00193 {
00194 return derived();
00195 }
00196
00198 template<typename Derived>
00199 EIGEN_STRONG_INLINE const typename MatrixBase<Derived>::ScalarMultipleReturnType
00200 MatrixBase<Derived>::operator*(const Scalar& scalar) const
00201 {
00202 return CwiseUnaryOp<ei_scalar_multiple_op<Scalar>, Derived>
00203 (derived(), ei_scalar_multiple_op<Scalar>(scalar));
00204 }
00205
00207 template<typename Derived>
00208 EIGEN_STRONG_INLINE const CwiseUnaryOp<ei_scalar_quotient1_op<typename ei_traits<Derived>::Scalar>, Derived>
00209 MatrixBase<Derived>::operator/(const Scalar& scalar) const
00210 {
00211 return CwiseUnaryOp<ei_scalar_quotient1_op<Scalar>, Derived>
00212 (derived(), ei_scalar_quotient1_op<Scalar>(scalar));
00213 }
00214
00215 template<typename Derived>
00216 EIGEN_STRONG_INLINE Derived&
00217 MatrixBase<Derived>::operator*=(const Scalar& other)
00218 {
00219 return *this = *this * other;
00220 }
00221
00222 template<typename Derived>
00223 EIGEN_STRONG_INLINE Derived&
00224 MatrixBase<Derived>::operator/=(const Scalar& other)
00225 {
00226 return *this = *this / other;
00227 }
00228
00229 #endif // EIGEN_CWISE_UNARY_OP_H