ArrayCwiseBinaryOps.h (14060B)
1 2 /** \returns an expression of the coefficient wise product of \c *this and \a other 3 * 4 * \sa MatrixBase::cwiseProduct 5 */ 6 template<typename OtherDerived> 7 EIGEN_DEVICE_FUNC 8 EIGEN_STRONG_INLINE const EIGEN_CWISE_BINARY_RETURN_TYPE(Derived,OtherDerived,product) 9 operator*(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const 10 { 11 return EIGEN_CWISE_BINARY_RETURN_TYPE(Derived,OtherDerived,product)(derived(), other.derived()); 12 } 13 14 /** \returns an expression of the coefficient wise quotient of \c *this and \a other 15 * 16 * \sa MatrixBase::cwiseQuotient 17 */ 18 template<typename OtherDerived> 19 EIGEN_DEVICE_FUNC 20 EIGEN_STRONG_INLINE const CwiseBinaryOp<internal::scalar_quotient_op<Scalar,typename OtherDerived::Scalar>, const Derived, const OtherDerived> 21 operator/(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const 22 { 23 return CwiseBinaryOp<internal::scalar_quotient_op<Scalar,typename OtherDerived::Scalar>, const Derived, const OtherDerived>(derived(), other.derived()); 24 } 25 26 /** \returns an expression of the coefficient-wise min of \c *this and \a other 27 * 28 * Example: \include Cwise_min.cpp 29 * Output: \verbinclude Cwise_min.out 30 * 31 * \sa max() 32 */ 33 EIGEN_MAKE_CWISE_BINARY_OP(min,min) 34 35 /** \returns an expression of the coefficient-wise min of \c *this and scalar \a other 36 * 37 * \sa max() 38 */ 39 EIGEN_DEVICE_FUNC 40 EIGEN_STRONG_INLINE const CwiseBinaryOp<internal::scalar_min_op<Scalar,Scalar>, const Derived, 41 const CwiseNullaryOp<internal::scalar_constant_op<Scalar>, PlainObject> > 42 #ifdef EIGEN_PARSED_BY_DOXYGEN 43 min 44 #else 45 (min) 46 #endif 47 (const Scalar &other) const 48 { 49 return (min)(Derived::PlainObject::Constant(rows(), cols(), other)); 50 } 51 52 /** \returns an expression of the coefficient-wise max of \c *this and \a other 53 * 54 * Example: \include Cwise_max.cpp 55 * Output: \verbinclude Cwise_max.out 56 * 57 * \sa min() 58 */ 59 EIGEN_MAKE_CWISE_BINARY_OP(max,max) 60 61 /** \returns an expression of the coefficient-wise max of \c *this and scalar \a other 62 * 63 * \sa min() 64 */ 65 EIGEN_DEVICE_FUNC 66 EIGEN_STRONG_INLINE const CwiseBinaryOp<internal::scalar_max_op<Scalar,Scalar>, const Derived, 67 const CwiseNullaryOp<internal::scalar_constant_op<Scalar>, PlainObject> > 68 #ifdef EIGEN_PARSED_BY_DOXYGEN 69 max 70 #else 71 (max) 72 #endif 73 (const Scalar &other) const 74 { 75 return (max)(Derived::PlainObject::Constant(rows(), cols(), other)); 76 } 77 78 /** \returns an expression of the coefficient-wise absdiff of \c *this and \a other 79 * 80 * Example: \include Cwise_absolute_difference.cpp 81 * Output: \verbinclude Cwise_absolute_difference.out 82 * 83 * \sa absolute_difference() 84 */ 85 EIGEN_MAKE_CWISE_BINARY_OP(absolute_difference,absolute_difference) 86 87 /** \returns an expression of the coefficient-wise absolute_difference of \c *this and scalar \a other 88 * 89 * \sa absolute_difference() 90 */ 91 EIGEN_DEVICE_FUNC 92 EIGEN_STRONG_INLINE const CwiseBinaryOp<internal::scalar_absolute_difference_op<Scalar,Scalar>, const Derived, 93 const CwiseNullaryOp<internal::scalar_constant_op<Scalar>, PlainObject> > 94 #ifdef EIGEN_PARSED_BY_DOXYGEN 95 absolute_difference 96 #else 97 (absolute_difference) 98 #endif 99 (const Scalar &other) const 100 { 101 return (absolute_difference)(Derived::PlainObject::Constant(rows(), cols(), other)); 102 } 103 104 /** \returns an expression of the coefficient-wise power of \c *this to the given array of \a exponents. 105 * 106 * This function computes the coefficient-wise power. 107 * 108 * Example: \include Cwise_array_power_array.cpp 109 * Output: \verbinclude Cwise_array_power_array.out 110 */ 111 EIGEN_MAKE_CWISE_BINARY_OP(pow,pow) 112 113 #ifndef EIGEN_PARSED_BY_DOXYGEN 114 EIGEN_MAKE_SCALAR_BINARY_OP_ONTHERIGHT(pow,pow) 115 #else 116 /** \returns an expression of the coefficients of \c *this rasied to the constant power \a exponent 117 * 118 * \tparam T is the scalar type of \a exponent. It must be compatible with the scalar type of the given expression. 119 * 120 * This function computes the coefficient-wise power. The function MatrixBase::pow() in the 121 * unsupported module MatrixFunctions computes the matrix power. 122 * 123 * Example: \include Cwise_pow.cpp 124 * Output: \verbinclude Cwise_pow.out 125 * 126 * \sa ArrayBase::pow(ArrayBase), square(), cube(), exp(), log() 127 */ 128 template<typename T> 129 const CwiseBinaryOp<internal::scalar_pow_op<Scalar,T>,Derived,Constant<T> > pow(const T& exponent) const; 130 #endif 131 132 133 // TODO code generating macros could be moved to Macros.h and could include generation of documentation 134 #define EIGEN_MAKE_CWISE_COMP_OP(OP, COMPARATOR) \ 135 template<typename OtherDerived> \ 136 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const CwiseBinaryOp<internal::scalar_cmp_op<Scalar, typename OtherDerived::Scalar, internal::cmp_ ## COMPARATOR>, const Derived, const OtherDerived> \ 137 OP(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const \ 138 { \ 139 return CwiseBinaryOp<internal::scalar_cmp_op<Scalar, typename OtherDerived::Scalar, internal::cmp_ ## COMPARATOR>, const Derived, const OtherDerived>(derived(), other.derived()); \ 140 }\ 141 typedef CwiseBinaryOp<internal::scalar_cmp_op<Scalar,Scalar, internal::cmp_ ## COMPARATOR>, const Derived, const CwiseNullaryOp<internal::scalar_constant_op<Scalar>, PlainObject> > Cmp ## COMPARATOR ## ReturnType; \ 142 typedef CwiseBinaryOp<internal::scalar_cmp_op<Scalar,Scalar, internal::cmp_ ## COMPARATOR>, const CwiseNullaryOp<internal::scalar_constant_op<Scalar>, PlainObject>, const Derived > RCmp ## COMPARATOR ## ReturnType; \ 143 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Cmp ## COMPARATOR ## ReturnType \ 144 OP(const Scalar& s) const { \ 145 return this->OP(Derived::PlainObject::Constant(rows(), cols(), s)); \ 146 } \ 147 EIGEN_DEVICE_FUNC friend EIGEN_STRONG_INLINE const RCmp ## COMPARATOR ## ReturnType \ 148 OP(const Scalar& s, const EIGEN_CURRENT_STORAGE_BASE_CLASS<Derived>& d) { \ 149 return Derived::PlainObject::Constant(d.rows(), d.cols(), s).OP(d); \ 150 } 151 152 #define EIGEN_MAKE_CWISE_COMP_R_OP(OP, R_OP, RCOMPARATOR) \ 153 template<typename OtherDerived> \ 154 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const CwiseBinaryOp<internal::scalar_cmp_op<typename OtherDerived::Scalar, Scalar, internal::cmp_##RCOMPARATOR>, const OtherDerived, const Derived> \ 155 OP(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const \ 156 { \ 157 return CwiseBinaryOp<internal::scalar_cmp_op<typename OtherDerived::Scalar, Scalar, internal::cmp_##RCOMPARATOR>, const OtherDerived, const Derived>(other.derived(), derived()); \ 158 } \ 159 EIGEN_DEVICE_FUNC \ 160 inline const RCmp ## RCOMPARATOR ## ReturnType \ 161 OP(const Scalar& s) const { \ 162 return Derived::PlainObject::Constant(rows(), cols(), s).R_OP(*this); \ 163 } \ 164 friend inline const Cmp ## RCOMPARATOR ## ReturnType \ 165 OP(const Scalar& s, const Derived& d) { \ 166 return d.R_OP(Derived::PlainObject::Constant(d.rows(), d.cols(), s)); \ 167 } 168 169 170 171 /** \returns an expression of the coefficient-wise \< operator of *this and \a other 172 * 173 * Example: \include Cwise_less.cpp 174 * Output: \verbinclude Cwise_less.out 175 * 176 * \sa all(), any(), operator>(), operator<=() 177 */ 178 EIGEN_MAKE_CWISE_COMP_OP(operator<, LT) 179 180 /** \returns an expression of the coefficient-wise \<= operator of *this and \a other 181 * 182 * Example: \include Cwise_less_equal.cpp 183 * Output: \verbinclude Cwise_less_equal.out 184 * 185 * \sa all(), any(), operator>=(), operator<() 186 */ 187 EIGEN_MAKE_CWISE_COMP_OP(operator<=, LE) 188 189 /** \returns an expression of the coefficient-wise \> operator of *this and \a other 190 * 191 * Example: \include Cwise_greater.cpp 192 * Output: \verbinclude Cwise_greater.out 193 * 194 * \sa all(), any(), operator>=(), operator<() 195 */ 196 EIGEN_MAKE_CWISE_COMP_R_OP(operator>, operator<, LT) 197 198 /** \returns an expression of the coefficient-wise \>= operator of *this and \a other 199 * 200 * Example: \include Cwise_greater_equal.cpp 201 * Output: \verbinclude Cwise_greater_equal.out 202 * 203 * \sa all(), any(), operator>(), operator<=() 204 */ 205 EIGEN_MAKE_CWISE_COMP_R_OP(operator>=, operator<=, LE) 206 207 /** \returns an expression of the coefficient-wise == operator of *this and \a other 208 * 209 * \warning this performs an exact comparison, which is generally a bad idea with floating-point types. 210 * In order to check for equality between two vectors or matrices with floating-point coefficients, it is 211 * generally a far better idea to use a fuzzy comparison as provided by isApprox() and 212 * isMuchSmallerThan(). 213 * 214 * Example: \include Cwise_equal_equal.cpp 215 * Output: \verbinclude Cwise_equal_equal.out 216 * 217 * \sa all(), any(), isApprox(), isMuchSmallerThan() 218 */ 219 EIGEN_MAKE_CWISE_COMP_OP(operator==, EQ) 220 221 /** \returns an expression of the coefficient-wise != operator of *this and \a other 222 * 223 * \warning this performs an exact comparison, which is generally a bad idea with floating-point types. 224 * In order to check for equality between two vectors or matrices with floating-point coefficients, it is 225 * generally a far better idea to use a fuzzy comparison as provided by isApprox() and 226 * isMuchSmallerThan(). 227 * 228 * Example: \include Cwise_not_equal.cpp 229 * Output: \verbinclude Cwise_not_equal.out 230 * 231 * \sa all(), any(), isApprox(), isMuchSmallerThan() 232 */ 233 EIGEN_MAKE_CWISE_COMP_OP(operator!=, NEQ) 234 235 236 #undef EIGEN_MAKE_CWISE_COMP_OP 237 #undef EIGEN_MAKE_CWISE_COMP_R_OP 238 239 // scalar addition 240 #ifndef EIGEN_PARSED_BY_DOXYGEN 241 EIGEN_MAKE_SCALAR_BINARY_OP(operator+,sum) 242 #else 243 /** \returns an expression of \c *this with each coeff incremented by the constant \a scalar 244 * 245 * \tparam T is the scalar type of \a scalar. It must be compatible with the scalar type of the given expression. 246 * 247 * Example: \include Cwise_plus.cpp 248 * Output: \verbinclude Cwise_plus.out 249 * 250 * \sa operator+=(), operator-() 251 */ 252 template<typename T> 253 const CwiseBinaryOp<internal::scalar_sum_op<Scalar,T>,Derived,Constant<T> > operator+(const T& scalar) const; 254 /** \returns an expression of \a expr with each coeff incremented by the constant \a scalar 255 * 256 * \tparam T is the scalar type of \a scalar. It must be compatible with the scalar type of the given expression. 257 */ 258 template<typename T> friend 259 const CwiseBinaryOp<internal::scalar_sum_op<T,Scalar>,Constant<T>,Derived> operator+(const T& scalar, const StorageBaseType& expr); 260 #endif 261 262 #ifndef EIGEN_PARSED_BY_DOXYGEN 263 EIGEN_MAKE_SCALAR_BINARY_OP(operator-,difference) 264 #else 265 /** \returns an expression of \c *this with each coeff decremented by the constant \a scalar 266 * 267 * \tparam T is the scalar type of \a scalar. It must be compatible with the scalar type of the given expression. 268 * 269 * Example: \include Cwise_minus.cpp 270 * Output: \verbinclude Cwise_minus.out 271 * 272 * \sa operator+=(), operator-() 273 */ 274 template<typename T> 275 const CwiseBinaryOp<internal::scalar_difference_op<Scalar,T>,Derived,Constant<T> > operator-(const T& scalar) const; 276 /** \returns an expression of the constant matrix of value \a scalar decremented by the coefficients of \a expr 277 * 278 * \tparam T is the scalar type of \a scalar. It must be compatible with the scalar type of the given expression. 279 */ 280 template<typename T> friend 281 const CwiseBinaryOp<internal::scalar_difference_op<T,Scalar>,Constant<T>,Derived> operator-(const T& scalar, const StorageBaseType& expr); 282 #endif 283 284 285 #ifndef EIGEN_PARSED_BY_DOXYGEN 286 EIGEN_MAKE_SCALAR_BINARY_OP_ONTHELEFT(operator/,quotient) 287 #else 288 /** 289 * \brief Component-wise division of the scalar \a s by array elements of \a a. 290 * 291 * \tparam Scalar is the scalar type of \a x. It must be compatible with the scalar type of the given array expression (\c Derived::Scalar). 292 */ 293 template<typename T> friend 294 inline const CwiseBinaryOp<internal::scalar_quotient_op<T,Scalar>,Constant<T>,Derived> 295 operator/(const T& s,const StorageBaseType& a); 296 #endif 297 298 /** \returns an expression of the coefficient-wise ^ operator of *this and \a other 299 * 300 * \warning this operator is for expression of bool only. 301 * 302 * Example: \include Cwise_boolean_xor.cpp 303 * Output: \verbinclude Cwise_boolean_xor.out 304 * 305 * \sa operator&&(), select() 306 */ 307 template<typename OtherDerived> 308 EIGEN_DEVICE_FUNC 309 inline const CwiseBinaryOp<internal::scalar_boolean_xor_op, const Derived, const OtherDerived> 310 operator^(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const 311 { 312 EIGEN_STATIC_ASSERT((internal::is_same<bool,Scalar>::value && internal::is_same<bool,typename OtherDerived::Scalar>::value), 313 THIS_METHOD_IS_ONLY_FOR_EXPRESSIONS_OF_BOOL); 314 return CwiseBinaryOp<internal::scalar_boolean_xor_op, const Derived, const OtherDerived>(derived(),other.derived()); 315 } 316 317 // NOTE disabled until we agree on argument order 318 #if 0 319 /** \cpp11 \returns an expression of the coefficient-wise polygamma function. 320 * 321 * \specialfunctions_module 322 * 323 * It returns the \a n -th derivative of the digamma(psi) evaluated at \c *this. 324 * 325 * \warning Be careful with the order of the parameters: x.polygamma(n) is equivalent to polygamma(n,x) 326 * 327 * \sa Eigen::polygamma() 328 */ 329 template<typename DerivedN> 330 inline const CwiseBinaryOp<internal::scalar_polygamma_op<Scalar>, const DerivedN, const Derived> 331 polygamma(const EIGEN_CURRENT_STORAGE_BASE_CLASS<DerivedN> &n) const 332 { 333 return CwiseBinaryOp<internal::scalar_polygamma_op<Scalar>, const DerivedN, const Derived>(n.derived(), this->derived()); 334 } 335 #endif 336 337 /** \returns an expression of the coefficient-wise zeta function. 338 * 339 * \specialfunctions_module 340 * 341 * It returns the Riemann zeta function of two arguments \c *this and \a q: 342 * 343 * \param q is the shift, it must be > 0 344 * 345 * \note *this is the exponent, it must be > 1. 346 * \note This function supports only float and double scalar types. To support other scalar types, the user has 347 * to provide implementations of zeta(T,T) for any scalar type T to be supported. 348 * 349 * This method is an alias for zeta(*this,q); 350 * 351 * \sa Eigen::zeta() 352 */ 353 template<typename DerivedQ> 354 inline const CwiseBinaryOp<internal::scalar_zeta_op<Scalar>, const Derived, const DerivedQ> 355 zeta(const EIGEN_CURRENT_STORAGE_BASE_CLASS<DerivedQ> &q) const 356 { 357 return CwiseBinaryOp<internal::scalar_zeta_op<Scalar>, const Derived, const DerivedQ>(this->derived(), q.derived()); 358 }