|
||||
File indexing completed on 2025-01-18 09:56:14
0001 // This file is part of Eigen, a lightweight C++ template library 0002 // for linear algebra. 0003 // 0004 // Copyright (C) 2007-2010 Benoit Jacob <jacob.benoit.1@gmail.com> 0005 // Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr> 0006 // 0007 // This Source Code Form is subject to the terms of the Mozilla 0008 // Public License v. 2.0. If a copy of the MPL was not distributed 0009 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 0010 0011 #ifndef EIGEN_MAP_H 0012 #define EIGEN_MAP_H 0013 0014 namespace Eigen { 0015 0016 namespace internal { 0017 template<typename PlainObjectType, int MapOptions, typename StrideType> 0018 struct traits<Map<PlainObjectType, MapOptions, StrideType> > 0019 : public traits<PlainObjectType> 0020 { 0021 typedef traits<PlainObjectType> TraitsBase; 0022 enum { 0023 PlainObjectTypeInnerSize = ((traits<PlainObjectType>::Flags&RowMajorBit)==RowMajorBit) 0024 ? PlainObjectType::ColsAtCompileTime 0025 : PlainObjectType::RowsAtCompileTime, 0026 0027 InnerStrideAtCompileTime = StrideType::InnerStrideAtCompileTime == 0 0028 ? int(PlainObjectType::InnerStrideAtCompileTime) 0029 : int(StrideType::InnerStrideAtCompileTime), 0030 OuterStrideAtCompileTime = StrideType::OuterStrideAtCompileTime == 0 0031 ? (InnerStrideAtCompileTime==Dynamic || PlainObjectTypeInnerSize==Dynamic 0032 ? Dynamic 0033 : int(InnerStrideAtCompileTime) * int(PlainObjectTypeInnerSize)) 0034 : int(StrideType::OuterStrideAtCompileTime), 0035 Alignment = int(MapOptions)&int(AlignedMask), 0036 Flags0 = TraitsBase::Flags & (~NestByRefBit), 0037 Flags = is_lvalue<PlainObjectType>::value ? int(Flags0) : (int(Flags0) & ~LvalueBit) 0038 }; 0039 private: 0040 enum { Options }; // Expressions don't have Options 0041 }; 0042 } 0043 0044 /** \class Map 0045 * \ingroup Core_Module 0046 * 0047 * \brief A matrix or vector expression mapping an existing array of data. 0048 * 0049 * \tparam PlainObjectType the equivalent matrix type of the mapped data 0050 * \tparam MapOptions specifies the pointer alignment in bytes. It can be: \c #Aligned128, \c #Aligned64, \c #Aligned32, \c #Aligned16, \c #Aligned8 or \c #Unaligned. 0051 * The default is \c #Unaligned. 0052 * \tparam StrideType optionally specifies strides. By default, Map assumes the memory layout 0053 * of an ordinary, contiguous array. This can be overridden by specifying strides. 0054 * The type passed here must be a specialization of the Stride template, see examples below. 0055 * 0056 * This class represents a matrix or vector expression mapping an existing array of data. 0057 * It can be used to let Eigen interface without any overhead with non-Eigen data structures, 0058 * such as plain C arrays or structures from other libraries. By default, it assumes that the 0059 * data is laid out contiguously in memory. You can however override this by explicitly specifying 0060 * inner and outer strides. 0061 * 0062 * Here's an example of simply mapping a contiguous array as a \ref TopicStorageOrders "column-major" matrix: 0063 * \include Map_simple.cpp 0064 * Output: \verbinclude Map_simple.out 0065 * 0066 * If you need to map non-contiguous arrays, you can do so by specifying strides: 0067 * 0068 * Here's an example of mapping an array as a vector, specifying an inner stride, that is, the pointer 0069 * increment between two consecutive coefficients. Here, we're specifying the inner stride as a compile-time 0070 * fixed value. 0071 * \include Map_inner_stride.cpp 0072 * Output: \verbinclude Map_inner_stride.out 0073 * 0074 * Here's an example of mapping an array while specifying an outer stride. Here, since we're mapping 0075 * as a column-major matrix, 'outer stride' means the pointer increment between two consecutive columns. 0076 * Here, we're specifying the outer stride as a runtime parameter. Note that here \c OuterStride<> is 0077 * a short version of \c OuterStride<Dynamic> because the default template parameter of OuterStride 0078 * is \c Dynamic 0079 * \include Map_outer_stride.cpp 0080 * Output: \verbinclude Map_outer_stride.out 0081 * 0082 * For more details and for an example of specifying both an inner and an outer stride, see class Stride. 0083 * 0084 * \b Tip: to change the array of data mapped by a Map object, you can use the C++ 0085 * placement new syntax: 0086 * 0087 * Example: \include Map_placement_new.cpp 0088 * Output: \verbinclude Map_placement_new.out 0089 * 0090 * This class is the return type of PlainObjectBase::Map() but can also be used directly. 0091 * 0092 * \sa PlainObjectBase::Map(), \ref TopicStorageOrders 0093 */ 0094 template<typename PlainObjectType, int MapOptions, typename StrideType> class Map 0095 : public MapBase<Map<PlainObjectType, MapOptions, StrideType> > 0096 { 0097 public: 0098 0099 typedef MapBase<Map> Base; 0100 EIGEN_DENSE_PUBLIC_INTERFACE(Map) 0101 0102 typedef typename Base::PointerType PointerType; 0103 typedef PointerType PointerArgType; 0104 EIGEN_DEVICE_FUNC 0105 inline PointerType cast_to_pointer_type(PointerArgType ptr) { return ptr; } 0106 0107 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR 0108 inline Index innerStride() const 0109 { 0110 return StrideType::InnerStrideAtCompileTime != 0 ? m_stride.inner() : 1; 0111 } 0112 0113 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR 0114 inline Index outerStride() const 0115 { 0116 return StrideType::OuterStrideAtCompileTime != 0 ? m_stride.outer() 0117 : internal::traits<Map>::OuterStrideAtCompileTime != Dynamic ? Index(internal::traits<Map>::OuterStrideAtCompileTime) 0118 : IsVectorAtCompileTime ? (this->size() * innerStride()) 0119 : int(Flags)&RowMajorBit ? (this->cols() * innerStride()) 0120 : (this->rows() * innerStride()); 0121 } 0122 0123 /** Constructor in the fixed-size case. 0124 * 0125 * \param dataPtr pointer to the array to map 0126 * \param stride optional Stride object, passing the strides. 0127 */ 0128 EIGEN_DEVICE_FUNC 0129 explicit inline Map(PointerArgType dataPtr, const StrideType& stride = StrideType()) 0130 : Base(cast_to_pointer_type(dataPtr)), m_stride(stride) 0131 { 0132 PlainObjectType::Base::_check_template_params(); 0133 } 0134 0135 /** Constructor in the dynamic-size vector case. 0136 * 0137 * \param dataPtr pointer to the array to map 0138 * \param size the size of the vector expression 0139 * \param stride optional Stride object, passing the strides. 0140 */ 0141 EIGEN_DEVICE_FUNC 0142 inline Map(PointerArgType dataPtr, Index size, const StrideType& stride = StrideType()) 0143 : Base(cast_to_pointer_type(dataPtr), size), m_stride(stride) 0144 { 0145 PlainObjectType::Base::_check_template_params(); 0146 } 0147 0148 /** Constructor in the dynamic-size matrix case. 0149 * 0150 * \param dataPtr pointer to the array to map 0151 * \param rows the number of rows of the matrix expression 0152 * \param cols the number of columns of the matrix expression 0153 * \param stride optional Stride object, passing the strides. 0154 */ 0155 EIGEN_DEVICE_FUNC 0156 inline Map(PointerArgType dataPtr, Index rows, Index cols, const StrideType& stride = StrideType()) 0157 : Base(cast_to_pointer_type(dataPtr), rows, cols), m_stride(stride) 0158 { 0159 PlainObjectType::Base::_check_template_params(); 0160 } 0161 0162 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Map) 0163 0164 protected: 0165 StrideType m_stride; 0166 }; 0167 0168 0169 } // end namespace Eigen 0170 0171 #endif // EIGEN_MAP_H
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |