Map.h
1// This file is part of Eigen, a lightweight C++ template library
2// for linear algebra.
3//
4// Copyright (C) 2007-2010 Benoit Jacob <jacob.benoit.1@gmail.com>
5// Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
6//
7// This Source Code Form is subject to the terms of the Mozilla
8// Public License v. 2.0. If a copy of the MPL was not distributed
9// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
10
11#ifndef EIGEN_MAP_H
12#define EIGEN_MAP_H
13
14namespace Eigen {
15
66
67namespace internal {
68template<typename PlainObjectType, int MapOptions, typename StrideType>
69struct traits<Map<PlainObjectType, MapOptions, StrideType> >
70 : public traits<PlainObjectType>
71{
72 typedef traits<PlainObjectType> TraitsBase;
73 typedef typename PlainObjectType::Index Index;
74 typedef typename PlainObjectType::Scalar Scalar;
75 enum {
76 InnerStrideAtCompileTime = StrideType::InnerStrideAtCompileTime == 0
77 ? int(PlainObjectType::InnerStrideAtCompileTime)
78 : int(StrideType::InnerStrideAtCompileTime),
79 OuterStrideAtCompileTime = StrideType::OuterStrideAtCompileTime == 0
80 ? int(PlainObjectType::OuterStrideAtCompileTime)
81 : int(StrideType::OuterStrideAtCompileTime),
82 HasNoInnerStride = InnerStrideAtCompileTime == 1,
83 HasNoOuterStride = StrideType::OuterStrideAtCompileTime == 0,
84 HasNoStride = HasNoInnerStride && HasNoOuterStride,
85 IsAligned = bool(EIGEN_ALIGN) && ((int(MapOptions)&Aligned)==Aligned),
86 IsDynamicSize = PlainObjectType::SizeAtCompileTime==Dynamic,
87 KeepsPacketAccess = bool(HasNoInnerStride)
88 && ( bool(IsDynamicSize)
89 || HasNoOuterStride
90 || ( OuterStrideAtCompileTime!=Dynamic
91 && ((static_cast<int>(sizeof(Scalar))*OuterStrideAtCompileTime)%16)==0 ) ),
92 Flags0 = TraitsBase::Flags & (~NestByRefBit),
93 Flags1 = IsAligned ? (int(Flags0) | AlignedBit) : (int(Flags0) & ~AlignedBit),
94 Flags2 = (bool(HasNoStride) || bool(PlainObjectType::IsVectorAtCompileTime))
95 ? int(Flags1) : int(Flags1 & ~LinearAccessBit),
96 Flags3 = is_lvalue<PlainObjectType>::value ? int(Flags2) : (int(Flags2) & ~LvalueBit),
97 Flags = KeepsPacketAccess ? int(Flags3) : (int(Flags3) & ~PacketAccessBit)
98 };
99private:
100 enum { Options }; // Expressions don't have Options
101};
102}
103
104template<typename PlainObjectType, int MapOptions, typename StrideType> class Map
105 : public MapBase<Map<PlainObjectType, MapOptions, StrideType> >
106{
107 public:
108
109 typedef MapBase<Map> Base;
110 EIGEN_DENSE_PUBLIC_INTERFACE(Map)
111
112 typedef typename Base::PointerType PointerType;
113#if EIGEN2_SUPPORT_STAGE <= STAGE30_FULL_EIGEN3_API
114 typedef const Scalar* PointerArgType;
115 inline PointerType cast_to_pointer_type(PointerArgType ptr) { return const_cast<PointerType>(ptr); }
116#else
117 typedef PointerType PointerArgType;
118 inline PointerType cast_to_pointer_type(PointerArgType ptr) { return ptr; }
119#endif
120
121 inline Index innerStride() const
122 {
123 return StrideType::InnerStrideAtCompileTime != 0 ? m_stride.inner() : 1;
124 }
125
126 inline Index outerStride() const
127 {
128 return StrideType::OuterStrideAtCompileTime != 0 ? m_stride.outer()
129 : IsVectorAtCompileTime ? this->size()
130 : int(Flags)&RowMajorBit ? this->cols()
131 : this->rows();
132 }
133
139 inline Map(PointerArgType data, const StrideType& stride = StrideType())
140 : Base(cast_to_pointer_type(data)), m_stride(stride)
141 {
142 PlainObjectType::Base::_check_template_params();
143 }
144
151 inline Map(PointerArgType data, Index size, const StrideType& stride = StrideType())
152 : Base(cast_to_pointer_type(data), size), m_stride(stride)
153 {
154 PlainObjectType::Base::_check_template_params();
155 }
156
164 inline Map(PointerArgType data, Index rows, Index cols, const StrideType& stride = StrideType())
165 : Base(cast_to_pointer_type(data), rows, cols), m_stride(stride)
166 {
167 PlainObjectType::Base::_check_template_params();
168 }
169
170 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Map)
171
172 protected:
173 StrideType m_stride;
174};
175
176template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
177inline Array<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>
178 ::Array(const Scalar *data)
179{
180 this->_set_noalias(Eigen::Map<const Array>(data));
181}
182
183template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
184inline Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>
185 ::Matrix(const Scalar *data)
186{
187 this->_set_noalias(Eigen::Map<const Matrix>(data));
188}
189
190} // end namespace Eigen
191
192#endif // EIGEN_MAP_H
Base class for Map and Block expression with direct access.
Definition ForwardDeclarations.h:110
A matrix or vector expression mapping an existing array of data.
Definition Map.h:106
Map(PointerArgType data, Index rows, Index cols, const StrideType &stride=StrideType())
Definition Map.h:164
Map(PointerArgType data, const StrideType &stride=StrideType())
Definition Map.h:139
Map(PointerArgType data, Index size, const StrideType &stride=StrideType())
Definition Map.h:151
@ Aligned
Definition Constants.h:189
const unsigned int LvalueBit
Definition Constants.h:126
const unsigned int RowMajorBit
Definition Constants.h:48
const unsigned int AlignedBit
Definition Constants.h:142
const unsigned int PacketAccessBit
Definition Constants.h:76
const unsigned int LinearAccessBit
Definition Constants.h:112
Definition LDLT.h:18