WPILibC++ 2023.4.3-108-ge5452e3
ArrayCwiseBinaryOps.h
Go to the documentation of this file.
1
2/** \returns an expression of the coefficient wise product of \c *this and \a other
3 *
4 * \sa MatrixBase::cwiseProduct
5 */
6template<typename OtherDerived>
8EIGEN_STRONG_INLINE const EIGEN_CWISE_BINARY_RETURN_TYPE(Derived,OtherDerived,product)
9operator*(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 */
18template<typename OtherDerived>
20EIGEN_STRONG_INLINE const CwiseBinaryOp<internal::scalar_quotient_op<Scalar,typename OtherDerived::Scalar>, const Derived, const OtherDerived>
21operator/(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 */
34
35/** \returns an expression of the coefficient-wise min of \c *this and scalar \a other
36 *
37 * \sa max()
38 */
40EIGEN_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
43min
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 */
60
61/** \returns an expression of the coefficient-wise max of \c *this and scalar \a other
62 *
63 * \sa min()
64 */
66EIGEN_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
69max
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 */
85EIGEN_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 */
92EIGEN_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
95absolute_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 */
112
113#ifndef EIGEN_PARSED_BY_DOXYGEN
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 */
128template<typename T>
129const 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) \
135template<typename OtherDerived> \
136EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const CwiseBinaryOp<internal::scalar_cmp_op<Scalar, typename OtherDerived::Scalar, internal::cmp_ ## COMPARATOR>, const Derived, const OtherDerived> \
137OP(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}\
141typedef CwiseBinaryOp<internal::scalar_cmp_op<Scalar,Scalar, internal::cmp_ ## COMPARATOR>, const Derived, const CwiseNullaryOp<internal::scalar_constant_op<Scalar>, PlainObject> > Cmp ## COMPARATOR ## ReturnType; \
142typedef CwiseBinaryOp<internal::scalar_cmp_op<Scalar,Scalar, internal::cmp_ ## COMPARATOR>, const CwiseNullaryOp<internal::scalar_constant_op<Scalar>, PlainObject>, const Derived > RCmp ## COMPARATOR ## ReturnType; \
143EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Cmp ## COMPARATOR ## ReturnType \
144OP(const Scalar& s) const { \
145 return this->OP(Derived::PlainObject::Constant(rows(), cols(), s)); \
146} \
147EIGEN_DEVICE_FUNC friend EIGEN_STRONG_INLINE const RCmp ## COMPARATOR ## ReturnType \
148OP(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) \
153template<typename OtherDerived> \
154EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const CwiseBinaryOp<internal::scalar_cmp_op<typename OtherDerived::Scalar, Scalar, internal::cmp_##RCOMPARATOR>, const OtherDerived, const Derived> \
155OP(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} \
159EIGEN_DEVICE_FUNC \
160inline const RCmp ## RCOMPARATOR ## ReturnType \
161OP(const Scalar& s) const { \
162 return Derived::PlainObject::Constant(rows(), cols(), s).R_OP(*this); \
163} \
164friend inline const Cmp ## RCOMPARATOR ## ReturnType \
165OP(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 */
178EIGEN_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 */
187EIGEN_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 */
196EIGEN_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 */
205EIGEN_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 */
219EIGEN_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 */
233EIGEN_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
241EIGEN_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 */
252template<typename T>
253const 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 */
258template<typename T> friend
259const 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
263EIGEN_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 */
274template<typename T>
275const 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 */
280template<typename T> friend
281const 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 */
307template<typename OtherDerived>
309inline const CwiseBinaryOp<internal::scalar_boolean_xor_op, const Derived, const OtherDerived>
310operator^(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 */
329template<typename DerivedN>
330inline const CwiseBinaryOp<internal::scalar_polygamma_op<Scalar>, const DerivedN, const Derived>
331polygamma(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 */
353template<typename DerivedQ>
354inline const CwiseBinaryOp<internal::scalar_zeta_op<Scalar>, const Derived, const DerivedQ>
355zeta(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}
EIGEN_DEVICE_FUNC const CwiseBinaryOp< internal::scalar_boolean_xor_op, const Derived, const OtherDerived > operator^(const EIGEN_CURRENT_STORAGE_BASE_CLASS< OtherDerived > &other) const
Definition: ArrayCwiseBinaryOps.h:310
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const EIGEN_CWISE_BINARY_RETURN_TYPE(Derived, OtherDerived, product) operator*(const EIGEN_CURRENT_STORAGE_BASE_CLASS< OtherDerived > &other) const
Definition: ArrayCwiseBinaryOps.h:8
const CwiseBinaryOp< internal::scalar_zeta_op< Scalar >, const Derived, const DerivedQ > zeta(const EIGEN_CURRENT_STORAGE_BASE_CLASS< DerivedQ > &q) const
Definition: ArrayCwiseBinaryOps.h:355
#define EIGEN_MAKE_CWISE_COMP_OP(OP, COMPARATOR)
Definition: ArrayCwiseBinaryOps.h:134
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const CwiseBinaryOp< internal::scalar_quotient_op< Scalar, typename OtherDerived::Scalar >, const Derived, const OtherDerived > operator/(const EIGEN_CURRENT_STORAGE_BASE_CLASS< OtherDerived > &other) const
Definition: ArrayCwiseBinaryOps.h:21
#define EIGEN_MAKE_CWISE_COMP_R_OP(OP, R_OP, RCOMPARATOR)
Definition: ArrayCwiseBinaryOps.h:152
EIGEN_DEVICE_FUNC const NegativeReturnType operator-() const
Definition: CommonCwiseUnaryOps.h:45
#define EIGEN_MAKE_SCALAR_BINARY_OP_ONTHERIGHT(METHOD, OPNAME)
Definition: Macros.h:1372
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:986
#define EIGEN_MAKE_SCALAR_BINARY_OP_ONTHELEFT(METHOD, OPNAME)
Definition: Macros.h:1381
#define EIGEN_MAKE_SCALAR_BINARY_OP(METHOD, OPNAME)
Definition: Macros.h:1390
#define EIGEN_MAKE_CWISE_BINARY_OP(METHOD, OPNAME)
Definition: Macros.h:1346
#define EIGEN_STRONG_INLINE
Definition: Macros.h:927
#define EIGEN_STATIC_ASSERT(CONDITION, MSG)
Definition: StaticAssert.h:127
const Eigen::CwiseBinaryOp< Eigen::internal::scalar_pow_op< typename Derived::Scalar, typename ExponentDerived::Scalar >, const Derived, const ExponentDerived > pow(const Eigen::ArrayBase< Derived > &x, const Eigen::ArrayBase< ExponentDerived > &exponents)
Definition: GlobalFunctions.h:143
FMT_CONSTEXPR fp operator*(fp x, fp y)
Definition: format.h:1482
constexpr common_t< T1, T2 > max(const T1 x, const T2 y) noexcept
Compile-time pairwise maximum function.
Definition: max.hpp:35
constexpr common_t< T1, T2 > min(const T1 x, const T2 y) noexcept
Compile-time pairwise minimum function.
Definition: min.hpp:35
unit< std::ratio< 1 >, units::category::scalar_unit > scalar
Definition: base.h:2521
constexpr unit_t< Units, T, NonLinearScale > operator+(const unit_t< Units, T, NonLinearScale > &u) noexcept
Definition: base.h:2339