Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: MPC_current_control HydraulicControlBoard_SW AHRS Test_ekf ... more
src/Core/ArrayBase.h@0:13a5d365ba16, 2016-10-13 (annotated)
- 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?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| ykuroda | 0:13a5d365ba16 | 1 | // This file is part of Eigen, a lightweight C++ template library |
| ykuroda | 0:13a5d365ba16 | 2 | // for linear algebra. |
| ykuroda | 0:13a5d365ba16 | 3 | // |
| ykuroda | 0:13a5d365ba16 | 4 | // Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr> |
| ykuroda | 0:13a5d365ba16 | 5 | // |
| ykuroda | 0:13a5d365ba16 | 6 | // This Source Code Form is subject to the terms of the Mozilla |
| ykuroda | 0:13a5d365ba16 | 7 | // Public License v. 2.0. If a copy of the MPL was not distributed |
| ykuroda | 0:13a5d365ba16 | 8 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| ykuroda | 0:13a5d365ba16 | 9 | |
| ykuroda | 0:13a5d365ba16 | 10 | #ifndef EIGEN_ARRAYBASE_H |
| ykuroda | 0:13a5d365ba16 | 11 | #define EIGEN_ARRAYBASE_H |
| ykuroda | 0:13a5d365ba16 | 12 | |
| ykuroda | 0:13a5d365ba16 | 13 | namespace Eigen { |
| ykuroda | 0:13a5d365ba16 | 14 | |
| ykuroda | 0:13a5d365ba16 | 15 | template<typename ExpressionType> class MatrixWrapper; |
| ykuroda | 0:13a5d365ba16 | 16 | |
| ykuroda | 0:13a5d365ba16 | 17 | /** \class ArrayBase |
| ykuroda | 0:13a5d365ba16 | 18 | * \ingroup Core_Module |
| ykuroda | 0:13a5d365ba16 | 19 | * |
| ykuroda | 0:13a5d365ba16 | 20 | * \brief Base class for all 1D and 2D array, and related expressions |
| ykuroda | 0:13a5d365ba16 | 21 | * |
| ykuroda | 0:13a5d365ba16 | 22 | * An array is similar to a dense vector or matrix. While matrices are mathematical |
| ykuroda | 0:13a5d365ba16 | 23 | * objects with well defined linear algebra operators, an array is just a collection |
| ykuroda | 0:13a5d365ba16 | 24 | * of scalar values arranged in a one or two dimensionnal fashion. As the main consequence, |
| ykuroda | 0:13a5d365ba16 | 25 | * all operations applied to an array are performed coefficient wise. Furthermore, |
| ykuroda | 0:13a5d365ba16 | 26 | * arrays support scalar math functions of the c++ standard library (e.g., std::sin(x)), and convenient |
| ykuroda | 0:13a5d365ba16 | 27 | * constructors allowing to easily write generic code working for both scalar values |
| ykuroda | 0:13a5d365ba16 | 28 | * and arrays. |
| ykuroda | 0:13a5d365ba16 | 29 | * |
| ykuroda | 0:13a5d365ba16 | 30 | * This class is the base that is inherited by all array expression types. |
| ykuroda | 0:13a5d365ba16 | 31 | * |
| ykuroda | 0:13a5d365ba16 | 32 | * \tparam Derived is the derived type, e.g., an array or an expression type. |
| ykuroda | 0:13a5d365ba16 | 33 | * |
| ykuroda | 0:13a5d365ba16 | 34 | * This class can be extended with the help of the plugin mechanism described on the page |
| ykuroda | 0:13a5d365ba16 | 35 | * \ref TopicCustomizingEigen by defining the preprocessor symbol \c EIGEN_ARRAYBASE_PLUGIN. |
| ykuroda | 0:13a5d365ba16 | 36 | * |
| ykuroda | 0:13a5d365ba16 | 37 | * \sa class MatrixBase, \ref TopicClassHierarchy |
| ykuroda | 0:13a5d365ba16 | 38 | */ |
| ykuroda | 0:13a5d365ba16 | 39 | template<typename Derived> class ArrayBase |
| ykuroda | 0:13a5d365ba16 | 40 | : public DenseBase<Derived> |
| ykuroda | 0:13a5d365ba16 | 41 | { |
| ykuroda | 0:13a5d365ba16 | 42 | public: |
| ykuroda | 0:13a5d365ba16 | 43 | #ifndef EIGEN_PARSED_BY_DOXYGEN |
| ykuroda | 0:13a5d365ba16 | 44 | /** The base class for a given storage type. */ |
| ykuroda | 0:13a5d365ba16 | 45 | typedef ArrayBase StorageBaseType; |
| ykuroda | 0:13a5d365ba16 | 46 | |
| ykuroda | 0:13a5d365ba16 | 47 | typedef ArrayBase Eigen_BaseClassForSpecializationOfGlobalMathFuncImpl; |
| ykuroda | 0:13a5d365ba16 | 48 | |
| ykuroda | 0:13a5d365ba16 | 49 | typedef typename internal::traits<Derived>::StorageKind StorageKind; |
| ykuroda | 0:13a5d365ba16 | 50 | typedef typename internal::traits<Derived>::Index Index; |
| ykuroda | 0:13a5d365ba16 | 51 | typedef typename internal::traits<Derived>::Scalar Scalar; |
| ykuroda | 0:13a5d365ba16 | 52 | typedef typename internal::packet_traits<Scalar>::type PacketScalar; |
| ykuroda | 0:13a5d365ba16 | 53 | typedef typename NumTraits<Scalar>::Real RealScalar; |
| ykuroda | 0:13a5d365ba16 | 54 | |
| ykuroda | 0:13a5d365ba16 | 55 | typedef DenseBase<Derived> Base; |
| ykuroda | 0:13a5d365ba16 | 56 | using Base::operator*; |
| ykuroda | 0:13a5d365ba16 | 57 | using Base::RowsAtCompileTime; |
| ykuroda | 0:13a5d365ba16 | 58 | using Base::ColsAtCompileTime; |
| ykuroda | 0:13a5d365ba16 | 59 | using Base::SizeAtCompileTime; |
| ykuroda | 0:13a5d365ba16 | 60 | using Base::MaxRowsAtCompileTime; |
| ykuroda | 0:13a5d365ba16 | 61 | using Base::MaxColsAtCompileTime; |
| ykuroda | 0:13a5d365ba16 | 62 | using Base::MaxSizeAtCompileTime; |
| ykuroda | 0:13a5d365ba16 | 63 | using Base::IsVectorAtCompileTime; |
| ykuroda | 0:13a5d365ba16 | 64 | using Base::Flags; |
| ykuroda | 0:13a5d365ba16 | 65 | using Base::CoeffReadCost; |
| ykuroda | 0:13a5d365ba16 | 66 | |
| ykuroda | 0:13a5d365ba16 | 67 | using Base::derived; |
| ykuroda | 0:13a5d365ba16 | 68 | using Base::const_cast_derived; |
| ykuroda | 0:13a5d365ba16 | 69 | using Base::rows; |
| ykuroda | 0:13a5d365ba16 | 70 | using Base::cols; |
| ykuroda | 0:13a5d365ba16 | 71 | using Base::size; |
| ykuroda | 0:13a5d365ba16 | 72 | using Base::coeff; |
| ykuroda | 0:13a5d365ba16 | 73 | using Base::coeffRef; |
| ykuroda | 0:13a5d365ba16 | 74 | using Base::lazyAssign; |
| ykuroda | 0:13a5d365ba16 | 75 | using Base::operator=; |
| ykuroda | 0:13a5d365ba16 | 76 | using Base::operator+=; |
| ykuroda | 0:13a5d365ba16 | 77 | using Base::operator-=; |
| ykuroda | 0:13a5d365ba16 | 78 | using Base::operator*=; |
| ykuroda | 0:13a5d365ba16 | 79 | using Base::operator/=; |
| ykuroda | 0:13a5d365ba16 | 80 | |
| ykuroda | 0:13a5d365ba16 | 81 | typedef typename Base::CoeffReturnType CoeffReturnType; |
| ykuroda | 0:13a5d365ba16 | 82 | |
| ykuroda | 0:13a5d365ba16 | 83 | #endif // not EIGEN_PARSED_BY_DOXYGEN |
| ykuroda | 0:13a5d365ba16 | 84 | |
| ykuroda | 0:13a5d365ba16 | 85 | #ifndef EIGEN_PARSED_BY_DOXYGEN |
| ykuroda | 0:13a5d365ba16 | 86 | /** \internal the plain matrix type corresponding to this expression. Note that is not necessarily |
| ykuroda | 0:13a5d365ba16 | 87 | * exactly the return type of eval(): in the case of plain matrices, the return type of eval() is a const |
| ykuroda | 0:13a5d365ba16 | 88 | * reference to a matrix, not a matrix! It is however guaranteed that the return type of eval() is either |
| ykuroda | 0:13a5d365ba16 | 89 | * PlainObject or const PlainObject&. |
| ykuroda | 0:13a5d365ba16 | 90 | */ |
| ykuroda | 0:13a5d365ba16 | 91 | typedef Array<typename internal::traits<Derived>::Scalar, |
| ykuroda | 0:13a5d365ba16 | 92 | internal::traits<Derived>::RowsAtCompileTime, |
| ykuroda | 0:13a5d365ba16 | 93 | internal::traits<Derived>::ColsAtCompileTime, |
| ykuroda | 0:13a5d365ba16 | 94 | AutoAlign | (internal::traits<Derived>::Flags&RowMajorBit ? RowMajor : ColMajor), |
| ykuroda | 0:13a5d365ba16 | 95 | internal::traits<Derived>::MaxRowsAtCompileTime, |
| ykuroda | 0:13a5d365ba16 | 96 | internal::traits<Derived>::MaxColsAtCompileTime |
| ykuroda | 0:13a5d365ba16 | 97 | > PlainObject; |
| ykuroda | 0:13a5d365ba16 | 98 | |
| ykuroda | 0:13a5d365ba16 | 99 | |
| ykuroda | 0:13a5d365ba16 | 100 | /** \internal Represents a matrix with all coefficients equal to one another*/ |
| ykuroda | 0:13a5d365ba16 | 101 | typedef CwiseNullaryOp<internal::scalar_constant_op<Scalar>,Derived> ConstantReturnType; |
| ykuroda | 0:13a5d365ba16 | 102 | #endif // not EIGEN_PARSED_BY_DOXYGEN |
| ykuroda | 0:13a5d365ba16 | 103 | |
| ykuroda | 0:13a5d365ba16 | 104 | #define EIGEN_CURRENT_STORAGE_BASE_CLASS Eigen::ArrayBase |
| ykuroda | 0:13a5d365ba16 | 105 | # include "../plugins/CommonCwiseUnaryOps.h" |
| ykuroda | 0:13a5d365ba16 | 106 | # include "../plugins/MatrixCwiseUnaryOps.h" |
| ykuroda | 0:13a5d365ba16 | 107 | # include "../plugins/ArrayCwiseUnaryOps.h" |
| ykuroda | 0:13a5d365ba16 | 108 | # include "../plugins/CommonCwiseBinaryOps.h" |
| ykuroda | 0:13a5d365ba16 | 109 | # include "../plugins/MatrixCwiseBinaryOps.h" |
| ykuroda | 0:13a5d365ba16 | 110 | # include "../plugins/ArrayCwiseBinaryOps.h" |
| ykuroda | 0:13a5d365ba16 | 111 | # ifdef EIGEN_ARRAYBASE_PLUGIN |
| ykuroda | 0:13a5d365ba16 | 112 | # include EIGEN_ARRAYBASE_PLUGIN |
| ykuroda | 0:13a5d365ba16 | 113 | # endif |
| ykuroda | 0:13a5d365ba16 | 114 | #undef EIGEN_CURRENT_STORAGE_BASE_CLASS |
| ykuroda | 0:13a5d365ba16 | 115 | |
| ykuroda | 0:13a5d365ba16 | 116 | /** Special case of the template operator=, in order to prevent the compiler |
| ykuroda | 0:13a5d365ba16 | 117 | * from generating a default operator= (issue hit with g++ 4.1) |
| ykuroda | 0:13a5d365ba16 | 118 | */ |
| ykuroda | 0:13a5d365ba16 | 119 | Derived& operator=(const ArrayBase& other) |
| ykuroda | 0:13a5d365ba16 | 120 | { |
| ykuroda | 0:13a5d365ba16 | 121 | return internal::assign_selector<Derived,Derived>::run(derived(), other.derived()); |
| ykuroda | 0:13a5d365ba16 | 122 | } |
| ykuroda | 0:13a5d365ba16 | 123 | |
| ykuroda | 0:13a5d365ba16 | 124 | Derived& operator+=(const Scalar& scalar) |
| ykuroda | 0:13a5d365ba16 | 125 | { return *this = derived() + scalar; } |
| ykuroda | 0:13a5d365ba16 | 126 | Derived& operator-=(const Scalar& scalar) |
| ykuroda | 0:13a5d365ba16 | 127 | { return *this = derived() - scalar; } |
| ykuroda | 0:13a5d365ba16 | 128 | |
| ykuroda | 0:13a5d365ba16 | 129 | template<typename OtherDerived> |
| ykuroda | 0:13a5d365ba16 | 130 | Derived& operator+=(const ArrayBase<OtherDerived>& other); |
| ykuroda | 0:13a5d365ba16 | 131 | template<typename OtherDerived> |
| ykuroda | 0:13a5d365ba16 | 132 | Derived& operator-=(const ArrayBase<OtherDerived>& other); |
| ykuroda | 0:13a5d365ba16 | 133 | |
| ykuroda | 0:13a5d365ba16 | 134 | template<typename OtherDerived> |
| ykuroda | 0:13a5d365ba16 | 135 | Derived& operator*=(const ArrayBase<OtherDerived>& other); |
| ykuroda | 0:13a5d365ba16 | 136 | |
| ykuroda | 0:13a5d365ba16 | 137 | template<typename OtherDerived> |
| ykuroda | 0:13a5d365ba16 | 138 | Derived& operator/=(const ArrayBase<OtherDerived>& other); |
| ykuroda | 0:13a5d365ba16 | 139 | |
| ykuroda | 0:13a5d365ba16 | 140 | public: |
| ykuroda | 0:13a5d365ba16 | 141 | ArrayBase<Derived>& array() { return *this; } |
| ykuroda | 0:13a5d365ba16 | 142 | const ArrayBase<Derived>& array() const { return *this; } |
| ykuroda | 0:13a5d365ba16 | 143 | |
| ykuroda | 0:13a5d365ba16 | 144 | /** \returns an \link Eigen::MatrixBase Matrix \endlink expression of this array |
| ykuroda | 0:13a5d365ba16 | 145 | * \sa MatrixBase::array() */ |
| ykuroda | 0:13a5d365ba16 | 146 | MatrixWrapper<Derived> matrix() { return derived(); } |
| ykuroda | 0:13a5d365ba16 | 147 | const MatrixWrapper<const Derived> matrix() const { return derived(); } |
| ykuroda | 0:13a5d365ba16 | 148 | |
| ykuroda | 0:13a5d365ba16 | 149 | // template<typename Dest> |
| ykuroda | 0:13a5d365ba16 | 150 | // inline void evalTo(Dest& dst) const { dst = matrix(); } |
| ykuroda | 0:13a5d365ba16 | 151 | |
| ykuroda | 0:13a5d365ba16 | 152 | protected: |
| ykuroda | 0:13a5d365ba16 | 153 | ArrayBase() : Base() {} |
| ykuroda | 0:13a5d365ba16 | 154 | |
| ykuroda | 0:13a5d365ba16 | 155 | private: |
| ykuroda | 0:13a5d365ba16 | 156 | explicit ArrayBase(Index); |
| ykuroda | 0:13a5d365ba16 | 157 | ArrayBase(Index,Index); |
| ykuroda | 0:13a5d365ba16 | 158 | template<typename OtherDerived> explicit ArrayBase(const ArrayBase<OtherDerived>&); |
| ykuroda | 0:13a5d365ba16 | 159 | protected: |
| ykuroda | 0:13a5d365ba16 | 160 | // mixing arrays and matrices is not legal |
| ykuroda | 0:13a5d365ba16 | 161 | template<typename OtherDerived> Derived& operator+=(const MatrixBase<OtherDerived>& ) |
| ykuroda | 0:13a5d365ba16 | 162 | {EIGEN_STATIC_ASSERT(std::ptrdiff_t(sizeof(typename OtherDerived::Scalar))==-1,YOU_CANNOT_MIX_ARRAYS_AND_MATRICES); return *this;} |
| ykuroda | 0:13a5d365ba16 | 163 | // mixing arrays and matrices is not legal |
| ykuroda | 0:13a5d365ba16 | 164 | template<typename OtherDerived> Derived& operator-=(const MatrixBase<OtherDerived>& ) |
| ykuroda | 0:13a5d365ba16 | 165 | {EIGEN_STATIC_ASSERT(std::ptrdiff_t(sizeof(typename OtherDerived::Scalar))==-1,YOU_CANNOT_MIX_ARRAYS_AND_MATRICES); return *this;} |
| ykuroda | 0:13a5d365ba16 | 166 | }; |
| ykuroda | 0:13a5d365ba16 | 167 | |
| ykuroda | 0:13a5d365ba16 | 168 | /** replaces \c *this by \c *this - \a other. |
| ykuroda | 0:13a5d365ba16 | 169 | * |
| ykuroda | 0:13a5d365ba16 | 170 | * \returns a reference to \c *this |
| ykuroda | 0:13a5d365ba16 | 171 | */ |
| ykuroda | 0:13a5d365ba16 | 172 | template<typename Derived> |
| ykuroda | 0:13a5d365ba16 | 173 | template<typename OtherDerived> |
| ykuroda | 0:13a5d365ba16 | 174 | EIGEN_STRONG_INLINE Derived & |
| ykuroda | 0:13a5d365ba16 | 175 | ArrayBase<Derived>::operator-=(const ArrayBase<OtherDerived> &other) |
| ykuroda | 0:13a5d365ba16 | 176 | { |
| ykuroda | 0:13a5d365ba16 | 177 | SelfCwiseBinaryOp<internal::scalar_difference_op<Scalar>, Derived, OtherDerived> tmp(derived()); |
| ykuroda | 0:13a5d365ba16 | 178 | tmp = other.derived(); |
| ykuroda | 0:13a5d365ba16 | 179 | return derived(); |
| ykuroda | 0:13a5d365ba16 | 180 | } |
| ykuroda | 0:13a5d365ba16 | 181 | |
| ykuroda | 0:13a5d365ba16 | 182 | /** replaces \c *this by \c *this + \a other. |
| ykuroda | 0:13a5d365ba16 | 183 | * |
| ykuroda | 0:13a5d365ba16 | 184 | * \returns a reference to \c *this |
| ykuroda | 0:13a5d365ba16 | 185 | */ |
| ykuroda | 0:13a5d365ba16 | 186 | template<typename Derived> |
| ykuroda | 0:13a5d365ba16 | 187 | template<typename OtherDerived> |
| ykuroda | 0:13a5d365ba16 | 188 | EIGEN_STRONG_INLINE Derived & |
| ykuroda | 0:13a5d365ba16 | 189 | ArrayBase<Derived>::operator+=(const ArrayBase<OtherDerived>& other) |
| ykuroda | 0:13a5d365ba16 | 190 | { |
| ykuroda | 0:13a5d365ba16 | 191 | SelfCwiseBinaryOp<internal::scalar_sum_op<Scalar>, Derived, OtherDerived> tmp(derived()); |
| ykuroda | 0:13a5d365ba16 | 192 | tmp = other.derived(); |
| ykuroda | 0:13a5d365ba16 | 193 | return derived(); |
| ykuroda | 0:13a5d365ba16 | 194 | } |
| ykuroda | 0:13a5d365ba16 | 195 | |
| ykuroda | 0:13a5d365ba16 | 196 | /** replaces \c *this by \c *this * \a other coefficient wise. |
| ykuroda | 0:13a5d365ba16 | 197 | * |
| ykuroda | 0:13a5d365ba16 | 198 | * \returns a reference to \c *this |
| ykuroda | 0:13a5d365ba16 | 199 | */ |
| ykuroda | 0:13a5d365ba16 | 200 | template<typename Derived> |
| ykuroda | 0:13a5d365ba16 | 201 | template<typename OtherDerived> |
| ykuroda | 0:13a5d365ba16 | 202 | EIGEN_STRONG_INLINE Derived & |
| ykuroda | 0:13a5d365ba16 | 203 | ArrayBase<Derived>::operator*=(const ArrayBase<OtherDerived>& other) |
| ykuroda | 0:13a5d365ba16 | 204 | { |
| ykuroda | 0:13a5d365ba16 | 205 | SelfCwiseBinaryOp<internal::scalar_product_op<Scalar>, Derived, OtherDerived> tmp(derived()); |
| ykuroda | 0:13a5d365ba16 | 206 | tmp = other.derived(); |
| ykuroda | 0:13a5d365ba16 | 207 | return derived(); |
| ykuroda | 0:13a5d365ba16 | 208 | } |
| ykuroda | 0:13a5d365ba16 | 209 | |
| ykuroda | 0:13a5d365ba16 | 210 | /** replaces \c *this by \c *this / \a other coefficient wise. |
| ykuroda | 0:13a5d365ba16 | 211 | * |
| ykuroda | 0:13a5d365ba16 | 212 | * \returns a reference to \c *this |
| ykuroda | 0:13a5d365ba16 | 213 | */ |
| ykuroda | 0:13a5d365ba16 | 214 | template<typename Derived> |
| ykuroda | 0:13a5d365ba16 | 215 | template<typename OtherDerived> |
| ykuroda | 0:13a5d365ba16 | 216 | EIGEN_STRONG_INLINE Derived & |
| ykuroda | 0:13a5d365ba16 | 217 | ArrayBase<Derived>::operator/=(const ArrayBase<OtherDerived>& other) |
| ykuroda | 0:13a5d365ba16 | 218 | { |
| ykuroda | 0:13a5d365ba16 | 219 | SelfCwiseBinaryOp<internal::scalar_quotient_op<Scalar>, Derived, OtherDerived> tmp(derived()); |
| ykuroda | 0:13a5d365ba16 | 220 | tmp = other.derived(); |
| ykuroda | 0:13a5d365ba16 | 221 | return derived(); |
| ykuroda | 0:13a5d365ba16 | 222 | } |
| ykuroda | 0:13a5d365ba16 | 223 | |
| ykuroda | 0:13a5d365ba16 | 224 | } // end namespace Eigen |
| ykuroda | 0:13a5d365ba16 | 225 | |
| ykuroda | 0:13a5d365ba16 | 226 | #endif // EIGEN_ARRAYBASE_H |