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_H
00027 #define EIGEN_CWISE_H
00028
00031 #define EIGEN_CWISE_BINOP_RETURN_TYPE(OP) \
00032 CwiseBinaryOp<OP<typename ei_traits<ExpressionType>::Scalar>, ExpressionType, OtherDerived>
00033
00034 #define EIGEN_CWISE_PRODUCT_RETURN_TYPE \
00035 CwiseBinaryOp< \
00036 ei_scalar_product_op< \
00037 typename ei_scalar_product_traits< \
00038 typename ei_traits<ExpressionType>::Scalar, \
00039 typename ei_traits<OtherDerived>::Scalar \
00040 >::ReturnType \
00041 >, \
00042 ExpressionType, \
00043 OtherDerived \
00044 >
00045
00048 #define EIGEN_CWISE_UNOP_RETURN_TYPE(OP) \
00049 CwiseUnaryOp<OP<typename ei_traits<ExpressionType>::Scalar>, ExpressionType>
00050
00053 #define EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(OP) \
00054 CwiseBinaryOp<OP<typename ei_traits<ExpressionType>::Scalar>, ExpressionType, \
00055 NestByValue<typename ExpressionType::ConstantReturnType> >
00056
00074 template<typename ExpressionType> class Cwise
00075 {
00076 public:
00077
00078 typedef typename ei_traits<ExpressionType>::Scalar Scalar;
00079 typedef typename ei_meta_if<ei_must_nest_by_value<ExpressionType>::ret,
00080 ExpressionType, const ExpressionType&>::ret ExpressionTypeNested;
00081 typedef CwiseUnaryOp<ei_scalar_add_op<Scalar>, ExpressionType> ScalarAddReturnType;
00082
00083 inline Cwise(const ExpressionType& matrix) : m_matrix(matrix) {}
00084
00086 inline const ExpressionType& _expression() const { return m_matrix; }
00087
00088 template<typename OtherDerived>
00089 const EIGEN_CWISE_PRODUCT_RETURN_TYPE
00090 operator*(const MatrixBase<OtherDerived> &other) const;
00091
00092 template<typename OtherDerived>
00093 const EIGEN_CWISE_BINOP_RETURN_TYPE(ei_scalar_quotient_op)
00094 operator/(const MatrixBase<OtherDerived> &other) const;
00095
00096 template<typename OtherDerived>
00097 const EIGEN_CWISE_BINOP_RETURN_TYPE(ei_scalar_min_op)
00098 min(const MatrixBase<OtherDerived> &other) const;
00099
00100 template<typename OtherDerived>
00101 const EIGEN_CWISE_BINOP_RETURN_TYPE(ei_scalar_max_op)
00102 max(const MatrixBase<OtherDerived> &other) const;
00103
00104 const EIGEN_CWISE_UNOP_RETURN_TYPE(ei_scalar_abs_op) abs() const;
00105 const EIGEN_CWISE_UNOP_RETURN_TYPE(ei_scalar_abs2_op) abs2() const;
00106 const EIGEN_CWISE_UNOP_RETURN_TYPE(ei_scalar_square_op) square() const;
00107 const EIGEN_CWISE_UNOP_RETURN_TYPE(ei_scalar_cube_op) cube() const;
00108 const EIGEN_CWISE_UNOP_RETURN_TYPE(ei_scalar_inverse_op) inverse() const;
00109 const EIGEN_CWISE_UNOP_RETURN_TYPE(ei_scalar_sqrt_op) sqrt() const;
00110 const EIGEN_CWISE_UNOP_RETURN_TYPE(ei_scalar_exp_op) exp() const;
00111 const EIGEN_CWISE_UNOP_RETURN_TYPE(ei_scalar_log_op) log() const;
00112 const EIGEN_CWISE_UNOP_RETURN_TYPE(ei_scalar_cos_op) cos() const;
00113 const EIGEN_CWISE_UNOP_RETURN_TYPE(ei_scalar_sin_op) sin() const;
00114 const EIGEN_CWISE_UNOP_RETURN_TYPE(ei_scalar_pow_op) pow(const Scalar& exponent) const;
00115
00116 const ScalarAddReturnType
00117 operator+(const Scalar& scalar) const;
00118
00120 friend const ScalarAddReturnType
00121 operator+(const Scalar& scalar, const Cwise& mat)
00122 { return mat + scalar; }
00123
00124 ExpressionType& operator+=(const Scalar& scalar);
00125
00126 const ScalarAddReturnType
00127 operator-(const Scalar& scalar) const;
00128
00129 ExpressionType& operator-=(const Scalar& scalar);
00130
00131 template<typename OtherDerived>
00132 inline ExpressionType& operator*=(const MatrixBase<OtherDerived> &other);
00133
00134 template<typename OtherDerived>
00135 inline ExpressionType& operator/=(const MatrixBase<OtherDerived> &other);
00136
00137 template<typename OtherDerived> const EIGEN_CWISE_BINOP_RETURN_TYPE(std::less)
00138 operator<(const MatrixBase<OtherDerived>& other) const;
00139
00140 template<typename OtherDerived> const EIGEN_CWISE_BINOP_RETURN_TYPE(std::less_equal)
00141 operator<=(const MatrixBase<OtherDerived>& other) const;
00142
00143 template<typename OtherDerived> const EIGEN_CWISE_BINOP_RETURN_TYPE(std::greater)
00144 operator>(const MatrixBase<OtherDerived>& other) const;
00145
00146 template<typename OtherDerived> const EIGEN_CWISE_BINOP_RETURN_TYPE(std::greater_equal)
00147 operator>=(const MatrixBase<OtherDerived>& other) const;
00148
00149 template<typename OtherDerived> const EIGEN_CWISE_BINOP_RETURN_TYPE(std::equal_to)
00150 operator==(const MatrixBase<OtherDerived>& other) const;
00151
00152 template<typename OtherDerived> const EIGEN_CWISE_BINOP_RETURN_TYPE(std::not_equal_to)
00153 operator!=(const MatrixBase<OtherDerived>& other) const;
00154
00155
00156 const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::less)
00157 operator<(Scalar s) const;
00158
00159 const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::less_equal)
00160 operator<=(Scalar s) const;
00161
00162 const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::greater)
00163 operator>(Scalar s) const;
00164
00165 const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::greater_equal)
00166 operator>=(Scalar s) const;
00167
00168 const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::equal_to)
00169 operator==(Scalar s) const;
00170
00171 const EIGEN_CWISE_COMP_TO_SCALAR_RETURN_TYPE(std::not_equal_to)
00172 operator!=(Scalar s) const;
00173
00174
00175 #ifdef EIGEN_CWISE_PLUGIN
00176 #include EIGEN_CWISE_PLUGIN
00177 #endif
00178
00179 protected:
00180 ExpressionTypeNested m_matrix;
00181
00182 private:
00183 Cwise& operator=(const Cwise&);
00184 };
00185
00193 template<typename Derived>
00194 inline const Cwise<Derived>
00195 MatrixBase<Derived>::cwise() const
00196 {
00197 return derived();
00198 }
00199
00207 template<typename Derived>
00208 inline Cwise<Derived>
00209 MatrixBase<Derived>::cwise()
00210 {
00211 return derived();
00212 }
00213
00214 #endif // EIGEN_CWISE_H