Eigne Matrix Class Library
Dependents: MPC_current_control HydraulicControlBoard_SW AHRS Test_ekf ... more
src/Core/PlainObjectBase.h@1:3b8049da21b8, 2019-09-24 (annotated)
- Committer:
- jsoh91
- Date:
- Tue Sep 24 00:18:23 2019 +0000
- Revision:
- 1:3b8049da21b8
- Parent:
- 0:13a5d365ba16
ignore and revise some of error parts
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) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr> |
ykuroda | 0:13a5d365ba16 | 5 | // Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com> |
ykuroda | 0:13a5d365ba16 | 6 | // |
ykuroda | 0:13a5d365ba16 | 7 | // This Source Code Form is subject to the terms of the Mozilla |
ykuroda | 0:13a5d365ba16 | 8 | // Public License v. 2.0. If a copy of the MPL was not distributed |
ykuroda | 0:13a5d365ba16 | 9 | // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. |
ykuroda | 0:13a5d365ba16 | 10 | |
ykuroda | 0:13a5d365ba16 | 11 | #ifndef EIGEN_DENSESTORAGEBASE_H |
ykuroda | 0:13a5d365ba16 | 12 | #define EIGEN_DENSESTORAGEBASE_H |
ykuroda | 0:13a5d365ba16 | 13 | |
ykuroda | 0:13a5d365ba16 | 14 | #if defined(EIGEN_INITIALIZE_MATRICES_BY_ZERO) |
ykuroda | 0:13a5d365ba16 | 15 | # define EIGEN_INITIALIZE_COEFFS |
ykuroda | 0:13a5d365ba16 | 16 | # define EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED for(int i=0;i<base().size();++i) coeffRef(i)=Scalar(0); |
ykuroda | 0:13a5d365ba16 | 17 | #elif defined(EIGEN_INITIALIZE_MATRICES_BY_NAN) |
ykuroda | 0:13a5d365ba16 | 18 | # define EIGEN_INITIALIZE_COEFFS |
ykuroda | 0:13a5d365ba16 | 19 | # define EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED for(int i=0;i<base().size();++i) coeffRef(i)=std::numeric_limits<Scalar>::quiet_NaN(); |
ykuroda | 0:13a5d365ba16 | 20 | #else |
ykuroda | 0:13a5d365ba16 | 21 | # undef EIGEN_INITIALIZE_COEFFS |
ykuroda | 0:13a5d365ba16 | 22 | # define EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED |
ykuroda | 0:13a5d365ba16 | 23 | #endif |
ykuroda | 0:13a5d365ba16 | 24 | |
ykuroda | 0:13a5d365ba16 | 25 | namespace Eigen { |
ykuroda | 0:13a5d365ba16 | 26 | |
ykuroda | 0:13a5d365ba16 | 27 | namespace internal { |
ykuroda | 0:13a5d365ba16 | 28 | |
ykuroda | 0:13a5d365ba16 | 29 | template<int MaxSizeAtCompileTime> struct check_rows_cols_for_overflow { |
ykuroda | 0:13a5d365ba16 | 30 | template<typename Index> |
ykuroda | 0:13a5d365ba16 | 31 | static EIGEN_ALWAYS_INLINE void run(Index, Index) |
ykuroda | 0:13a5d365ba16 | 32 | { |
ykuroda | 0:13a5d365ba16 | 33 | } |
ykuroda | 0:13a5d365ba16 | 34 | }; |
ykuroda | 0:13a5d365ba16 | 35 | |
ykuroda | 0:13a5d365ba16 | 36 | template<> struct check_rows_cols_for_overflow<Dynamic> { |
ykuroda | 0:13a5d365ba16 | 37 | template<typename Index> |
ykuroda | 0:13a5d365ba16 | 38 | static EIGEN_ALWAYS_INLINE void run(Index rows, Index cols) |
ykuroda | 0:13a5d365ba16 | 39 | { |
ykuroda | 0:13a5d365ba16 | 40 | // http://hg.mozilla.org/mozilla-central/file/6c8a909977d3/xpcom/ds/CheckedInt.h#l242 |
ykuroda | 0:13a5d365ba16 | 41 | // we assume Index is signed |
ykuroda | 0:13a5d365ba16 | 42 | Index max_index = (size_t(1) << (8 * sizeof(Index) - 1)) - 1; // assume Index is signed |
ykuroda | 0:13a5d365ba16 | 43 | bool error = (rows == 0 || cols == 0) ? false |
ykuroda | 0:13a5d365ba16 | 44 | : (rows > max_index / cols); |
ykuroda | 0:13a5d365ba16 | 45 | if (error) |
ykuroda | 0:13a5d365ba16 | 46 | throw_std_bad_alloc(); |
ykuroda | 0:13a5d365ba16 | 47 | } |
ykuroda | 0:13a5d365ba16 | 48 | }; |
ykuroda | 0:13a5d365ba16 | 49 | |
ykuroda | 0:13a5d365ba16 | 50 | template <typename Derived, |
ykuroda | 0:13a5d365ba16 | 51 | typename OtherDerived = Derived, |
ykuroda | 0:13a5d365ba16 | 52 | bool IsVector = bool(Derived::IsVectorAtCompileTime) && bool(OtherDerived::IsVectorAtCompileTime)> |
ykuroda | 0:13a5d365ba16 | 53 | struct conservative_resize_like_impl; |
ykuroda | 0:13a5d365ba16 | 54 | |
ykuroda | 0:13a5d365ba16 | 55 | template<typename MatrixTypeA, typename MatrixTypeB, bool SwapPointers> struct matrix_swap_impl; |
ykuroda | 0:13a5d365ba16 | 56 | |
ykuroda | 0:13a5d365ba16 | 57 | } // end namespace internal |
ykuroda | 0:13a5d365ba16 | 58 | |
ykuroda | 0:13a5d365ba16 | 59 | /** \class PlainObjectBase |
ykuroda | 0:13a5d365ba16 | 60 | * \brief %Dense storage base class for matrices and arrays. |
ykuroda | 0:13a5d365ba16 | 61 | * |
ykuroda | 0:13a5d365ba16 | 62 | * This class can be extended with the help of the plugin mechanism described on the page |
ykuroda | 0:13a5d365ba16 | 63 | * \ref TopicCustomizingEigen by defining the preprocessor symbol \c EIGEN_PLAINOBJECTBASE_PLUGIN. |
ykuroda | 0:13a5d365ba16 | 64 | * |
ykuroda | 0:13a5d365ba16 | 65 | * \sa \ref TopicClassHierarchy |
ykuroda | 0:13a5d365ba16 | 66 | */ |
ykuroda | 0:13a5d365ba16 | 67 | #ifdef EIGEN_PARSED_BY_DOXYGEN |
ykuroda | 0:13a5d365ba16 | 68 | namespace internal { |
ykuroda | 0:13a5d365ba16 | 69 | |
ykuroda | 0:13a5d365ba16 | 70 | // this is a warkaround to doxygen not being able to understand the inheritence logic |
ykuroda | 0:13a5d365ba16 | 71 | // when it is hidden by the dense_xpr_base helper struct. |
ykuroda | 0:13a5d365ba16 | 72 | template<typename Derived> struct dense_xpr_base_dispatcher_for_doxygen;// : public MatrixBase<Derived> {}; |
ykuroda | 0:13a5d365ba16 | 73 | /** This class is just a workaround for Doxygen and it does not not actually exist. */ |
ykuroda | 0:13a5d365ba16 | 74 | template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols> |
ykuroda | 0:13a5d365ba16 | 75 | struct dense_xpr_base_dispatcher_for_doxygen<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> > |
ykuroda | 0:13a5d365ba16 | 76 | : public MatrixBase<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> > {}; |
ykuroda | 0:13a5d365ba16 | 77 | /** This class is just a workaround for Doxygen and it does not not actually exist. */ |
ykuroda | 0:13a5d365ba16 | 78 | template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols> |
ykuroda | 0:13a5d365ba16 | 79 | struct dense_xpr_base_dispatcher_for_doxygen<Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> > |
ykuroda | 0:13a5d365ba16 | 80 | : public ArrayBase<Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> > {}; |
ykuroda | 0:13a5d365ba16 | 81 | |
ykuroda | 0:13a5d365ba16 | 82 | } // namespace internal |
ykuroda | 0:13a5d365ba16 | 83 | |
ykuroda | 0:13a5d365ba16 | 84 | template<typename Derived> |
ykuroda | 0:13a5d365ba16 | 85 | class PlainObjectBase : public internal::dense_xpr_base_dispatcher_for_doxygen<Derived> |
ykuroda | 0:13a5d365ba16 | 86 | #else |
ykuroda | 0:13a5d365ba16 | 87 | template<typename Derived> |
ykuroda | 0:13a5d365ba16 | 88 | class PlainObjectBase : public internal::dense_xpr_base<Derived>::type |
ykuroda | 0:13a5d365ba16 | 89 | #endif |
ykuroda | 0:13a5d365ba16 | 90 | { |
ykuroda | 0:13a5d365ba16 | 91 | public: |
ykuroda | 0:13a5d365ba16 | 92 | enum { Options = internal::traits<Derived>::Options }; |
ykuroda | 0:13a5d365ba16 | 93 | typedef typename internal::dense_xpr_base<Derived>::type Base; |
ykuroda | 0:13a5d365ba16 | 94 | |
ykuroda | 0:13a5d365ba16 | 95 | typedef typename internal::traits<Derived>::StorageKind StorageKind; |
ykuroda | 0:13a5d365ba16 | 96 | typedef typename internal::traits<Derived>::Index Index; |
ykuroda | 0:13a5d365ba16 | 97 | typedef typename internal::traits<Derived>::Scalar Scalar; |
ykuroda | 0:13a5d365ba16 | 98 | typedef typename internal::packet_traits<Scalar>::type PacketScalar; |
ykuroda | 0:13a5d365ba16 | 99 | typedef typename NumTraits<Scalar>::Real RealScalar; |
ykuroda | 0:13a5d365ba16 | 100 | typedef Derived DenseType; |
ykuroda | 0:13a5d365ba16 | 101 | |
ykuroda | 0:13a5d365ba16 | 102 | using Base::RowsAtCompileTime; |
ykuroda | 0:13a5d365ba16 | 103 | using Base::ColsAtCompileTime; |
ykuroda | 0:13a5d365ba16 | 104 | using Base::SizeAtCompileTime; |
ykuroda | 0:13a5d365ba16 | 105 | using Base::MaxRowsAtCompileTime; |
ykuroda | 0:13a5d365ba16 | 106 | using Base::MaxColsAtCompileTime; |
ykuroda | 0:13a5d365ba16 | 107 | using Base::MaxSizeAtCompileTime; |
ykuroda | 0:13a5d365ba16 | 108 | using Base::IsVectorAtCompileTime; |
ykuroda | 0:13a5d365ba16 | 109 | using Base::Flags; |
ykuroda | 0:13a5d365ba16 | 110 | |
ykuroda | 0:13a5d365ba16 | 111 | template<typename PlainObjectType, int MapOptions, typename StrideType> friend class Eigen::Map; |
ykuroda | 0:13a5d365ba16 | 112 | friend class Eigen::Map<Derived, Unaligned>; |
ykuroda | 0:13a5d365ba16 | 113 | typedef Eigen::Map<Derived, Unaligned> MapType; |
ykuroda | 0:13a5d365ba16 | 114 | friend class Eigen::Map<const Derived, Unaligned>; |
ykuroda | 0:13a5d365ba16 | 115 | typedef const Eigen::Map<const Derived, Unaligned> ConstMapType; |
ykuroda | 0:13a5d365ba16 | 116 | friend class Eigen::Map<Derived, Aligned>; |
ykuroda | 0:13a5d365ba16 | 117 | typedef Eigen::Map<Derived, Aligned> AlignedMapType; |
ykuroda | 0:13a5d365ba16 | 118 | friend class Eigen::Map<const Derived, Aligned>; |
ykuroda | 0:13a5d365ba16 | 119 | typedef const Eigen::Map<const Derived, Aligned> ConstAlignedMapType; |
ykuroda | 0:13a5d365ba16 | 120 | template<typename StrideType> struct StridedMapType { typedef Eigen::Map<Derived, Unaligned, StrideType> type; }; |
ykuroda | 0:13a5d365ba16 | 121 | template<typename StrideType> struct StridedConstMapType { typedef Eigen::Map<const Derived, Unaligned, StrideType> type; }; |
ykuroda | 0:13a5d365ba16 | 122 | template<typename StrideType> struct StridedAlignedMapType { typedef Eigen::Map<Derived, Aligned, StrideType> type; }; |
ykuroda | 0:13a5d365ba16 | 123 | template<typename StrideType> struct StridedConstAlignedMapType { typedef Eigen::Map<const Derived, Aligned, StrideType> type; }; |
ykuroda | 0:13a5d365ba16 | 124 | |
ykuroda | 0:13a5d365ba16 | 125 | protected: |
ykuroda | 0:13a5d365ba16 | 126 | DenseStorage<Scalar, Base::MaxSizeAtCompileTime, Base::RowsAtCompileTime, Base::ColsAtCompileTime, Options> m_storage; |
ykuroda | 0:13a5d365ba16 | 127 | |
ykuroda | 0:13a5d365ba16 | 128 | public: |
ykuroda | 0:13a5d365ba16 | 129 | enum { NeedsToAlign = SizeAtCompileTime != Dynamic && (internal::traits<Derived>::Flags & AlignedBit) != 0 }; |
ykuroda | 0:13a5d365ba16 | 130 | EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(NeedsToAlign) |
ykuroda | 0:13a5d365ba16 | 131 | |
ykuroda | 0:13a5d365ba16 | 132 | Base& base() { return *static_cast<Base*>(this); } |
ykuroda | 0:13a5d365ba16 | 133 | const Base& base() const { return *static_cast<const Base*>(this); } |
ykuroda | 0:13a5d365ba16 | 134 | |
ykuroda | 0:13a5d365ba16 | 135 | EIGEN_STRONG_INLINE Index rows() const { return m_storage.rows(); } |
ykuroda | 0:13a5d365ba16 | 136 | EIGEN_STRONG_INLINE Index cols() const { return m_storage.cols(); } |
ykuroda | 0:13a5d365ba16 | 137 | |
ykuroda | 0:13a5d365ba16 | 138 | EIGEN_STRONG_INLINE const Scalar& coeff(Index rowId, Index colId) const |
ykuroda | 0:13a5d365ba16 | 139 | { |
ykuroda | 0:13a5d365ba16 | 140 | if(Flags & RowMajorBit) |
ykuroda | 0:13a5d365ba16 | 141 | return m_storage.data()[colId + rowId * m_storage.cols()]; |
ykuroda | 0:13a5d365ba16 | 142 | else // column-major |
ykuroda | 0:13a5d365ba16 | 143 | return m_storage.data()[rowId + colId * m_storage.rows()]; |
ykuroda | 0:13a5d365ba16 | 144 | } |
ykuroda | 0:13a5d365ba16 | 145 | |
ykuroda | 0:13a5d365ba16 | 146 | EIGEN_STRONG_INLINE const Scalar& coeff(Index index) const |
ykuroda | 0:13a5d365ba16 | 147 | { |
ykuroda | 0:13a5d365ba16 | 148 | return m_storage.data()[index]; |
ykuroda | 0:13a5d365ba16 | 149 | } |
ykuroda | 0:13a5d365ba16 | 150 | |
ykuroda | 0:13a5d365ba16 | 151 | EIGEN_STRONG_INLINE Scalar& coeffRef(Index rowId, Index colId) |
ykuroda | 0:13a5d365ba16 | 152 | { |
ykuroda | 0:13a5d365ba16 | 153 | if(Flags & RowMajorBit) |
ykuroda | 0:13a5d365ba16 | 154 | return m_storage.data()[colId + rowId * m_storage.cols()]; |
ykuroda | 0:13a5d365ba16 | 155 | else // column-major |
ykuroda | 0:13a5d365ba16 | 156 | return m_storage.data()[rowId + colId * m_storage.rows()]; |
ykuroda | 0:13a5d365ba16 | 157 | } |
ykuroda | 0:13a5d365ba16 | 158 | |
ykuroda | 0:13a5d365ba16 | 159 | EIGEN_STRONG_INLINE Scalar& coeffRef(Index index) |
ykuroda | 0:13a5d365ba16 | 160 | { |
ykuroda | 0:13a5d365ba16 | 161 | return m_storage.data()[index]; |
ykuroda | 0:13a5d365ba16 | 162 | } |
ykuroda | 0:13a5d365ba16 | 163 | |
ykuroda | 0:13a5d365ba16 | 164 | EIGEN_STRONG_INLINE const Scalar& coeffRef(Index rowId, Index colId) const |
ykuroda | 0:13a5d365ba16 | 165 | { |
ykuroda | 0:13a5d365ba16 | 166 | if(Flags & RowMajorBit) |
ykuroda | 0:13a5d365ba16 | 167 | return m_storage.data()[colId + rowId * m_storage.cols()]; |
ykuroda | 0:13a5d365ba16 | 168 | else // column-major |
ykuroda | 0:13a5d365ba16 | 169 | return m_storage.data()[rowId + colId * m_storage.rows()]; |
ykuroda | 0:13a5d365ba16 | 170 | } |
ykuroda | 0:13a5d365ba16 | 171 | |
ykuroda | 0:13a5d365ba16 | 172 | EIGEN_STRONG_INLINE const Scalar& coeffRef(Index index) const |
ykuroda | 0:13a5d365ba16 | 173 | { |
ykuroda | 0:13a5d365ba16 | 174 | return m_storage.data()[index]; |
ykuroda | 0:13a5d365ba16 | 175 | } |
ykuroda | 0:13a5d365ba16 | 176 | |
ykuroda | 0:13a5d365ba16 | 177 | /** \internal */ |
ykuroda | 0:13a5d365ba16 | 178 | template<int LoadMode> |
ykuroda | 0:13a5d365ba16 | 179 | EIGEN_STRONG_INLINE PacketScalar packet(Index rowId, Index colId) const |
ykuroda | 0:13a5d365ba16 | 180 | { |
ykuroda | 0:13a5d365ba16 | 181 | return internal::ploadt<PacketScalar, LoadMode> |
ykuroda | 0:13a5d365ba16 | 182 | (m_storage.data() + (Flags & RowMajorBit |
ykuroda | 0:13a5d365ba16 | 183 | ? colId + rowId * m_storage.cols() |
ykuroda | 0:13a5d365ba16 | 184 | : rowId + colId * m_storage.rows())); |
ykuroda | 0:13a5d365ba16 | 185 | } |
ykuroda | 0:13a5d365ba16 | 186 | |
ykuroda | 0:13a5d365ba16 | 187 | /** \internal */ |
ykuroda | 0:13a5d365ba16 | 188 | template<int LoadMode> |
ykuroda | 0:13a5d365ba16 | 189 | EIGEN_STRONG_INLINE PacketScalar packet(Index index) const |
ykuroda | 0:13a5d365ba16 | 190 | { |
ykuroda | 0:13a5d365ba16 | 191 | return internal::ploadt<PacketScalar, LoadMode>(m_storage.data() + index); |
ykuroda | 0:13a5d365ba16 | 192 | } |
ykuroda | 0:13a5d365ba16 | 193 | |
ykuroda | 0:13a5d365ba16 | 194 | /** \internal */ |
ykuroda | 0:13a5d365ba16 | 195 | template<int StoreMode> |
ykuroda | 0:13a5d365ba16 | 196 | EIGEN_STRONG_INLINE void writePacket(Index rowId, Index colId, const PacketScalar& val) |
ykuroda | 0:13a5d365ba16 | 197 | { |
ykuroda | 0:13a5d365ba16 | 198 | internal::pstoret<Scalar, PacketScalar, StoreMode> |
ykuroda | 0:13a5d365ba16 | 199 | (m_storage.data() + (Flags & RowMajorBit |
ykuroda | 0:13a5d365ba16 | 200 | ? colId + rowId * m_storage.cols() |
ykuroda | 0:13a5d365ba16 | 201 | : rowId + colId * m_storage.rows()), val); |
ykuroda | 0:13a5d365ba16 | 202 | } |
ykuroda | 0:13a5d365ba16 | 203 | |
ykuroda | 0:13a5d365ba16 | 204 | /** \internal */ |
ykuroda | 0:13a5d365ba16 | 205 | template<int StoreMode> |
ykuroda | 0:13a5d365ba16 | 206 | EIGEN_STRONG_INLINE void writePacket(Index index, const PacketScalar& val) |
ykuroda | 0:13a5d365ba16 | 207 | { |
ykuroda | 0:13a5d365ba16 | 208 | internal::pstoret<Scalar, PacketScalar, StoreMode>(m_storage.data() + index, val); |
ykuroda | 0:13a5d365ba16 | 209 | } |
ykuroda | 0:13a5d365ba16 | 210 | |
ykuroda | 0:13a5d365ba16 | 211 | /** \returns a const pointer to the data array of this matrix */ |
ykuroda | 0:13a5d365ba16 | 212 | EIGEN_STRONG_INLINE const Scalar *data() const |
ykuroda | 0:13a5d365ba16 | 213 | { return m_storage.data(); } |
ykuroda | 0:13a5d365ba16 | 214 | |
ykuroda | 0:13a5d365ba16 | 215 | /** \returns a pointer to the data array of this matrix */ |
ykuroda | 0:13a5d365ba16 | 216 | EIGEN_STRONG_INLINE Scalar *data() |
ykuroda | 0:13a5d365ba16 | 217 | { return m_storage.data(); } |
ykuroda | 0:13a5d365ba16 | 218 | |
ykuroda | 0:13a5d365ba16 | 219 | /** Resizes \c *this to a \a rows x \a cols matrix. |
ykuroda | 0:13a5d365ba16 | 220 | * |
ykuroda | 0:13a5d365ba16 | 221 | * This method is intended for dynamic-size matrices, although it is legal to call it on any |
ykuroda | 0:13a5d365ba16 | 222 | * matrix as long as fixed dimensions are left unchanged. If you only want to change the number |
ykuroda | 0:13a5d365ba16 | 223 | * of rows and/or of columns, you can use resize(NoChange_t, Index), resize(Index, NoChange_t). |
ykuroda | 0:13a5d365ba16 | 224 | * |
ykuroda | 0:13a5d365ba16 | 225 | * If the current number of coefficients of \c *this exactly matches the |
ykuroda | 0:13a5d365ba16 | 226 | * product \a rows * \a cols, then no memory allocation is performed and |
ykuroda | 0:13a5d365ba16 | 227 | * the current values are left unchanged. In all other cases, including |
ykuroda | 0:13a5d365ba16 | 228 | * shrinking, the data is reallocated and all previous values are lost. |
ykuroda | 0:13a5d365ba16 | 229 | * |
ykuroda | 0:13a5d365ba16 | 230 | * Example: \include Matrix_resize_int_int.cpp |
ykuroda | 0:13a5d365ba16 | 231 | * Output: \verbinclude Matrix_resize_int_int.out |
ykuroda | 0:13a5d365ba16 | 232 | * |
ykuroda | 0:13a5d365ba16 | 233 | * \sa resize(Index) for vectors, resize(NoChange_t, Index), resize(Index, NoChange_t) |
ykuroda | 0:13a5d365ba16 | 234 | */ |
ykuroda | 0:13a5d365ba16 | 235 | EIGEN_STRONG_INLINE void resize(Index nbRows, Index nbCols) |
ykuroda | 0:13a5d365ba16 | 236 | { |
ykuroda | 0:13a5d365ba16 | 237 | eigen_assert( EIGEN_IMPLIES(RowsAtCompileTime!=Dynamic,nbRows==RowsAtCompileTime) |
ykuroda | 0:13a5d365ba16 | 238 | && EIGEN_IMPLIES(ColsAtCompileTime!=Dynamic,nbCols==ColsAtCompileTime) |
ykuroda | 0:13a5d365ba16 | 239 | && EIGEN_IMPLIES(RowsAtCompileTime==Dynamic && MaxRowsAtCompileTime!=Dynamic,nbRows<=MaxRowsAtCompileTime) |
ykuroda | 0:13a5d365ba16 | 240 | && EIGEN_IMPLIES(ColsAtCompileTime==Dynamic && MaxColsAtCompileTime!=Dynamic,nbCols<=MaxColsAtCompileTime) |
ykuroda | 0:13a5d365ba16 | 241 | && nbRows>=0 && nbCols>=0 && "Invalid sizes when resizing a matrix or array."); |
ykuroda | 0:13a5d365ba16 | 242 | internal::check_rows_cols_for_overflow<MaxSizeAtCompileTime>::run(nbRows, nbCols); |
ykuroda | 0:13a5d365ba16 | 243 | #ifdef EIGEN_INITIALIZE_COEFFS |
ykuroda | 0:13a5d365ba16 | 244 | Index size = nbRows*nbCols; |
ykuroda | 0:13a5d365ba16 | 245 | bool size_changed = size != this->size(); |
ykuroda | 0:13a5d365ba16 | 246 | m_storage.resize(size, nbRows, nbCols); |
ykuroda | 0:13a5d365ba16 | 247 | if(size_changed) EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED |
ykuroda | 0:13a5d365ba16 | 248 | #else |
ykuroda | 0:13a5d365ba16 | 249 | internal::check_rows_cols_for_overflow<MaxSizeAtCompileTime>::run(nbRows, nbCols); |
ykuroda | 0:13a5d365ba16 | 250 | m_storage.resize(nbRows*nbCols, nbRows, nbCols); |
ykuroda | 0:13a5d365ba16 | 251 | #endif |
ykuroda | 0:13a5d365ba16 | 252 | } |
ykuroda | 0:13a5d365ba16 | 253 | |
ykuroda | 0:13a5d365ba16 | 254 | /** Resizes \c *this to a vector of length \a size |
ykuroda | 0:13a5d365ba16 | 255 | * |
ykuroda | 0:13a5d365ba16 | 256 | * \only_for_vectors. This method does not work for |
ykuroda | 0:13a5d365ba16 | 257 | * partially dynamic matrices when the static dimension is anything other |
ykuroda | 0:13a5d365ba16 | 258 | * than 1. For example it will not work with Matrix<double, 2, Dynamic>. |
ykuroda | 0:13a5d365ba16 | 259 | * |
ykuroda | 0:13a5d365ba16 | 260 | * Example: \include Matrix_resize_int.cpp |
ykuroda | 0:13a5d365ba16 | 261 | * Output: \verbinclude Matrix_resize_int.out |
ykuroda | 0:13a5d365ba16 | 262 | * |
ykuroda | 0:13a5d365ba16 | 263 | * \sa resize(Index,Index), resize(NoChange_t, Index), resize(Index, NoChange_t) |
ykuroda | 0:13a5d365ba16 | 264 | */ |
ykuroda | 0:13a5d365ba16 | 265 | inline void resize(Index size) |
ykuroda | 0:13a5d365ba16 | 266 | { |
ykuroda | 0:13a5d365ba16 | 267 | EIGEN_STATIC_ASSERT_VECTOR_ONLY(PlainObjectBase) |
ykuroda | 0:13a5d365ba16 | 268 | eigen_assert(((SizeAtCompileTime == Dynamic && (MaxSizeAtCompileTime==Dynamic || size<=MaxSizeAtCompileTime)) || SizeAtCompileTime == size) && size>=0); |
ykuroda | 0:13a5d365ba16 | 269 | #ifdef EIGEN_INITIALIZE_COEFFS |
ykuroda | 0:13a5d365ba16 | 270 | bool size_changed = size != this->size(); |
ykuroda | 0:13a5d365ba16 | 271 | #endif |
ykuroda | 0:13a5d365ba16 | 272 | if(RowsAtCompileTime == 1) |
ykuroda | 0:13a5d365ba16 | 273 | m_storage.resize(size, 1, size); |
ykuroda | 0:13a5d365ba16 | 274 | else |
ykuroda | 0:13a5d365ba16 | 275 | m_storage.resize(size, size, 1); |
ykuroda | 0:13a5d365ba16 | 276 | #ifdef EIGEN_INITIALIZE_COEFFS |
ykuroda | 0:13a5d365ba16 | 277 | if(size_changed) EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED |
ykuroda | 0:13a5d365ba16 | 278 | #endif |
ykuroda | 0:13a5d365ba16 | 279 | } |
ykuroda | 0:13a5d365ba16 | 280 | |
ykuroda | 0:13a5d365ba16 | 281 | /** Resizes the matrix, changing only the number of columns. For the parameter of type NoChange_t, just pass the special value \c NoChange |
ykuroda | 0:13a5d365ba16 | 282 | * as in the example below. |
ykuroda | 0:13a5d365ba16 | 283 | * |
ykuroda | 0:13a5d365ba16 | 284 | * Example: \include Matrix_resize_NoChange_int.cpp |
ykuroda | 0:13a5d365ba16 | 285 | * Output: \verbinclude Matrix_resize_NoChange_int.out |
ykuroda | 0:13a5d365ba16 | 286 | * |
ykuroda | 0:13a5d365ba16 | 287 | * \sa resize(Index,Index) |
ykuroda | 0:13a5d365ba16 | 288 | */ |
ykuroda | 0:13a5d365ba16 | 289 | inline void resize(NoChange_t, Index nbCols) |
ykuroda | 0:13a5d365ba16 | 290 | { |
ykuroda | 0:13a5d365ba16 | 291 | resize(rows(), nbCols); |
ykuroda | 0:13a5d365ba16 | 292 | } |
ykuroda | 0:13a5d365ba16 | 293 | |
ykuroda | 0:13a5d365ba16 | 294 | /** Resizes the matrix, changing only the number of rows. For the parameter of type NoChange_t, just pass the special value \c NoChange |
ykuroda | 0:13a5d365ba16 | 295 | * as in the example below. |
ykuroda | 0:13a5d365ba16 | 296 | * |
ykuroda | 0:13a5d365ba16 | 297 | * Example: \include Matrix_resize_int_NoChange.cpp |
ykuroda | 0:13a5d365ba16 | 298 | * Output: \verbinclude Matrix_resize_int_NoChange.out |
ykuroda | 0:13a5d365ba16 | 299 | * |
ykuroda | 0:13a5d365ba16 | 300 | * \sa resize(Index,Index) |
ykuroda | 0:13a5d365ba16 | 301 | */ |
ykuroda | 0:13a5d365ba16 | 302 | inline void resize(Index nbRows, NoChange_t) |
ykuroda | 0:13a5d365ba16 | 303 | { |
ykuroda | 0:13a5d365ba16 | 304 | resize(nbRows, cols()); |
ykuroda | 0:13a5d365ba16 | 305 | } |
ykuroda | 0:13a5d365ba16 | 306 | |
ykuroda | 0:13a5d365ba16 | 307 | /** Resizes \c *this to have the same dimensions as \a other. |
ykuroda | 0:13a5d365ba16 | 308 | * Takes care of doing all the checking that's needed. |
ykuroda | 0:13a5d365ba16 | 309 | * |
ykuroda | 0:13a5d365ba16 | 310 | * Note that copying a row-vector into a vector (and conversely) is allowed. |
ykuroda | 0:13a5d365ba16 | 311 | * The resizing, if any, is then done in the appropriate way so that row-vectors |
ykuroda | 0:13a5d365ba16 | 312 | * remain row-vectors and vectors remain vectors. |
ykuroda | 0:13a5d365ba16 | 313 | */ |
ykuroda | 0:13a5d365ba16 | 314 | template<typename OtherDerived> |
ykuroda | 0:13a5d365ba16 | 315 | EIGEN_STRONG_INLINE void resizeLike(const EigenBase<OtherDerived>& _other) |
ykuroda | 0:13a5d365ba16 | 316 | { |
ykuroda | 0:13a5d365ba16 | 317 | const OtherDerived& other = _other.derived(); |
ykuroda | 0:13a5d365ba16 | 318 | internal::check_rows_cols_for_overflow<MaxSizeAtCompileTime>::run(other.rows(), other.cols()); |
ykuroda | 0:13a5d365ba16 | 319 | const Index othersize = other.rows()*other.cols(); |
ykuroda | 0:13a5d365ba16 | 320 | if(RowsAtCompileTime == 1) |
ykuroda | 0:13a5d365ba16 | 321 | { |
ykuroda | 0:13a5d365ba16 | 322 | eigen_assert(other.rows() == 1 || other.cols() == 1); |
ykuroda | 0:13a5d365ba16 | 323 | resize(1, othersize); |
ykuroda | 0:13a5d365ba16 | 324 | } |
ykuroda | 0:13a5d365ba16 | 325 | else if(ColsAtCompileTime == 1) |
ykuroda | 0:13a5d365ba16 | 326 | { |
ykuroda | 0:13a5d365ba16 | 327 | eigen_assert(other.rows() == 1 || other.cols() == 1); |
ykuroda | 0:13a5d365ba16 | 328 | resize(othersize, 1); |
ykuroda | 0:13a5d365ba16 | 329 | } |
ykuroda | 0:13a5d365ba16 | 330 | else resize(other.rows(), other.cols()); |
ykuroda | 0:13a5d365ba16 | 331 | } |
ykuroda | 0:13a5d365ba16 | 332 | |
ykuroda | 0:13a5d365ba16 | 333 | /** Resizes the matrix to \a rows x \a cols while leaving old values untouched. |
ykuroda | 0:13a5d365ba16 | 334 | * |
ykuroda | 0:13a5d365ba16 | 335 | * The method is intended for matrices of dynamic size. If you only want to change the number |
ykuroda | 0:13a5d365ba16 | 336 | * of rows and/or of columns, you can use conservativeResize(NoChange_t, Index) or |
ykuroda | 0:13a5d365ba16 | 337 | * conservativeResize(Index, NoChange_t). |
ykuroda | 0:13a5d365ba16 | 338 | * |
ykuroda | 0:13a5d365ba16 | 339 | * Matrices are resized relative to the top-left element. In case values need to be |
ykuroda | 0:13a5d365ba16 | 340 | * appended to the matrix they will be uninitialized. |
ykuroda | 0:13a5d365ba16 | 341 | */ |
ykuroda | 0:13a5d365ba16 | 342 | EIGEN_STRONG_INLINE void conservativeResize(Index nbRows, Index nbCols) |
ykuroda | 0:13a5d365ba16 | 343 | { |
ykuroda | 0:13a5d365ba16 | 344 | internal::conservative_resize_like_impl<Derived>::run(*this, nbRows, nbCols); |
ykuroda | 0:13a5d365ba16 | 345 | } |
ykuroda | 0:13a5d365ba16 | 346 | |
ykuroda | 0:13a5d365ba16 | 347 | /** Resizes the matrix to \a rows x \a cols while leaving old values untouched. |
ykuroda | 0:13a5d365ba16 | 348 | * |
ykuroda | 0:13a5d365ba16 | 349 | * As opposed to conservativeResize(Index rows, Index cols), this version leaves |
ykuroda | 0:13a5d365ba16 | 350 | * the number of columns unchanged. |
ykuroda | 0:13a5d365ba16 | 351 | * |
ykuroda | 0:13a5d365ba16 | 352 | * In case the matrix is growing, new rows will be uninitialized. |
ykuroda | 0:13a5d365ba16 | 353 | */ |
ykuroda | 0:13a5d365ba16 | 354 | EIGEN_STRONG_INLINE void conservativeResize(Index nbRows, NoChange_t) |
ykuroda | 0:13a5d365ba16 | 355 | { |
ykuroda | 0:13a5d365ba16 | 356 | // Note: see the comment in conservativeResize(Index,Index) |
ykuroda | 0:13a5d365ba16 | 357 | conservativeResize(nbRows, cols()); |
ykuroda | 0:13a5d365ba16 | 358 | } |
ykuroda | 0:13a5d365ba16 | 359 | |
ykuroda | 0:13a5d365ba16 | 360 | /** Resizes the matrix to \a rows x \a cols while leaving old values untouched. |
ykuroda | 0:13a5d365ba16 | 361 | * |
ykuroda | 0:13a5d365ba16 | 362 | * As opposed to conservativeResize(Index rows, Index cols), this version leaves |
ykuroda | 0:13a5d365ba16 | 363 | * the number of rows unchanged. |
ykuroda | 0:13a5d365ba16 | 364 | * |
ykuroda | 0:13a5d365ba16 | 365 | * In case the matrix is growing, new columns will be uninitialized. |
ykuroda | 0:13a5d365ba16 | 366 | */ |
ykuroda | 0:13a5d365ba16 | 367 | EIGEN_STRONG_INLINE void conservativeResize(NoChange_t, Index nbCols) |
ykuroda | 0:13a5d365ba16 | 368 | { |
ykuroda | 0:13a5d365ba16 | 369 | // Note: see the comment in conservativeResize(Index,Index) |
ykuroda | 0:13a5d365ba16 | 370 | conservativeResize(rows(), nbCols); |
ykuroda | 0:13a5d365ba16 | 371 | } |
ykuroda | 0:13a5d365ba16 | 372 | |
ykuroda | 0:13a5d365ba16 | 373 | /** Resizes the vector to \a size while retaining old values. |
ykuroda | 0:13a5d365ba16 | 374 | * |
ykuroda | 0:13a5d365ba16 | 375 | * \only_for_vectors. This method does not work for |
ykuroda | 0:13a5d365ba16 | 376 | * partially dynamic matrices when the static dimension is anything other |
ykuroda | 0:13a5d365ba16 | 377 | * than 1. For example it will not work with Matrix<double, 2, Dynamic>. |
ykuroda | 0:13a5d365ba16 | 378 | * |
ykuroda | 0:13a5d365ba16 | 379 | * When values are appended, they will be uninitialized. |
ykuroda | 0:13a5d365ba16 | 380 | */ |
ykuroda | 0:13a5d365ba16 | 381 | EIGEN_STRONG_INLINE void conservativeResize(Index size) |
ykuroda | 0:13a5d365ba16 | 382 | { |
ykuroda | 0:13a5d365ba16 | 383 | internal::conservative_resize_like_impl<Derived>::run(*this, size); |
ykuroda | 0:13a5d365ba16 | 384 | } |
ykuroda | 0:13a5d365ba16 | 385 | |
ykuroda | 0:13a5d365ba16 | 386 | /** Resizes the matrix to \a rows x \a cols of \c other, while leaving old values untouched. |
ykuroda | 0:13a5d365ba16 | 387 | * |
ykuroda | 0:13a5d365ba16 | 388 | * The method is intended for matrices of dynamic size. If you only want to change the number |
ykuroda | 0:13a5d365ba16 | 389 | * of rows and/or of columns, you can use conservativeResize(NoChange_t, Index) or |
ykuroda | 0:13a5d365ba16 | 390 | * conservativeResize(Index, NoChange_t). |
ykuroda | 0:13a5d365ba16 | 391 | * |
ykuroda | 0:13a5d365ba16 | 392 | * Matrices are resized relative to the top-left element. In case values need to be |
ykuroda | 0:13a5d365ba16 | 393 | * appended to the matrix they will copied from \c other. |
ykuroda | 0:13a5d365ba16 | 394 | */ |
ykuroda | 0:13a5d365ba16 | 395 | template<typename OtherDerived> |
ykuroda | 0:13a5d365ba16 | 396 | EIGEN_STRONG_INLINE void conservativeResizeLike(const DenseBase<OtherDerived>& other) |
ykuroda | 0:13a5d365ba16 | 397 | { |
ykuroda | 0:13a5d365ba16 | 398 | internal::conservative_resize_like_impl<Derived,OtherDerived>::run(*this, other); |
ykuroda | 0:13a5d365ba16 | 399 | } |
ykuroda | 0:13a5d365ba16 | 400 | |
ykuroda | 0:13a5d365ba16 | 401 | /** This is a special case of the templated operator=. Its purpose is to |
ykuroda | 0:13a5d365ba16 | 402 | * prevent a default operator= from hiding the templated operator=. |
ykuroda | 0:13a5d365ba16 | 403 | */ |
ykuroda | 0:13a5d365ba16 | 404 | EIGEN_STRONG_INLINE Derived& operator=(const PlainObjectBase& other) |
ykuroda | 0:13a5d365ba16 | 405 | { |
ykuroda | 0:13a5d365ba16 | 406 | return _set(other); |
ykuroda | 0:13a5d365ba16 | 407 | } |
ykuroda | 0:13a5d365ba16 | 408 | |
ykuroda | 0:13a5d365ba16 | 409 | /** \sa MatrixBase::lazyAssign() */ |
ykuroda | 0:13a5d365ba16 | 410 | template<typename OtherDerived> |
ykuroda | 0:13a5d365ba16 | 411 | EIGEN_STRONG_INLINE Derived& lazyAssign(const DenseBase<OtherDerived>& other) |
ykuroda | 0:13a5d365ba16 | 412 | { |
ykuroda | 0:13a5d365ba16 | 413 | _resize_to_match(other); |
ykuroda | 0:13a5d365ba16 | 414 | return Base::lazyAssign(other.derived()); |
ykuroda | 0:13a5d365ba16 | 415 | } |
ykuroda | 0:13a5d365ba16 | 416 | |
ykuroda | 0:13a5d365ba16 | 417 | template<typename OtherDerived> |
ykuroda | 0:13a5d365ba16 | 418 | EIGEN_STRONG_INLINE Derived& operator=(const ReturnByValue<OtherDerived>& func) |
ykuroda | 0:13a5d365ba16 | 419 | { |
ykuroda | 0:13a5d365ba16 | 420 | resize(func.rows(), func.cols()); |
ykuroda | 0:13a5d365ba16 | 421 | return Base::operator=(func); |
ykuroda | 0:13a5d365ba16 | 422 | } |
ykuroda | 0:13a5d365ba16 | 423 | |
ykuroda | 0:13a5d365ba16 | 424 | EIGEN_STRONG_INLINE PlainObjectBase() : m_storage() |
ykuroda | 0:13a5d365ba16 | 425 | { |
ykuroda | 0:13a5d365ba16 | 426 | // _check_template_params(); |
ykuroda | 0:13a5d365ba16 | 427 | // EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED |
ykuroda | 0:13a5d365ba16 | 428 | } |
ykuroda | 0:13a5d365ba16 | 429 | |
ykuroda | 0:13a5d365ba16 | 430 | #ifndef EIGEN_PARSED_BY_DOXYGEN |
ykuroda | 0:13a5d365ba16 | 431 | // FIXME is it still needed ? |
ykuroda | 0:13a5d365ba16 | 432 | /** \internal */ |
ykuroda | 0:13a5d365ba16 | 433 | PlainObjectBase(internal::constructor_without_unaligned_array_assert) |
ykuroda | 0:13a5d365ba16 | 434 | : m_storage(internal::constructor_without_unaligned_array_assert()) |
ykuroda | 0:13a5d365ba16 | 435 | { |
ykuroda | 0:13a5d365ba16 | 436 | // _check_template_params(); EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED |
ykuroda | 0:13a5d365ba16 | 437 | } |
ykuroda | 0:13a5d365ba16 | 438 | #endif |
ykuroda | 0:13a5d365ba16 | 439 | |
ykuroda | 0:13a5d365ba16 | 440 | #ifdef EIGEN_HAVE_RVALUE_REFERENCES |
ykuroda | 0:13a5d365ba16 | 441 | PlainObjectBase(PlainObjectBase&& other) |
ykuroda | 0:13a5d365ba16 | 442 | : m_storage( std::move(other.m_storage) ) |
ykuroda | 0:13a5d365ba16 | 443 | { |
ykuroda | 0:13a5d365ba16 | 444 | } |
ykuroda | 0:13a5d365ba16 | 445 | |
ykuroda | 0:13a5d365ba16 | 446 | PlainObjectBase& operator=(PlainObjectBase&& other) |
ykuroda | 0:13a5d365ba16 | 447 | { |
ykuroda | 0:13a5d365ba16 | 448 | using std::swap; |
ykuroda | 0:13a5d365ba16 | 449 | swap(m_storage, other.m_storage); |
ykuroda | 0:13a5d365ba16 | 450 | return *this; |
ykuroda | 0:13a5d365ba16 | 451 | } |
ykuroda | 0:13a5d365ba16 | 452 | #endif |
ykuroda | 0:13a5d365ba16 | 453 | |
ykuroda | 0:13a5d365ba16 | 454 | /** Copy constructor */ |
ykuroda | 0:13a5d365ba16 | 455 | EIGEN_STRONG_INLINE PlainObjectBase(const PlainObjectBase& other) |
ykuroda | 0:13a5d365ba16 | 456 | : m_storage() |
ykuroda | 0:13a5d365ba16 | 457 | { |
ykuroda | 0:13a5d365ba16 | 458 | _check_template_params(); |
ykuroda | 0:13a5d365ba16 | 459 | lazyAssign(other); |
ykuroda | 0:13a5d365ba16 | 460 | } |
ykuroda | 0:13a5d365ba16 | 461 | |
ykuroda | 0:13a5d365ba16 | 462 | template<typename OtherDerived> |
ykuroda | 0:13a5d365ba16 | 463 | EIGEN_STRONG_INLINE PlainObjectBase(const DenseBase<OtherDerived> &other) |
ykuroda | 0:13a5d365ba16 | 464 | : m_storage() |
ykuroda | 0:13a5d365ba16 | 465 | { |
ykuroda | 0:13a5d365ba16 | 466 | _check_template_params(); |
ykuroda | 0:13a5d365ba16 | 467 | lazyAssign(other); |
ykuroda | 0:13a5d365ba16 | 468 | } |
ykuroda | 0:13a5d365ba16 | 469 | |
ykuroda | 0:13a5d365ba16 | 470 | EIGEN_STRONG_INLINE PlainObjectBase(Index a_size, Index nbRows, Index nbCols) |
ykuroda | 0:13a5d365ba16 | 471 | : m_storage(a_size, nbRows, nbCols) |
ykuroda | 0:13a5d365ba16 | 472 | { |
ykuroda | 0:13a5d365ba16 | 473 | // _check_template_params(); |
ykuroda | 0:13a5d365ba16 | 474 | // EIGEN_INITIALIZE_COEFFS_IF_THAT_OPTION_IS_ENABLED |
ykuroda | 0:13a5d365ba16 | 475 | } |
ykuroda | 0:13a5d365ba16 | 476 | |
ykuroda | 0:13a5d365ba16 | 477 | /** \copydoc MatrixBase::operator=(const EigenBase<OtherDerived>&) |
ykuroda | 0:13a5d365ba16 | 478 | */ |
ykuroda | 0:13a5d365ba16 | 479 | template<typename OtherDerived> |
ykuroda | 0:13a5d365ba16 | 480 | EIGEN_STRONG_INLINE Derived& operator=(const EigenBase<OtherDerived> &other) |
ykuroda | 0:13a5d365ba16 | 481 | { |
ykuroda | 0:13a5d365ba16 | 482 | _resize_to_match(other); |
ykuroda | 0:13a5d365ba16 | 483 | Base::operator=(other.derived()); |
ykuroda | 0:13a5d365ba16 | 484 | return this->derived(); |
ykuroda | 0:13a5d365ba16 | 485 | } |
ykuroda | 0:13a5d365ba16 | 486 | |
ykuroda | 0:13a5d365ba16 | 487 | /** \sa MatrixBase::operator=(const EigenBase<OtherDerived>&) */ |
ykuroda | 0:13a5d365ba16 | 488 | template<typename OtherDerived> |
ykuroda | 0:13a5d365ba16 | 489 | EIGEN_STRONG_INLINE PlainObjectBase(const EigenBase<OtherDerived> &other) |
ykuroda | 0:13a5d365ba16 | 490 | : m_storage(other.derived().rows() * other.derived().cols(), other.derived().rows(), other.derived().cols()) |
ykuroda | 0:13a5d365ba16 | 491 | { |
ykuroda | 0:13a5d365ba16 | 492 | _check_template_params(); |
ykuroda | 0:13a5d365ba16 | 493 | internal::check_rows_cols_for_overflow<MaxSizeAtCompileTime>::run(other.derived().rows(), other.derived().cols()); |
ykuroda | 0:13a5d365ba16 | 494 | Base::operator=(other.derived()); |
ykuroda | 0:13a5d365ba16 | 495 | } |
ykuroda | 0:13a5d365ba16 | 496 | |
ykuroda | 0:13a5d365ba16 | 497 | /** \name Map |
ykuroda | 0:13a5d365ba16 | 498 | * These are convenience functions returning Map objects. The Map() static functions return unaligned Map objects, |
ykuroda | 0:13a5d365ba16 | 499 | * while the AlignedMap() functions return aligned Map objects and thus should be called only with 16-byte-aligned |
ykuroda | 0:13a5d365ba16 | 500 | * \a data pointers. |
ykuroda | 0:13a5d365ba16 | 501 | * |
ykuroda | 0:13a5d365ba16 | 502 | * \see class Map |
ykuroda | 0:13a5d365ba16 | 503 | */ |
ykuroda | 0:13a5d365ba16 | 504 | //@{ |
ykuroda | 0:13a5d365ba16 | 505 | static inline ConstMapType Map(const Scalar* data) |
ykuroda | 0:13a5d365ba16 | 506 | { return ConstMapType(data); } |
ykuroda | 0:13a5d365ba16 | 507 | static inline MapType Map(Scalar* data) |
ykuroda | 0:13a5d365ba16 | 508 | { return MapType(data); } |
ykuroda | 0:13a5d365ba16 | 509 | static inline ConstMapType Map(const Scalar* data, Index size) |
ykuroda | 0:13a5d365ba16 | 510 | { return ConstMapType(data, size); } |
ykuroda | 0:13a5d365ba16 | 511 | static inline MapType Map(Scalar* data, Index size) |
ykuroda | 0:13a5d365ba16 | 512 | { return MapType(data, size); } |
ykuroda | 0:13a5d365ba16 | 513 | static inline ConstMapType Map(const Scalar* data, Index rows, Index cols) |
ykuroda | 0:13a5d365ba16 | 514 | { return ConstMapType(data, rows, cols); } |
ykuroda | 0:13a5d365ba16 | 515 | static inline MapType Map(Scalar* data, Index rows, Index cols) |
ykuroda | 0:13a5d365ba16 | 516 | { return MapType(data, rows, cols); } |
ykuroda | 0:13a5d365ba16 | 517 | |
ykuroda | 0:13a5d365ba16 | 518 | static inline ConstAlignedMapType MapAligned(const Scalar* data) |
ykuroda | 0:13a5d365ba16 | 519 | { return ConstAlignedMapType(data); } |
ykuroda | 0:13a5d365ba16 | 520 | static inline AlignedMapType MapAligned(Scalar* data) |
ykuroda | 0:13a5d365ba16 | 521 | { return AlignedMapType(data); } |
ykuroda | 0:13a5d365ba16 | 522 | static inline ConstAlignedMapType MapAligned(const Scalar* data, Index size) |
ykuroda | 0:13a5d365ba16 | 523 | { return ConstAlignedMapType(data, size); } |
ykuroda | 0:13a5d365ba16 | 524 | static inline AlignedMapType MapAligned(Scalar* data, Index size) |
ykuroda | 0:13a5d365ba16 | 525 | { return AlignedMapType(data, size); } |
ykuroda | 0:13a5d365ba16 | 526 | static inline ConstAlignedMapType MapAligned(const Scalar* data, Index rows, Index cols) |
ykuroda | 0:13a5d365ba16 | 527 | { return ConstAlignedMapType(data, rows, cols); } |
ykuroda | 0:13a5d365ba16 | 528 | static inline AlignedMapType MapAligned(Scalar* data, Index rows, Index cols) |
ykuroda | 0:13a5d365ba16 | 529 | { return AlignedMapType(data, rows, cols); } |
ykuroda | 0:13a5d365ba16 | 530 | |
ykuroda | 0:13a5d365ba16 | 531 | template<int Outer, int Inner> |
ykuroda | 0:13a5d365ba16 | 532 | static inline typename StridedConstMapType<Stride<Outer, Inner> >::type Map(const Scalar* data, const Stride<Outer, Inner>& stride) |
ykuroda | 0:13a5d365ba16 | 533 | { return typename StridedConstMapType<Stride<Outer, Inner> >::type(data, stride); } |
ykuroda | 0:13a5d365ba16 | 534 | template<int Outer, int Inner> |
ykuroda | 0:13a5d365ba16 | 535 | static inline typename StridedMapType<Stride<Outer, Inner> >::type Map(Scalar* data, const Stride<Outer, Inner>& stride) |
ykuroda | 0:13a5d365ba16 | 536 | { return typename StridedMapType<Stride<Outer, Inner> >::type(data, stride); } |
ykuroda | 0:13a5d365ba16 | 537 | template<int Outer, int Inner> |
ykuroda | 0:13a5d365ba16 | 538 | static inline typename StridedConstMapType<Stride<Outer, Inner> >::type Map(const Scalar* data, Index size, const Stride<Outer, Inner>& stride) |
ykuroda | 0:13a5d365ba16 | 539 | { return typename StridedConstMapType<Stride<Outer, Inner> >::type(data, size, stride); } |
ykuroda | 0:13a5d365ba16 | 540 | template<int Outer, int Inner> |
ykuroda | 0:13a5d365ba16 | 541 | static inline typename StridedMapType<Stride<Outer, Inner> >::type Map(Scalar* data, Index size, const Stride<Outer, Inner>& stride) |
ykuroda | 0:13a5d365ba16 | 542 | { return typename StridedMapType<Stride<Outer, Inner> >::type(data, size, stride); } |
ykuroda | 0:13a5d365ba16 | 543 | template<int Outer, int Inner> |
ykuroda | 0:13a5d365ba16 | 544 | static inline typename StridedConstMapType<Stride<Outer, Inner> >::type Map(const Scalar* data, Index rows, Index cols, const Stride<Outer, Inner>& stride) |
ykuroda | 0:13a5d365ba16 | 545 | { return typename StridedConstMapType<Stride<Outer, Inner> >::type(data, rows, cols, stride); } |
ykuroda | 0:13a5d365ba16 | 546 | template<int Outer, int Inner> |
ykuroda | 0:13a5d365ba16 | 547 | static inline typename StridedMapType<Stride<Outer, Inner> >::type Map(Scalar* data, Index rows, Index cols, const Stride<Outer, Inner>& stride) |
ykuroda | 0:13a5d365ba16 | 548 | { return typename StridedMapType<Stride<Outer, Inner> >::type(data, rows, cols, stride); } |
ykuroda | 0:13a5d365ba16 | 549 | |
ykuroda | 0:13a5d365ba16 | 550 | template<int Outer, int Inner> |
ykuroda | 0:13a5d365ba16 | 551 | static inline typename StridedConstAlignedMapType<Stride<Outer, Inner> >::type MapAligned(const Scalar* data, const Stride<Outer, Inner>& stride) |
ykuroda | 0:13a5d365ba16 | 552 | { return typename StridedConstAlignedMapType<Stride<Outer, Inner> >::type(data, stride); } |
ykuroda | 0:13a5d365ba16 | 553 | template<int Outer, int Inner> |
ykuroda | 0:13a5d365ba16 | 554 | static inline typename StridedAlignedMapType<Stride<Outer, Inner> >::type MapAligned(Scalar* data, const Stride<Outer, Inner>& stride) |
ykuroda | 0:13a5d365ba16 | 555 | { return typename StridedAlignedMapType<Stride<Outer, Inner> >::type(data, stride); } |
ykuroda | 0:13a5d365ba16 | 556 | template<int Outer, int Inner> |
ykuroda | 0:13a5d365ba16 | 557 | static inline typename StridedConstAlignedMapType<Stride<Outer, Inner> >::type MapAligned(const Scalar* data, Index size, const Stride<Outer, Inner>& stride) |
ykuroda | 0:13a5d365ba16 | 558 | { return typename StridedConstAlignedMapType<Stride<Outer, Inner> >::type(data, size, stride); } |
ykuroda | 0:13a5d365ba16 | 559 | template<int Outer, int Inner> |
ykuroda | 0:13a5d365ba16 | 560 | static inline typename StridedAlignedMapType<Stride<Outer, Inner> >::type MapAligned(Scalar* data, Index size, const Stride<Outer, Inner>& stride) |
ykuroda | 0:13a5d365ba16 | 561 | { return typename StridedAlignedMapType<Stride<Outer, Inner> >::type(data, size, stride); } |
ykuroda | 0:13a5d365ba16 | 562 | template<int Outer, int Inner> |
ykuroda | 0:13a5d365ba16 | 563 | static inline typename StridedConstAlignedMapType<Stride<Outer, Inner> >::type MapAligned(const Scalar* data, Index rows, Index cols, const Stride<Outer, Inner>& stride) |
ykuroda | 0:13a5d365ba16 | 564 | { return typename StridedConstAlignedMapType<Stride<Outer, Inner> >::type(data, rows, cols, stride); } |
ykuroda | 0:13a5d365ba16 | 565 | template<int Outer, int Inner> |
ykuroda | 0:13a5d365ba16 | 566 | static inline typename StridedAlignedMapType<Stride<Outer, Inner> >::type MapAligned(Scalar* data, Index rows, Index cols, const Stride<Outer, Inner>& stride) |
ykuroda | 0:13a5d365ba16 | 567 | { return typename StridedAlignedMapType<Stride<Outer, Inner> >::type(data, rows, cols, stride); } |
ykuroda | 0:13a5d365ba16 | 568 | //@} |
ykuroda | 0:13a5d365ba16 | 569 | |
ykuroda | 0:13a5d365ba16 | 570 | using Base::setConstant; |
ykuroda | 0:13a5d365ba16 | 571 | Derived& setConstant(Index size, const Scalar& value); |
ykuroda | 0:13a5d365ba16 | 572 | Derived& setConstant(Index rows, Index cols, const Scalar& value); |
ykuroda | 0:13a5d365ba16 | 573 | |
ykuroda | 0:13a5d365ba16 | 574 | using Base::setZero; |
ykuroda | 0:13a5d365ba16 | 575 | Derived& setZero(Index size); |
ykuroda | 0:13a5d365ba16 | 576 | Derived& setZero(Index rows, Index cols); |
ykuroda | 0:13a5d365ba16 | 577 | |
ykuroda | 0:13a5d365ba16 | 578 | using Base::setOnes; |
ykuroda | 0:13a5d365ba16 | 579 | Derived& setOnes(Index size); |
ykuroda | 0:13a5d365ba16 | 580 | Derived& setOnes(Index rows, Index cols); |
ykuroda | 0:13a5d365ba16 | 581 | |
ykuroda | 0:13a5d365ba16 | 582 | using Base::setRandom; |
ykuroda | 0:13a5d365ba16 | 583 | Derived& setRandom(Index size); |
ykuroda | 0:13a5d365ba16 | 584 | Derived& setRandom(Index rows, Index cols); |
ykuroda | 0:13a5d365ba16 | 585 | |
ykuroda | 0:13a5d365ba16 | 586 | #ifdef EIGEN_PLAINOBJECTBASE_PLUGIN |
ykuroda | 0:13a5d365ba16 | 587 | #include EIGEN_PLAINOBJECTBASE_PLUGIN |
ykuroda | 0:13a5d365ba16 | 588 | #endif |
ykuroda | 0:13a5d365ba16 | 589 | |
ykuroda | 0:13a5d365ba16 | 590 | protected: |
ykuroda | 0:13a5d365ba16 | 591 | /** \internal Resizes *this in preparation for assigning \a other to it. |
ykuroda | 0:13a5d365ba16 | 592 | * Takes care of doing all the checking that's needed. |
ykuroda | 0:13a5d365ba16 | 593 | * |
ykuroda | 0:13a5d365ba16 | 594 | * Note that copying a row-vector into a vector (and conversely) is allowed. |
ykuroda | 0:13a5d365ba16 | 595 | * The resizing, if any, is then done in the appropriate way so that row-vectors |
ykuroda | 0:13a5d365ba16 | 596 | * remain row-vectors and vectors remain vectors. |
ykuroda | 0:13a5d365ba16 | 597 | */ |
ykuroda | 0:13a5d365ba16 | 598 | template<typename OtherDerived> |
ykuroda | 0:13a5d365ba16 | 599 | EIGEN_STRONG_INLINE void _resize_to_match(const EigenBase<OtherDerived>& other) |
ykuroda | 0:13a5d365ba16 | 600 | { |
ykuroda | 0:13a5d365ba16 | 601 | #ifdef EIGEN_NO_AUTOMATIC_RESIZING |
ykuroda | 0:13a5d365ba16 | 602 | eigen_assert((this->size()==0 || (IsVectorAtCompileTime ? (this->size() == other.size()) |
ykuroda | 0:13a5d365ba16 | 603 | : (rows() == other.rows() && cols() == other.cols()))) |
ykuroda | 0:13a5d365ba16 | 604 | && "Size mismatch. Automatic resizing is disabled because EIGEN_NO_AUTOMATIC_RESIZING is defined"); |
ykuroda | 0:13a5d365ba16 | 605 | EIGEN_ONLY_USED_FOR_DEBUG(other); |
ykuroda | 0:13a5d365ba16 | 606 | if(this->size()==0) |
ykuroda | 0:13a5d365ba16 | 607 | resizeLike(other); |
ykuroda | 0:13a5d365ba16 | 608 | #else |
ykuroda | 0:13a5d365ba16 | 609 | resizeLike(other); |
ykuroda | 0:13a5d365ba16 | 610 | #endif |
ykuroda | 0:13a5d365ba16 | 611 | } |
ykuroda | 0:13a5d365ba16 | 612 | |
ykuroda | 0:13a5d365ba16 | 613 | /** |
ykuroda | 0:13a5d365ba16 | 614 | * \brief Copies the value of the expression \a other into \c *this with automatic resizing. |
ykuroda | 0:13a5d365ba16 | 615 | * |
ykuroda | 0:13a5d365ba16 | 616 | * *this might be resized to match the dimensions of \a other. If *this was a null matrix (not already initialized), |
ykuroda | 0:13a5d365ba16 | 617 | * it will be initialized. |
ykuroda | 0:13a5d365ba16 | 618 | * |
ykuroda | 0:13a5d365ba16 | 619 | * Note that copying a row-vector into a vector (and conversely) is allowed. |
ykuroda | 0:13a5d365ba16 | 620 | * The resizing, if any, is then done in the appropriate way so that row-vectors |
ykuroda | 0:13a5d365ba16 | 621 | * remain row-vectors and vectors remain vectors. |
ykuroda | 0:13a5d365ba16 | 622 | * |
ykuroda | 0:13a5d365ba16 | 623 | * \sa operator=(const MatrixBase<OtherDerived>&), _set_noalias() |
ykuroda | 0:13a5d365ba16 | 624 | * |
ykuroda | 0:13a5d365ba16 | 625 | * \internal |
ykuroda | 0:13a5d365ba16 | 626 | */ |
ykuroda | 0:13a5d365ba16 | 627 | template<typename OtherDerived> |
ykuroda | 0:13a5d365ba16 | 628 | EIGEN_STRONG_INLINE Derived& _set(const DenseBase<OtherDerived>& other) |
ykuroda | 0:13a5d365ba16 | 629 | { |
ykuroda | 0:13a5d365ba16 | 630 | _set_selector(other.derived(), typename internal::conditional<static_cast<bool>(int(OtherDerived::Flags) & EvalBeforeAssigningBit), internal::true_type, internal::false_type>::type()); |
ykuroda | 0:13a5d365ba16 | 631 | return this->derived(); |
ykuroda | 0:13a5d365ba16 | 632 | } |
ykuroda | 0:13a5d365ba16 | 633 | |
ykuroda | 0:13a5d365ba16 | 634 | template<typename OtherDerived> |
ykuroda | 0:13a5d365ba16 | 635 | EIGEN_STRONG_INLINE void _set_selector(const OtherDerived& other, const internal::true_type&) { _set_noalias(other.eval()); } |
ykuroda | 0:13a5d365ba16 | 636 | |
ykuroda | 0:13a5d365ba16 | 637 | template<typename OtherDerived> |
ykuroda | 0:13a5d365ba16 | 638 | EIGEN_STRONG_INLINE void _set_selector(const OtherDerived& other, const internal::false_type&) { _set_noalias(other); } |
ykuroda | 0:13a5d365ba16 | 639 | |
ykuroda | 0:13a5d365ba16 | 640 | /** \internal Like _set() but additionally makes the assumption that no aliasing effect can happen (which |
ykuroda | 0:13a5d365ba16 | 641 | * is the case when creating a new matrix) so one can enforce lazy evaluation. |
ykuroda | 0:13a5d365ba16 | 642 | * |
ykuroda | 0:13a5d365ba16 | 643 | * \sa operator=(const MatrixBase<OtherDerived>&), _set() |
ykuroda | 0:13a5d365ba16 | 644 | */ |
ykuroda | 0:13a5d365ba16 | 645 | template<typename OtherDerived> |
ykuroda | 0:13a5d365ba16 | 646 | EIGEN_STRONG_INLINE Derived& _set_noalias(const DenseBase<OtherDerived>& other) |
ykuroda | 0:13a5d365ba16 | 647 | { |
ykuroda | 0:13a5d365ba16 | 648 | // I don't think we need this resize call since the lazyAssign will anyways resize |
ykuroda | 0:13a5d365ba16 | 649 | // and lazyAssign will be called by the assign selector. |
ykuroda | 0:13a5d365ba16 | 650 | //_resize_to_match(other); |
ykuroda | 0:13a5d365ba16 | 651 | // the 'false' below means to enforce lazy evaluation. We don't use lazyAssign() because |
ykuroda | 0:13a5d365ba16 | 652 | // it wouldn't allow to copy a row-vector into a column-vector. |
ykuroda | 0:13a5d365ba16 | 653 | return internal::assign_selector<Derived,OtherDerived,false>::run(this->derived(), other.derived()); |
ykuroda | 0:13a5d365ba16 | 654 | } |
ykuroda | 0:13a5d365ba16 | 655 | |
ykuroda | 0:13a5d365ba16 | 656 | template<typename T0, typename T1> |
ykuroda | 0:13a5d365ba16 | 657 | EIGEN_STRONG_INLINE void _init2(Index nbRows, Index nbCols, typename internal::enable_if<Base::SizeAtCompileTime!=2,T0>::type* = 0) |
ykuroda | 0:13a5d365ba16 | 658 | { |
ykuroda | 0:13a5d365ba16 | 659 | EIGEN_STATIC_ASSERT(bool(NumTraits<T0>::IsInteger) && |
ykuroda | 0:13a5d365ba16 | 660 | bool(NumTraits<T1>::IsInteger), |
ykuroda | 0:13a5d365ba16 | 661 | FLOATING_POINT_ARGUMENT_PASSED__INTEGER_WAS_EXPECTED) |
ykuroda | 0:13a5d365ba16 | 662 | resize(nbRows,nbCols); |
ykuroda | 0:13a5d365ba16 | 663 | } |
ykuroda | 0:13a5d365ba16 | 664 | template<typename T0, typename T1> |
ykuroda | 0:13a5d365ba16 | 665 | EIGEN_STRONG_INLINE void _init2(const Scalar& val0, const Scalar& val1, typename internal::enable_if<Base::SizeAtCompileTime==2,T0>::type* = 0) |
ykuroda | 0:13a5d365ba16 | 666 | { |
ykuroda | 0:13a5d365ba16 | 667 | EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(PlainObjectBase, 2) |
ykuroda | 0:13a5d365ba16 | 668 | m_storage.data()[0] = val0; |
ykuroda | 0:13a5d365ba16 | 669 | m_storage.data()[1] = val1; |
ykuroda | 0:13a5d365ba16 | 670 | } |
ykuroda | 0:13a5d365ba16 | 671 | |
ykuroda | 0:13a5d365ba16 | 672 | template<typename MatrixTypeA, typename MatrixTypeB, bool SwapPointers> |
ykuroda | 0:13a5d365ba16 | 673 | friend struct internal::matrix_swap_impl; |
ykuroda | 0:13a5d365ba16 | 674 | |
ykuroda | 0:13a5d365ba16 | 675 | /** \internal generic implementation of swap for dense storage since for dynamic-sized matrices of same type it is enough to swap the |
ykuroda | 0:13a5d365ba16 | 676 | * data pointers. |
ykuroda | 0:13a5d365ba16 | 677 | */ |
ykuroda | 0:13a5d365ba16 | 678 | template<typename OtherDerived> |
ykuroda | 0:13a5d365ba16 | 679 | void _swap(DenseBase<OtherDerived> const & other) |
ykuroda | 0:13a5d365ba16 | 680 | { |
ykuroda | 0:13a5d365ba16 | 681 | enum { SwapPointers = internal::is_same<Derived, OtherDerived>::value && Base::SizeAtCompileTime==Dynamic }; |
ykuroda | 0:13a5d365ba16 | 682 | internal::matrix_swap_impl<Derived, OtherDerived, bool(SwapPointers)>::run(this->derived(), other.const_cast_derived()); |
ykuroda | 0:13a5d365ba16 | 683 | } |
ykuroda | 0:13a5d365ba16 | 684 | |
ykuroda | 0:13a5d365ba16 | 685 | public: |
ykuroda | 0:13a5d365ba16 | 686 | #ifndef EIGEN_PARSED_BY_DOXYGEN |
ykuroda | 0:13a5d365ba16 | 687 | static EIGEN_STRONG_INLINE void _check_template_params() |
ykuroda | 0:13a5d365ba16 | 688 | { |
ykuroda | 0:13a5d365ba16 | 689 | EIGEN_STATIC_ASSERT((EIGEN_IMPLIES(MaxRowsAtCompileTime==1 && MaxColsAtCompileTime!=1, (Options&RowMajor)==RowMajor) |
ykuroda | 0:13a5d365ba16 | 690 | && EIGEN_IMPLIES(MaxColsAtCompileTime==1 && MaxRowsAtCompileTime!=1, (Options&RowMajor)==0) |
ykuroda | 0:13a5d365ba16 | 691 | && ((RowsAtCompileTime == Dynamic) || (RowsAtCompileTime >= 0)) |
ykuroda | 0:13a5d365ba16 | 692 | && ((ColsAtCompileTime == Dynamic) || (ColsAtCompileTime >= 0)) |
ykuroda | 0:13a5d365ba16 | 693 | && ((MaxRowsAtCompileTime == Dynamic) || (MaxRowsAtCompileTime >= 0)) |
ykuroda | 0:13a5d365ba16 | 694 | && ((MaxColsAtCompileTime == Dynamic) || (MaxColsAtCompileTime >= 0)) |
ykuroda | 0:13a5d365ba16 | 695 | && (MaxRowsAtCompileTime == RowsAtCompileTime || RowsAtCompileTime==Dynamic) |
ykuroda | 0:13a5d365ba16 | 696 | && (MaxColsAtCompileTime == ColsAtCompileTime || ColsAtCompileTime==Dynamic) |
ykuroda | 0:13a5d365ba16 | 697 | && (Options & (DontAlign|RowMajor)) == Options), |
ykuroda | 0:13a5d365ba16 | 698 | INVALID_MATRIX_TEMPLATE_PARAMETERS) |
ykuroda | 0:13a5d365ba16 | 699 | } |
ykuroda | 0:13a5d365ba16 | 700 | #endif |
ykuroda | 0:13a5d365ba16 | 701 | |
ykuroda | 0:13a5d365ba16 | 702 | private: |
ykuroda | 0:13a5d365ba16 | 703 | enum { ThisConstantIsPrivateInPlainObjectBase }; |
ykuroda | 0:13a5d365ba16 | 704 | }; |
ykuroda | 0:13a5d365ba16 | 705 | |
ykuroda | 0:13a5d365ba16 | 706 | namespace internal { |
ykuroda | 0:13a5d365ba16 | 707 | |
ykuroda | 0:13a5d365ba16 | 708 | template <typename Derived, typename OtherDerived, bool IsVector> |
ykuroda | 0:13a5d365ba16 | 709 | struct conservative_resize_like_impl |
ykuroda | 0:13a5d365ba16 | 710 | { |
ykuroda | 0:13a5d365ba16 | 711 | typedef typename Derived::Index Index; |
ykuroda | 0:13a5d365ba16 | 712 | static void run(DenseBase<Derived>& _this, Index rows, Index cols) |
ykuroda | 0:13a5d365ba16 | 713 | { |
ykuroda | 0:13a5d365ba16 | 714 | if (_this.rows() == rows && _this.cols() == cols) return; |
ykuroda | 0:13a5d365ba16 | 715 | EIGEN_STATIC_ASSERT_DYNAMIC_SIZE(Derived) |
ykuroda | 0:13a5d365ba16 | 716 | |
ykuroda | 0:13a5d365ba16 | 717 | if ( ( Derived::IsRowMajor && _this.cols() == cols) || // row-major and we change only the number of rows |
ykuroda | 0:13a5d365ba16 | 718 | (!Derived::IsRowMajor && _this.rows() == rows) ) // column-major and we change only the number of columns |
ykuroda | 0:13a5d365ba16 | 719 | { |
ykuroda | 0:13a5d365ba16 | 720 | internal::check_rows_cols_for_overflow<Derived::MaxSizeAtCompileTime>::run(rows, cols); |
ykuroda | 0:13a5d365ba16 | 721 | _this.derived().m_storage.conservativeResize(rows*cols,rows,cols); |
ykuroda | 0:13a5d365ba16 | 722 | } |
ykuroda | 0:13a5d365ba16 | 723 | else |
ykuroda | 0:13a5d365ba16 | 724 | { |
ykuroda | 0:13a5d365ba16 | 725 | // The storage order does not allow us to use reallocation. |
ykuroda | 0:13a5d365ba16 | 726 | typename Derived::PlainObject tmp(rows,cols); |
ykuroda | 0:13a5d365ba16 | 727 | const Index common_rows = (std::min)(rows, _this.rows()); |
ykuroda | 0:13a5d365ba16 | 728 | const Index common_cols = (std::min)(cols, _this.cols()); |
ykuroda | 0:13a5d365ba16 | 729 | tmp.block(0,0,common_rows,common_cols) = _this.block(0,0,common_rows,common_cols); |
ykuroda | 0:13a5d365ba16 | 730 | _this.derived().swap(tmp); |
ykuroda | 0:13a5d365ba16 | 731 | } |
ykuroda | 0:13a5d365ba16 | 732 | } |
ykuroda | 0:13a5d365ba16 | 733 | |
ykuroda | 0:13a5d365ba16 | 734 | static void run(DenseBase<Derived>& _this, const DenseBase<OtherDerived>& other) |
ykuroda | 0:13a5d365ba16 | 735 | { |
ykuroda | 0:13a5d365ba16 | 736 | if (_this.rows() == other.rows() && _this.cols() == other.cols()) return; |
ykuroda | 0:13a5d365ba16 | 737 | |
ykuroda | 0:13a5d365ba16 | 738 | // Note: Here is space for improvement. Basically, for conservativeResize(Index,Index), |
ykuroda | 0:13a5d365ba16 | 739 | // neither RowsAtCompileTime or ColsAtCompileTime must be Dynamic. If only one of the |
ykuroda | 0:13a5d365ba16 | 740 | // dimensions is dynamic, one could use either conservativeResize(Index rows, NoChange_t) or |
ykuroda | 0:13a5d365ba16 | 741 | // conservativeResize(NoChange_t, Index cols). For these methods new static asserts like |
ykuroda | 0:13a5d365ba16 | 742 | // EIGEN_STATIC_ASSERT_DYNAMIC_ROWS and EIGEN_STATIC_ASSERT_DYNAMIC_COLS would be good. |
ykuroda | 0:13a5d365ba16 | 743 | EIGEN_STATIC_ASSERT_DYNAMIC_SIZE(Derived) |
ykuroda | 0:13a5d365ba16 | 744 | EIGEN_STATIC_ASSERT_DYNAMIC_SIZE(OtherDerived) |
ykuroda | 0:13a5d365ba16 | 745 | |
ykuroda | 0:13a5d365ba16 | 746 | if ( ( Derived::IsRowMajor && _this.cols() == other.cols()) || // row-major and we change only the number of rows |
ykuroda | 0:13a5d365ba16 | 747 | (!Derived::IsRowMajor && _this.rows() == other.rows()) ) // column-major and we change only the number of columns |
ykuroda | 0:13a5d365ba16 | 748 | { |
ykuroda | 0:13a5d365ba16 | 749 | const Index new_rows = other.rows() - _this.rows(); |
ykuroda | 0:13a5d365ba16 | 750 | const Index new_cols = other.cols() - _this.cols(); |
ykuroda | 0:13a5d365ba16 | 751 | _this.derived().m_storage.conservativeResize(other.size(),other.rows(),other.cols()); |
ykuroda | 0:13a5d365ba16 | 752 | if (new_rows>0) |
ykuroda | 0:13a5d365ba16 | 753 | _this.bottomRightCorner(new_rows, other.cols()) = other.bottomRows(new_rows); |
ykuroda | 0:13a5d365ba16 | 754 | else if (new_cols>0) |
ykuroda | 0:13a5d365ba16 | 755 | _this.bottomRightCorner(other.rows(), new_cols) = other.rightCols(new_cols); |
ykuroda | 0:13a5d365ba16 | 756 | } |
ykuroda | 0:13a5d365ba16 | 757 | else |
ykuroda | 0:13a5d365ba16 | 758 | { |
ykuroda | 0:13a5d365ba16 | 759 | // The storage order does not allow us to use reallocation. |
ykuroda | 0:13a5d365ba16 | 760 | typename Derived::PlainObject tmp(other); |
ykuroda | 0:13a5d365ba16 | 761 | const Index common_rows = (std::min)(tmp.rows(), _this.rows()); |
ykuroda | 0:13a5d365ba16 | 762 | const Index common_cols = (std::min)(tmp.cols(), _this.cols()); |
ykuroda | 0:13a5d365ba16 | 763 | tmp.block(0,0,common_rows,common_cols) = _this.block(0,0,common_rows,common_cols); |
ykuroda | 0:13a5d365ba16 | 764 | _this.derived().swap(tmp); |
ykuroda | 0:13a5d365ba16 | 765 | } |
ykuroda | 0:13a5d365ba16 | 766 | } |
ykuroda | 0:13a5d365ba16 | 767 | }; |
ykuroda | 0:13a5d365ba16 | 768 | |
ykuroda | 0:13a5d365ba16 | 769 | // Here, the specialization for vectors inherits from the general matrix case |
ykuroda | 0:13a5d365ba16 | 770 | // to allow calling .conservativeResize(rows,cols) on vectors. |
ykuroda | 0:13a5d365ba16 | 771 | template <typename Derived, typename OtherDerived> |
ykuroda | 0:13a5d365ba16 | 772 | struct conservative_resize_like_impl<Derived,OtherDerived,true> |
ykuroda | 0:13a5d365ba16 | 773 | : conservative_resize_like_impl<Derived,OtherDerived,false> |
ykuroda | 0:13a5d365ba16 | 774 | { |
ykuroda | 0:13a5d365ba16 | 775 | using conservative_resize_like_impl<Derived,OtherDerived,false>::run; |
ykuroda | 0:13a5d365ba16 | 776 | |
ykuroda | 0:13a5d365ba16 | 777 | typedef typename Derived::Index Index; |
ykuroda | 0:13a5d365ba16 | 778 | static void run(DenseBase<Derived>& _this, Index size) |
ykuroda | 0:13a5d365ba16 | 779 | { |
ykuroda | 0:13a5d365ba16 | 780 | const Index new_rows = Derived::RowsAtCompileTime==1 ? 1 : size; |
ykuroda | 0:13a5d365ba16 | 781 | const Index new_cols = Derived::RowsAtCompileTime==1 ? size : 1; |
ykuroda | 0:13a5d365ba16 | 782 | _this.derived().m_storage.conservativeResize(size,new_rows,new_cols); |
ykuroda | 0:13a5d365ba16 | 783 | } |
ykuroda | 0:13a5d365ba16 | 784 | |
ykuroda | 0:13a5d365ba16 | 785 | static void run(DenseBase<Derived>& _this, const DenseBase<OtherDerived>& other) |
ykuroda | 0:13a5d365ba16 | 786 | { |
ykuroda | 0:13a5d365ba16 | 787 | if (_this.rows() == other.rows() && _this.cols() == other.cols()) return; |
ykuroda | 0:13a5d365ba16 | 788 | |
ykuroda | 0:13a5d365ba16 | 789 | const Index num_new_elements = other.size() - _this.size(); |
ykuroda | 0:13a5d365ba16 | 790 | |
ykuroda | 0:13a5d365ba16 | 791 | const Index new_rows = Derived::RowsAtCompileTime==1 ? 1 : other.rows(); |
ykuroda | 0:13a5d365ba16 | 792 | const Index new_cols = Derived::RowsAtCompileTime==1 ? other.cols() : 1; |
ykuroda | 0:13a5d365ba16 | 793 | _this.derived().m_storage.conservativeResize(other.size(),new_rows,new_cols); |
ykuroda | 0:13a5d365ba16 | 794 | |
ykuroda | 0:13a5d365ba16 | 795 | if (num_new_elements > 0) |
ykuroda | 0:13a5d365ba16 | 796 | _this.tail(num_new_elements) = other.tail(num_new_elements); |
ykuroda | 0:13a5d365ba16 | 797 | } |
ykuroda | 0:13a5d365ba16 | 798 | }; |
ykuroda | 0:13a5d365ba16 | 799 | |
ykuroda | 0:13a5d365ba16 | 800 | template<typename MatrixTypeA, typename MatrixTypeB, bool SwapPointers> |
ykuroda | 0:13a5d365ba16 | 801 | struct matrix_swap_impl |
ykuroda | 0:13a5d365ba16 | 802 | { |
ykuroda | 0:13a5d365ba16 | 803 | static inline void run(MatrixTypeA& a, MatrixTypeB& b) |
ykuroda | 0:13a5d365ba16 | 804 | { |
ykuroda | 0:13a5d365ba16 | 805 | a.base().swap(b); |
ykuroda | 0:13a5d365ba16 | 806 | } |
ykuroda | 0:13a5d365ba16 | 807 | }; |
ykuroda | 0:13a5d365ba16 | 808 | |
ykuroda | 0:13a5d365ba16 | 809 | template<typename MatrixTypeA, typename MatrixTypeB> |
ykuroda | 0:13a5d365ba16 | 810 | struct matrix_swap_impl<MatrixTypeA, MatrixTypeB, true> |
ykuroda | 0:13a5d365ba16 | 811 | { |
ykuroda | 0:13a5d365ba16 | 812 | static inline void run(MatrixTypeA& a, MatrixTypeB& b) |
ykuroda | 0:13a5d365ba16 | 813 | { |
ykuroda | 0:13a5d365ba16 | 814 | static_cast<typename MatrixTypeA::Base&>(a).m_storage.swap(static_cast<typename MatrixTypeB::Base&>(b).m_storage); |
ykuroda | 0:13a5d365ba16 | 815 | } |
ykuroda | 0:13a5d365ba16 | 816 | }; |
ykuroda | 0:13a5d365ba16 | 817 | |
ykuroda | 0:13a5d365ba16 | 818 | } // end namespace internal |
ykuroda | 0:13a5d365ba16 | 819 | |
ykuroda | 0:13a5d365ba16 | 820 | } // end namespace Eigen |
ykuroda | 0:13a5d365ba16 | 821 | |
ykuroda | 0:13a5d365ba16 | 822 | #endif // EIGEN_DENSESTORAGEBASE_H |