Eigen libary for mbed

Committer:
ykuroda
Date:
Thu Oct 13 04:07:23 2016 +0000
Revision:
0:13a5d365ba16
First commint, Eigne Matrix Class Library

Who changed what in which revision?

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