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.
Map.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_MAP_H 00012 #define EIGEN_MAP_H 00013 00014 namespace Eigen { 00015 00016 /** \class Map 00017 * \ingroup Core_Module 00018 * 00019 * \brief A matrix or vector expression mapping an existing array of data. 00020 * 00021 * \tparam PlainObjectType the equivalent matrix type of the mapped data 00022 * \tparam MapOptions specifies whether the pointer is \c #Aligned, or \c #Unaligned. 00023 * The default is \c #Unaligned. 00024 * \tparam StrideType optionally specifies strides. By default, Map assumes the memory layout 00025 * of an ordinary, contiguous array. This can be overridden by specifying strides. 00026 * The type passed here must be a specialization of the Stride template, see examples below. 00027 * 00028 * This class represents a matrix or vector expression mapping an existing array of data. 00029 * It can be used to let Eigen interface without any overhead with non-Eigen data structures, 00030 * such as plain C arrays or structures from other libraries. By default, it assumes that the 00031 * data is laid out contiguously in memory. You can however override this by explicitly specifying 00032 * inner and outer strides. 00033 * 00034 * Here's an example of simply mapping a contiguous array as a \ref TopicStorageOrders "column-major" matrix: 00035 * \include Map_simple.cpp 00036 * Output: \verbinclude Map_simple.out 00037 * 00038 * If you need to map non-contiguous arrays, you can do so by specifying strides: 00039 * 00040 * Here's an example of mapping an array as a vector, specifying an inner stride, that is, the pointer 00041 * increment between two consecutive coefficients. Here, we're specifying the inner stride as a compile-time 00042 * fixed value. 00043 * \include Map_inner_stride.cpp 00044 * Output: \verbinclude Map_inner_stride.out 00045 * 00046 * Here's an example of mapping an array while specifying an outer stride. Here, since we're mapping 00047 * as a column-major matrix, 'outer stride' means the pointer increment between two consecutive columns. 00048 * Here, we're specifying the outer stride as a runtime parameter. Note that here \c OuterStride<> is 00049 * a short version of \c OuterStride<Dynamic> because the default template parameter of OuterStride 00050 * is \c Dynamic 00051 * \include Map_outer_stride.cpp 00052 * Output: \verbinclude Map_outer_stride.out 00053 * 00054 * For more details and for an example of specifying both an inner and an outer stride, see class Stride. 00055 * 00056 * \b Tip: to change the array of data mapped by a Map object, you can use the C++ 00057 * placement new syntax: 00058 * 00059 * Example: \include Map_placement_new.cpp 00060 * Output: \verbinclude Map_placement_new.out 00061 * 00062 * This class is the return type of PlainObjectBase::Map() but can also be used directly. 00063 * 00064 * \sa PlainObjectBase::Map(), \ref TopicStorageOrders 00065 */ 00066 00067 namespace internal { 00068 template<typename PlainObjectType, int MapOptions, typename StrideType> 00069 struct traits<Map<PlainObjectType, MapOptions, StrideType> > 00070 : public traits<PlainObjectType> 00071 { 00072 typedef traits<PlainObjectType> TraitsBase; 00073 typedef typename PlainObjectType::Index Index; 00074 typedef typename PlainObjectType::Scalar Scalar; 00075 enum { 00076 InnerStrideAtCompileTime = StrideType::InnerStrideAtCompileTime == 0 00077 ? int(PlainObjectType::InnerStrideAtCompileTime) 00078 : int(StrideType::InnerStrideAtCompileTime), 00079 OuterStrideAtCompileTime = StrideType::OuterStrideAtCompileTime == 0 00080 ? int(PlainObjectType::OuterStrideAtCompileTime) 00081 : int(StrideType::OuterStrideAtCompileTime), 00082 HasNoInnerStride = InnerStrideAtCompileTime == 1, 00083 HasNoOuterStride = StrideType::OuterStrideAtCompileTime == 0, 00084 HasNoStride = HasNoInnerStride && HasNoOuterStride, 00085 IsAligned = bool(EIGEN_ALIGN) && ((int(MapOptions)&Aligned)==Aligned), 00086 IsDynamicSize = PlainObjectType::SizeAtCompileTime==Dynamic, 00087 KeepsPacketAccess = bool(HasNoInnerStride) 00088 && ( bool(IsDynamicSize) 00089 || HasNoOuterStride 00090 || ( OuterStrideAtCompileTime!=Dynamic 00091 && ((static_cast<int>(sizeof(Scalar))*OuterStrideAtCompileTime)%16)==0 ) ), 00092 Flags0 = TraitsBase::Flags & (~NestByRefBit), 00093 Flags1 = IsAligned ? (int(Flags0) | AlignedBit) : (int(Flags0) & ~AlignedBit), 00094 Flags2 = (bool(HasNoStride) || bool(PlainObjectType::IsVectorAtCompileTime)) 00095 ? int(Flags1) : int(Flags1 & ~LinearAccessBit), 00096 Flags3 = is_lvalue<PlainObjectType>::value ? int(Flags2) : (int(Flags2) & ~LvalueBit), 00097 Flags = KeepsPacketAccess ? int(Flags3) : (int(Flags3) & ~PacketAccessBit) 00098 }; 00099 private: 00100 enum { Options }; // Expressions don't have Options 00101 }; 00102 } 00103 00104 template<typename PlainObjectType, int MapOptions, typename StrideType> class Map 00105 : public MapBase<Map<PlainObjectType, MapOptions, StrideType> > 00106 { 00107 public: 00108 00109 typedef MapBase<Map> Base; 00110 EIGEN_DENSE_PUBLIC_INTERFACE(Map) 00111 00112 typedef typename Base::PointerType PointerType; 00113 #if EIGEN2_SUPPORT_STAGE <= STAGE30_FULL_EIGEN3_API 00114 typedef const Scalar* PointerArgType; 00115 inline PointerType cast_to_pointer_type(PointerArgType ptr) { return const_cast<PointerType>(ptr); } 00116 #else 00117 typedef PointerType PointerArgType; 00118 inline PointerType cast_to_pointer_type(PointerArgType ptr) { return ptr; } 00119 #endif 00120 00121 inline Index innerStride() const 00122 { 00123 return StrideType::InnerStrideAtCompileTime != 0 ? m_stride.inner() : 1; 00124 } 00125 00126 inline Index outerStride() const 00127 { 00128 return StrideType::OuterStrideAtCompileTime != 0 ? m_stride.outer() 00129 : IsVectorAtCompileTime ? this->size() 00130 : int(Flags)&RowMajorBit ? this->cols() 00131 : this->rows(); 00132 } 00133 00134 /** Constructor in the fixed-size case. 00135 * 00136 * \param dataPtr pointer to the array to map 00137 * \param a_stride optional Stride object, passing the strides. 00138 */ 00139 inline Map(PointerArgType dataPtr, const StrideType& a_stride = StrideType()) 00140 : Base(cast_to_pointer_type(dataPtr)), m_stride(a_stride) 00141 { 00142 PlainObjectType::Base::_check_template_params(); 00143 } 00144 00145 /** Constructor in the dynamic-size vector case. 00146 * 00147 * \param dataPtr pointer to the array to map 00148 * \param a_size the size of the vector expression 00149 * \param a_stride optional Stride object, passing the strides. 00150 */ 00151 inline Map(PointerArgType dataPtr, Index a_size, const StrideType& a_stride = StrideType()) 00152 : Base(cast_to_pointer_type(dataPtr), a_size), m_stride(a_stride) 00153 { 00154 PlainObjectType::Base::_check_template_params(); 00155 } 00156 00157 /** Constructor in the dynamic-size matrix case. 00158 * 00159 * \param dataPtr pointer to the array to map 00160 * \param nbRows the number of rows of the matrix expression 00161 * \param nbCols the number of columns of the matrix expression 00162 * \param a_stride optional Stride object, passing the strides. 00163 */ 00164 inline Map(PointerArgType dataPtr, Index nbRows, Index nbCols, const StrideType& a_stride = StrideType()) 00165 : Base(cast_to_pointer_type(dataPtr), nbRows, nbCols), m_stride(a_stride) 00166 { 00167 PlainObjectType::Base::_check_template_params(); 00168 } 00169 00170 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Map) 00171 00172 protected: 00173 StrideType m_stride; 00174 }; 00175 00176 template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols> 00177 inline Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> 00178 ::Array(const Scalar *data) 00179 { 00180 this->_set_noalias(Eigen::Map<const Array>(data)); 00181 } 00182 00183 template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols> 00184 inline Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> 00185 ::Matrix(const Scalar *data) 00186 { 00187 this->_set_noalias(Eigen::Map<const Matrix>(data)); 00188 } 00189 00190 } // end namespace Eigen 00191 00192 #endif // EIGEN_MAP_H
Generated on Thu Nov 17 2022 22:01:29 by
1.7.2