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