| 1 |
// This file is part of Eigen, a lightweight C++ template library |
| 2 |
// for linear algebra. |
| 3 |
// |
| 4 |
// Copyright (C) 2008-2016 Gael Guennebaud <[email protected]> |
| 5 |
// Copyright (C) 2006-2008 Benoit Jacob <[email protected]> |
| 6 |
// |
| 7 |
// This Source Code Form is subject to the terms of the Mozilla |
| 8 |
// Public License v. 2.0. If a copy of the MPL was not distributed |
| 9 |
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 10 |
|
| 11 |
// This file is a base class plugin containing common coefficient wise functions. |
| 12 |
|
| 13 |
/** \returns an expression of the difference of \c *this and \a other |
| 14 |
* |
| 15 |
* \note If you want to subtract a given scalar from all coefficients, see Cwise::operator-(). |
| 16 |
* |
| 17 |
* \sa class CwiseBinaryOp, operator-=() |
| 18 |
*/ |
| 19 |
EIGEN_MAKE_CWISE_BINARY_OP(operator-,difference) |
| 20 |
|
| 21 |
/** \returns an expression of the sum of \c *this and \a other |
| 22 |
* |
| 23 |
* \note If you want to add a given scalar to all coefficients, see Cwise::operator+(). |
| 24 |
* |
| 25 |
* \sa class CwiseBinaryOp, operator+=() |
| 26 |
*/ |
| 27 |
EIGEN_MAKE_CWISE_BINARY_OP(operator+,sum) |
| 28 |
|
| 29 |
/** \returns an expression of a custom coefficient-wise operator \a func of *this and \a other |
| 30 |
* |
| 31 |
* The template parameter \a CustomBinaryOp is the type of the functor |
| 32 |
* of the custom operator (see class CwiseBinaryOp for an example) |
| 33 |
* |
| 34 |
* Here is an example illustrating the use of custom functors: |
| 35 |
* \include class_CwiseBinaryOp.cpp |
| 36 |
* Output: \verbinclude class_CwiseBinaryOp.out |
| 37 |
* |
| 38 |
* \sa class CwiseBinaryOp, operator+(), operator-(), cwiseProduct() |
| 39 |
*/ |
| 40 |
template<typename CustomBinaryOp, typename OtherDerived> |
| 41 |
EIGEN_DEVICE_FUNC |
| 42 |
EIGEN_STRONG_INLINE const CwiseBinaryOp<CustomBinaryOp, const Derived, const OtherDerived> |
| 43 |
binaryExpr(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other, const CustomBinaryOp& func = CustomBinaryOp()) const |
| 44 |
{ |
| 45 |
return CwiseBinaryOp<CustomBinaryOp, const Derived, const OtherDerived>(derived(), other.derived(), func); |
| 46 |
} |
| 47 |
|
| 48 |
|
| 49 |
#ifndef EIGEN_PARSED_BY_DOXYGEN |
| 50 |
EIGEN_MAKE_SCALAR_BINARY_OP(operator*,product) |
| 51 |
#else |
| 52 |
/** \returns an expression of \c *this scaled by the scalar factor \a scalar |
| 53 |
* |
| 54 |
* \tparam T is the scalar type of \a scalar. It must be compatible with the scalar type of the given expression. |
| 55 |
*/ |
| 56 |
template<typename T> |
| 57 |
const CwiseBinaryOp<internal::scalar_product_op<Scalar,T>,Derived,Constant<T> > operator*(const T& scalar) const; |
| 58 |
/** \returns an expression of \a expr scaled by the scalar factor \a scalar |
| 59 |
* |
| 60 |
* \tparam T is the scalar type of \a scalar. It must be compatible with the scalar type of the given expression. |
| 61 |
*/ |
| 62 |
template<typename T> friend |
| 63 |
const CwiseBinaryOp<internal::scalar_product_op<T,Scalar>,Constant<T>,Derived> operator*(const T& scalar, const StorageBaseType& expr); |
| 64 |
#endif |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
#ifndef EIGEN_PARSED_BY_DOXYGEN |
| 69 |
EIGEN_MAKE_SCALAR_BINARY_OP_ONTHERIGHT(operator/,quotient) |
| 70 |
#else |
| 71 |
/** \returns an expression of \c *this divided by the scalar value \a scalar |
| 72 |
* |
| 73 |
* \tparam T is the scalar type of \a scalar. It must be compatible with the scalar type of the given expression. |
| 74 |
*/ |
| 75 |
template<typename T> |
| 76 |
const CwiseBinaryOp<internal::scalar_quotient_op<Scalar,T>,Derived,Constant<T> > operator/(const T& scalar) const; |
| 77 |
#endif |
| 78 |
|
| 79 |
/** \returns an expression of the coefficient-wise boolean \b and operator of \c *this and \a other |
| 80 |
* |
| 81 |
* Example: \include Cwise_boolean_and.cpp |
| 82 |
* Output: \verbinclude Cwise_boolean_and.out |
| 83 |
* |
| 84 |
* \sa operator||(), select() |
| 85 |
*/ |
| 86 |
template <typename OtherDerived> |
| 87 |
EIGEN_DEVICE_FUNC inline const CwiseBinaryOp<internal::scalar_boolean_and_op<Scalar>, const Derived, const OtherDerived> |
| 88 |
operator&&(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived>& other) const { |
| 89 |
return CwiseBinaryOp<internal::scalar_boolean_and_op<Scalar>, const Derived, const OtherDerived>(derived(), |
| 90 |
other.derived()); |
| 91 |
} |
| 92 |
|
| 93 |
/** \returns an expression of the coefficient-wise boolean \b or operator of \c *this and \a other |
| 94 |
* |
| 95 |
* Example: \include Cwise_boolean_or.cpp |
| 96 |
* Output: \verbinclude Cwise_boolean_or.out |
| 97 |
* |
| 98 |
* \sa operator&&(), select() |
| 99 |
*/ |
| 100 |
template <typename OtherDerived> |
| 101 |
EIGEN_DEVICE_FUNC inline const CwiseBinaryOp<internal::scalar_boolean_or_op<Scalar>, const Derived, const OtherDerived> |
| 102 |
operator||(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived>& other) const { |
| 103 |
return CwiseBinaryOp<internal::scalar_boolean_or_op<Scalar>, const Derived, const OtherDerived>(derived(), |
| 104 |
other.derived()); |
| 105 |
} |
| 106 |
|
| 107 |
/** \returns an expression of the bitwise \b and operator of \c *this and \a other |
| 108 |
* |
| 109 |
* \sa operator|(), operator^() |
| 110 |
*/ |
| 111 |
template <typename OtherDerived> |
| 112 |
EIGEN_DEVICE_FUNC inline const CwiseBinaryOp<internal::scalar_bitwise_and_op<Scalar>, const Derived, const OtherDerived> |
| 113 |
operator&(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived>& other) const { |
| 114 |
return CwiseBinaryOp<internal::scalar_bitwise_and_op<Scalar>, const Derived, const OtherDerived>(derived(), |
| 115 |
other.derived()); |
| 116 |
} |
| 117 |
|
| 118 |
/** \returns an expression of the bitwise boolean \b or operator of \c *this and \a other |
| 119 |
* |
| 120 |
* \sa operator&(), operator^() |
| 121 |
*/ |
| 122 |
template <typename OtherDerived> |
| 123 |
EIGEN_DEVICE_FUNC inline const CwiseBinaryOp<internal::scalar_bitwise_or_op<Scalar>, const Derived, const OtherDerived> |
| 124 |
operator|(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived>& other) const { |
| 125 |
return CwiseBinaryOp<internal::scalar_bitwise_or_op<Scalar>, const Derived, const OtherDerived>(derived(), |
| 126 |
other.derived()); |
| 127 |
} |
| 128 |
|
| 129 |
/** \returns an expression of the bitwise xor operator of *this and \a other |
| 130 |
* \sa operator&(), operator|() |
| 131 |
*/ |
| 132 |
template <typename OtherDerived> |
| 133 |
EIGEN_DEVICE_FUNC inline const CwiseBinaryOp<internal::scalar_bitwise_xor_op<Scalar>, const Derived, const OtherDerived> |
| 134 |
operator^(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived>& other) const { |
| 135 |
return CwiseBinaryOp<internal::scalar_bitwise_xor_op<Scalar>, const Derived, const OtherDerived>(derived(), |
| 136 |
other.derived()); |
| 137 |
} |