1 /** \returns an expression of the coefficient wise product of \c *this and \a other 2 * 3 * \sa MatrixBase::cwiseProduct 4 */ 5 template<typename OtherDerived> 6 EIGEN_STRONG_INLINE const EIGEN_CWISE_PRODUCT_RETURN_TYPE(Derived,OtherDerived) 7 operator*(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const 8 { 9 return EIGEN_CWISE_PRODUCT_RETURN_TYPE(Derived,OtherDerived)(derived(), other.derived()); 10 } 11 12 /** \returns an expression of the coefficient wise quotient of \c *this and \a other 13 * 14 * \sa MatrixBase::cwiseQuotient 15 */ 16 template<typename OtherDerived> 17 EIGEN_STRONG_INLINE const CwiseBinaryOp<internal::scalar_quotient_op<Scalar>, const Derived, const OtherDerived> 18 operator/(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const 19 { 20 return CwiseBinaryOp<internal::scalar_quotient_op<Scalar>, const Derived, const OtherDerived>(derived(), other.derived()); 21 } 22 23 /** \returns an expression of the coefficient-wise min of \c *this and \a other 24 * 25 * Example: \include Cwise_min.cpp 26 * Output: \verbinclude Cwise_min.out 27 * 28 * \sa max() 29 */ 30 EIGEN_MAKE_CWISE_BINARY_OP(min,internal::scalar_min_op) 31 32 /** \returns an expression of the coefficient-wise min of \c *this and scalar \a other 33 * 34 * \sa max() 35 */ 36 EIGEN_STRONG_INLINE const CwiseBinaryOp<internal::scalar_min_op<Scalar>, const Derived, 37 const CwiseNullaryOp<internal::scalar_constant_op<Scalar>, PlainObject> > 38 #ifdef EIGEN_PARSED_BY_DOXYGEN 39 min 40 #else 41 (min) 42 #endif 43 (const Scalar &other) const 44 { 45 return (min)(Derived::PlainObject::Constant(rows(), cols(), other)); 46 } 47 48 /** \returns an expression of the coefficient-wise max of \c *this and \a other 49 * 50 * Example: \include Cwise_max.cpp 51 * Output: \verbinclude Cwise_max.out 52 * 53 * \sa min() 54 */ 55 EIGEN_MAKE_CWISE_BINARY_OP(max,internal::scalar_max_op) 56 57 /** \returns an expression of the coefficient-wise max of \c *this and scalar \a other 58 * 59 * \sa min() 60 */ 61 EIGEN_STRONG_INLINE const CwiseBinaryOp<internal::scalar_max_op<Scalar>, const Derived, 62 const CwiseNullaryOp<internal::scalar_constant_op<Scalar>, PlainObject> > 63 #ifdef EIGEN_PARSED_BY_DOXYGEN 64 max 65 #else 66 (max) 67 #endif 68 (const Scalar &other) const 69 { 70 return (max)(Derived::PlainObject::Constant(rows(), cols(), other)); 71 } 72 73 74 #define EIGEN_MAKE_CWISE_COMP_OP(OP, COMPARATOR) \ 75 template<typename OtherDerived> \ 76 EIGEN_STRONG_INLINE const CwiseBinaryOp<internal::scalar_cmp_op<Scalar, internal::cmp_ ## COMPARATOR>, const Derived, const OtherDerived> \ 77 OP(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const \ 78 { \ 79 return CwiseBinaryOp<internal::scalar_cmp_op<Scalar, internal::cmp_ ## COMPARATOR>, const Derived, const OtherDerived>(derived(), other.derived()); \ 80 }\ 81 typedef CwiseBinaryOp<internal::scalar_cmp_op<Scalar, internal::cmp_ ## COMPARATOR>, const Derived, const CwiseNullaryOp<internal::scalar_constant_op<Scalar>, PlainObject> > Cmp ## COMPARATOR ## ReturnType; \ 82 typedef CwiseBinaryOp<internal::scalar_cmp_op<Scalar, internal::cmp_ ## COMPARATOR>, const CwiseNullaryOp<internal::scalar_constant_op<Scalar>, PlainObject>, const Derived > RCmp ## COMPARATOR ## ReturnType; \ 83 EIGEN_STRONG_INLINE const Cmp ## COMPARATOR ## ReturnType \ 84 OP(const Scalar& s) const { \ 85 return this->OP(Derived::PlainObject::Constant(rows(), cols(), s)); \ 86 } \ 87 friend EIGEN_STRONG_INLINE const RCmp ## COMPARATOR ## ReturnType \ 88 OP(const Scalar& s, const Derived& d) { \ 89 return Derived::PlainObject::Constant(d.rows(), d.cols(), s).OP(d); \ 90 } 91 92 #define EIGEN_MAKE_CWISE_COMP_R_OP(OP, R_OP, RCOMPARATOR) \ 93 template<typename OtherDerived> \ 94 EIGEN_STRONG_INLINE const CwiseBinaryOp<internal::scalar_cmp_op<Scalar, internal::cmp_##RCOMPARATOR>, const OtherDerived, const Derived> \ 95 OP(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const \ 96 { \ 97 return CwiseBinaryOp<internal::scalar_cmp_op<Scalar, internal::cmp_##RCOMPARATOR>, const OtherDerived, const Derived>(other.derived(), derived()); \ 98 } \ 99 \ 100 inline const RCmp ## RCOMPARATOR ## ReturnType \ 101 OP(const Scalar& s) const { \ 102 return Derived::PlainObject::Constant(rows(), cols(), s).R_OP(*this); \ 103 } \ 104 friend inline const Cmp ## RCOMPARATOR ## ReturnType \ 105 OP(const Scalar& s, const Derived& d) { \ 106 return d.R_OP(Derived::PlainObject::Constant(d.rows(), d.cols(), s)); \ 107 } 108 109 110 /** \returns an expression of the coefficient-wise \< operator of *this and \a other 111 * 112 * Example: \include Cwise_less.cpp 113 * Output: \verbinclude Cwise_less.out 114 * 115 * \sa all(), any(), operator>(), operator<=() 116 */ 117 EIGEN_MAKE_CWISE_COMP_OP(operator<, LT) 118 119 /** \returns an expression of the coefficient-wise \<= operator of *this and \a other 120 * 121 * Example: \include Cwise_less_equal.cpp 122 * Output: \verbinclude Cwise_less_equal.out 123 * 124 * \sa all(), any(), operator>=(), operator<() 125 */ 126 EIGEN_MAKE_CWISE_COMP_OP(operator<=, LE) 127 128 /** \returns an expression of the coefficient-wise \> operator of *this and \a other 129 * 130 * Example: \include Cwise_greater.cpp 131 * Output: \verbinclude Cwise_greater.out 132 * 133 * \sa all(), any(), operator>=(), operator<() 134 */ 135 EIGEN_MAKE_CWISE_COMP_R_OP(operator>, operator<, LT) 136 137 /** \returns an expression of the coefficient-wise \>= operator of *this and \a other 138 * 139 * Example: \include Cwise_greater_equal.cpp 140 * Output: \verbinclude Cwise_greater_equal.out 141 * 142 * \sa all(), any(), operator>(), operator<=() 143 */ 144 EIGEN_MAKE_CWISE_COMP_R_OP(operator>=, operator<=, LE) 145 146 /** \returns an expression of the coefficient-wise == operator of *this and \a other 147 * 148 * \warning this performs an exact comparison, which is generally a bad idea with floating-point types. 149 * In order to check for equality between two vectors or matrices with floating-point coefficients, it is 150 * generally a far better idea to use a fuzzy comparison as provided by isApprox() and 151 * isMuchSmallerThan(). 152 * 153 * Example: \include Cwise_equal_equal.cpp 154 * Output: \verbinclude Cwise_equal_equal.out 155 * 156 * \sa all(), any(), isApprox(), isMuchSmallerThan() 157 */ 158 EIGEN_MAKE_CWISE_COMP_OP(operator==, EQ) 159 160 /** \returns an expression of the coefficient-wise != operator of *this and \a other 161 * 162 * \warning this performs an exact comparison, which is generally a bad idea with floating-point types. 163 * In order to check for equality between two vectors or matrices with floating-point coefficients, it is 164 * generally a far better idea to use a fuzzy comparison as provided by isApprox() and 165 * isMuchSmallerThan(). 166 * 167 * Example: \include Cwise_not_equal.cpp 168 * Output: \verbinclude Cwise_not_equal.out 169 * 170 * \sa all(), any(), isApprox(), isMuchSmallerThan() 171 */ 172 EIGEN_MAKE_CWISE_COMP_OP(operator!=, NEQ) 173 174 #undef EIGEN_MAKE_CWISE_COMP_OP 175 #undef EIGEN_MAKE_CWISE_COMP_R_OP 176 177 // scalar addition 178 179 /** \returns an expression of \c *this with each coeff incremented by the constant \a scalar 180 * 181 * Example: \include Cwise_plus.cpp 182 * Output: \verbinclude Cwise_plus.out 183 * 184 * \sa operator+=(), operator-() 185 */ 186 inline const CwiseUnaryOp<internal::scalar_add_op<Scalar>, const Derived> 187 operator+(const Scalar& scalar) const 188 { 189 return CwiseUnaryOp<internal::scalar_add_op<Scalar>, const Derived>(derived(), internal::scalar_add_op<Scalar>(scalar)); 190 } 191 192 friend inline const CwiseUnaryOp<internal::scalar_add_op<Scalar>, const Derived> 193 operator+(const Scalar& scalar,const EIGEN_CURRENT_STORAGE_BASE_CLASS<Derived>& other) 194 { 195 return other + scalar; 196 } 197 198 /** \returns an expression of \c *this with each coeff decremented by the constant \a scalar 199 * 200 * Example: \include Cwise_minus.cpp 201 * Output: \verbinclude Cwise_minus.out 202 * 203 * \sa operator+(), operator-=() 204 */ 205 inline const CwiseUnaryOp<internal::scalar_add_op<Scalar>, const Derived> 206 operator-(const Scalar& scalar) const 207 { 208 return *this + (-scalar); 209 } 210 211 friend inline const CwiseUnaryOp<internal::scalar_add_op<Scalar>, const CwiseUnaryOp<internal::scalar_opposite_op<Scalar>, const Derived> > 212 operator-(const Scalar& scalar,const EIGEN_CURRENT_STORAGE_BASE_CLASS<Derived>& other) 213 { 214 return (-other) + scalar; 215 } 216 217 /** \returns an expression of the coefficient-wise && operator of *this and \a other 218 * 219 * \warning this operator is for expression of bool only. 220 * 221 * Example: \include Cwise_boolean_and.cpp 222 * Output: \verbinclude Cwise_boolean_and.out 223 * 224 * \sa operator||(), select() 225 */ 226 template<typename OtherDerived> 227 inline const CwiseBinaryOp<internal::scalar_boolean_and_op, const Derived, const OtherDerived> 228 operator&&(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const 229 { 230 EIGEN_STATIC_ASSERT((internal::is_same<bool,Scalar>::value && internal::is_same<bool,typename OtherDerived::Scalar>::value), 231 THIS_METHOD_IS_ONLY_FOR_EXPRESSIONS_OF_BOOL); 232 return CwiseBinaryOp<internal::scalar_boolean_and_op, const Derived, const OtherDerived>(derived(),other.derived()); 233 } 234 235 /** \returns an expression of the coefficient-wise || operator of *this and \a other 236 * 237 * \warning this operator is for expression of bool only. 238 * 239 * Example: \include Cwise_boolean_or.cpp 240 * Output: \verbinclude Cwise_boolean_or.out 241 * 242 * \sa operator&&(), select() 243 */ 244 template<typename OtherDerived> 245 inline const CwiseBinaryOp<internal::scalar_boolean_or_op, const Derived, const OtherDerived> 246 operator||(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const 247 { 248 EIGEN_STATIC_ASSERT((internal::is_same<bool,Scalar>::value && internal::is_same<bool,typename OtherDerived::Scalar>::value), 249 THIS_METHOD_IS_ONLY_FOR_EXPRESSIONS_OF_BOOL); 250 return CwiseBinaryOp<internal::scalar_boolean_or_op, const Derived, const OtherDerived>(derived(),other.derived()); 251 } 252 253 254