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: Eigen_test Odometry_test AttitudeEstimation_usingTicker MPU9250_Quaternion_Binary_Serial ... more
MapBase.h
00001 // This file is part of Eigen, a lightweight C++ template library 00002 // for linear algebra. 00003 // 00004 // Copyright (C) 2007-2010 Benoit Jacob <jacob.benoit.1@gmail.com> 00005 // Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr> 00006 // 00007 // This Source Code Form is subject to the terms of the Mozilla 00008 // Public License v. 2.0. If a copy of the MPL was not distributed 00009 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 00010 00011 #ifndef EIGEN_MAPBASE_H 00012 #define EIGEN_MAPBASE_H 00013 00014 #define EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived) \ 00015 EIGEN_STATIC_ASSERT((int(internal::traits<Derived>::Flags) & LinearAccessBit) || Derived::IsVectorAtCompileTime, \ 00016 YOU_ARE_TRYING_TO_USE_AN_INDEX_BASED_ACCESSOR_ON_AN_EXPRESSION_THAT_DOES_NOT_SUPPORT_THAT) 00017 00018 namespace Eigen { 00019 00020 /** \class MapBase 00021 * \ingroup Core_Module 00022 * 00023 * \brief Base class for Map and Block expression with direct access 00024 * 00025 * \sa class Map, class Block 00026 */ 00027 template<typename Derived> class MapBase<Derived, ReadOnlyAccessors> 00028 : public internal::dense_xpr_base<Derived>::type 00029 { 00030 public: 00031 00032 typedef typename internal::dense_xpr_base<Derived>::type Base; 00033 enum { 00034 RowsAtCompileTime = internal::traits<Derived>::RowsAtCompileTime, 00035 ColsAtCompileTime = internal::traits<Derived>::ColsAtCompileTime, 00036 SizeAtCompileTime = Base::SizeAtCompileTime 00037 }; 00038 00039 typedef typename internal::traits<Derived>::StorageKind StorageKind; 00040 typedef typename internal::traits<Derived>::Index Index; 00041 typedef typename internal::traits<Derived>::Scalar Scalar; 00042 typedef typename internal::packet_traits<Scalar>::type PacketScalar; 00043 typedef typename NumTraits<Scalar>::Real RealScalar; 00044 typedef typename internal::conditional< 00045 bool(internal::is_lvalue<Derived>::value), 00046 Scalar *, 00047 const Scalar *>::type 00048 PointerType; 00049 00050 using Base::derived; 00051 // using Base::RowsAtCompileTime; 00052 // using Base::ColsAtCompileTime; 00053 // using Base::SizeAtCompileTime; 00054 using Base::MaxRowsAtCompileTime; 00055 using Base::MaxColsAtCompileTime; 00056 using Base::MaxSizeAtCompileTime; 00057 using Base::IsVectorAtCompileTime; 00058 using Base::Flags; 00059 using Base::IsRowMajor; 00060 00061 using Base::rows; 00062 using Base::cols; 00063 using Base::size; 00064 using Base::coeff; 00065 using Base::coeffRef; 00066 using Base::lazyAssign; 00067 using Base::eval; 00068 00069 using Base::innerStride; 00070 using Base::outerStride; 00071 using Base::rowStride; 00072 using Base::colStride; 00073 00074 // bug 217 - compile error on ICC 11.1 00075 using Base::operator=; 00076 00077 typedef typename Base::CoeffReturnType CoeffReturnType; 00078 00079 inline Index rows() const { return m_rows.value(); } 00080 inline Index cols() const { return m_cols.value(); } 00081 00082 /** Returns a pointer to the first coefficient of the matrix or vector. 00083 * 00084 * \note When addressing this data, make sure to honor the strides returned by innerStride() and outerStride(). 00085 * 00086 * \sa innerStride(), outerStride() 00087 */ 00088 inline const Scalar* data() const { return m_data; } 00089 00090 inline const Scalar& coeff(Index rowId, Index colId) const 00091 { 00092 return m_data[colId * colStride() + rowId * rowStride()]; 00093 } 00094 00095 inline const Scalar& coeff(Index index) const 00096 { 00097 EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived) 00098 return m_data[index * innerStride()]; 00099 } 00100 00101 inline const Scalar& coeffRef(Index rowId, Index colId) const 00102 { 00103 return this->m_data[colId * colStride() + rowId * rowStride()]; 00104 } 00105 00106 inline const Scalar& coeffRef(Index index) const 00107 { 00108 EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived) 00109 return this->m_data[index * innerStride()]; 00110 } 00111 00112 template<int LoadMode> 00113 inline PacketScalar packet(Index rowId, Index colId) const 00114 { 00115 return internal::ploadt<PacketScalar, LoadMode> 00116 (m_data + (colId * colStride() + rowId * rowStride())); 00117 } 00118 00119 template<int LoadMode> 00120 inline PacketScalar packet(Index index) const 00121 { 00122 EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived) 00123 return internal::ploadt<PacketScalar, LoadMode>(m_data + index * innerStride()); 00124 } 00125 00126 explicit inline MapBase(PointerType dataPtr) : m_data(dataPtr), m_rows(RowsAtCompileTime), m_cols(ColsAtCompileTime) 00127 { 00128 EIGEN_STATIC_ASSERT_FIXED_SIZE(Derived) 00129 checkSanity(); 00130 } 00131 00132 inline MapBase(PointerType dataPtr, Index vecSize) 00133 : m_data(dataPtr), 00134 m_rows(RowsAtCompileTime == Dynamic ? vecSize : Index(RowsAtCompileTime)), 00135 m_cols(ColsAtCompileTime == Dynamic ? vecSize : Index(ColsAtCompileTime)) 00136 { 00137 EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived) 00138 eigen_assert(vecSize >= 0); 00139 eigen_assert(dataPtr == 0 || SizeAtCompileTime == Dynamic || SizeAtCompileTime == vecSize); 00140 checkSanity(); 00141 } 00142 00143 inline MapBase(PointerType dataPtr, Index nbRows, Index nbCols) 00144 : m_data(dataPtr), m_rows(nbRows), m_cols(nbCols) 00145 { 00146 eigen_assert( (dataPtr == 0) 00147 || ( nbRows >= 0 && (RowsAtCompileTime == Dynamic || RowsAtCompileTime == nbRows) 00148 && nbCols >= 0 && (ColsAtCompileTime == Dynamic || ColsAtCompileTime == nbCols))); 00149 checkSanity(); 00150 } 00151 00152 #ifdef EIGEN_MAPBASE_PLUGIN 00153 #include EIGEN_MAPBASE_PLUGIN 00154 #endif 00155 00156 protected: 00157 00158 void checkSanity() const 00159 { 00160 EIGEN_STATIC_ASSERT(EIGEN_IMPLIES(internal::traits<Derived>::Flags&PacketAccessBit, 00161 internal::inner_stride_at_compile_time<Derived>::ret==1), 00162 PACKET_ACCESS_REQUIRES_TO_HAVE_INNER_STRIDE_FIXED_TO_1); 00163 eigen_assert(EIGEN_IMPLIES(internal::traits<Derived>::Flags&AlignedBit, (size_t(m_data) % 16) == 0) 00164 && "input pointer is not aligned on a 16 byte boundary"); 00165 } 00166 00167 PointerType m_data; 00168 const internal::variable_if_dynamic<Index, RowsAtCompileTime> m_rows; 00169 const internal::variable_if_dynamic<Index, ColsAtCompileTime> m_cols; 00170 }; 00171 00172 template<typename Derived> class MapBase<Derived, WriteAccessors> 00173 : public MapBase<Derived, ReadOnlyAccessors> 00174 { 00175 typedef MapBase<Derived, ReadOnlyAccessors> ReadOnlyMapBase; 00176 public: 00177 00178 typedef MapBase<Derived, ReadOnlyAccessors> Base; 00179 00180 typedef typename Base::Scalar Scalar; 00181 typedef typename Base::PacketScalar PacketScalar; 00182 typedef typename Base::Index Index; 00183 typedef typename Base::PointerType PointerType; 00184 00185 using Base::derived; 00186 using Base::rows; 00187 using Base::cols; 00188 using Base::size; 00189 using Base::coeff; 00190 using Base::coeffRef; 00191 00192 using Base::innerStride; 00193 using Base::outerStride; 00194 using Base::rowStride; 00195 using Base::colStride; 00196 00197 typedef typename internal::conditional< 00198 internal::is_lvalue<Derived>::value, 00199 Scalar, 00200 const Scalar 00201 >::type ScalarWithConstIfNotLvalue; 00202 00203 inline const Scalar* data() const { return this->m_data; } 00204 inline ScalarWithConstIfNotLvalue* data() { return this->m_data; } // no const-cast here so non-const-correct code will give a compile error 00205 00206 inline ScalarWithConstIfNotLvalue& coeffRef(Index row, Index col) 00207 { 00208 return this->m_data[col * colStride() + row * rowStride()]; 00209 } 00210 00211 inline ScalarWithConstIfNotLvalue& coeffRef(Index index) 00212 { 00213 EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived) 00214 return this->m_data[index * innerStride()]; 00215 } 00216 00217 template<int StoreMode> 00218 inline void writePacket(Index row, Index col, const PacketScalar& val) 00219 { 00220 internal::pstoret<Scalar, PacketScalar, StoreMode> 00221 (this->m_data + (col * colStride() + row * rowStride()), val); 00222 } 00223 00224 template<int StoreMode> 00225 inline void writePacket(Index index, const PacketScalar& val) 00226 { 00227 EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS(Derived) 00228 internal::pstoret<Scalar, PacketScalar, StoreMode> 00229 (this->m_data + index * innerStride(), val); 00230 } 00231 00232 explicit inline MapBase(PointerType dataPtr) : Base(dataPtr) {} 00233 inline MapBase(PointerType dataPtr, Index vecSize) : Base(dataPtr, vecSize) {} 00234 inline MapBase(PointerType dataPtr, Index nbRows, Index nbCols) : Base(dataPtr, nbRows, nbCols) {} 00235 00236 Derived& operator=(const MapBase& other) 00237 { 00238 ReadOnlyMapBase::Base::operator=(other); 00239 return derived(); 00240 } 00241 00242 // In theory we could simply refer to Base:Base::operator=, but MSVC does not like Base::Base, 00243 // see bugs 821 and 920. 00244 using ReadOnlyMapBase::Base::operator=; 00245 }; 00246 00247 #undef EIGEN_STATIC_ASSERT_INDEX_BASED_ACCESS 00248 00249 } // end namespace Eigen 00250 00251 #endif // EIGEN_MAPBASE_H
Generated on Tue Jul 12 2022 17:46:57 by
1.7.2