Eigen  5.0.1
 
Loading...
Searching...
No Matches
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// SPDX-License-Identifier: MPL-2.0
11
12#ifndef EIGEN_MAP_H
13#define EIGEN_MAP_H
14
15// IWYU pragma: private
16#include "./InternalHeaderCheck.h"
17
18namespace Eigen {
19
20namespace internal {
21template <typename PlainObjectType, int MapOptions, typename StrideType>
22struct traits<Map<PlainObjectType, MapOptions, StrideType> > : public traits<PlainObjectType> {
23 using TraitsBase = traits<PlainObjectType>;
24 enum {
25 PlainObjectTypeInnerSize = ((traits<PlainObjectType>::Flags & RowMajorBit) == RowMajorBit)
26 ? PlainObjectType::ColsAtCompileTime
27 : PlainObjectType::RowsAtCompileTime,
28
29 InnerStrideAtCompileTime = StrideType::InnerStrideAtCompileTime == 0
30 ? int(PlainObjectType::InnerStrideAtCompileTime)
31 : int(StrideType::InnerStrideAtCompileTime),
32 OuterStrideAtCompileTime = StrideType::OuterStrideAtCompileTime == 0
33 ? (InnerStrideAtCompileTime == Dynamic || PlainObjectTypeInnerSize == Dynamic
34 ? Dynamic
35 : int(InnerStrideAtCompileTime) * int(PlainObjectTypeInnerSize))
36 : int(StrideType::OuterStrideAtCompileTime),
37 Alignment = int(MapOptions) & int(AlignedMask),
38 Flags0 = TraitsBase::Flags & (~NestByRefBit),
39 Flags = is_lvalue<PlainObjectType>::value ? int(Flags0) : (int(Flags0) & ~LvalueBit)
40 };
41
42 private:
43 enum { Options }; // Expressions don't have Options
44};
45} // namespace internal
46
96template <typename PlainObjectType, int MapOptions, typename StrideType>
97class Map : public MapBase<Map<PlainObjectType, MapOptions, StrideType> > {
98 public:
99 using Base = MapBase<Map>;
100 EIGEN_DENSE_PUBLIC_INTERFACE(Map)
101
102 using PointerType = typename Base::PointerType;
103 using PointerArgType = PointerType;
104 EIGEN_DEVICE_FUNC constexpr inline PointerType cast_to_pointer_type(PointerArgType ptr) const { return ptr; }
105
106 EIGEN_DEVICE_FUNC constexpr Index innerStride() const {
107 return StrideType::InnerStrideAtCompileTime != 0 ? m_stride.inner() : 1;
108 }
109
110 EIGEN_DEVICE_FUNC constexpr Index outerStride() const {
111 return StrideType::OuterStrideAtCompileTime != 0 ? m_stride.outer()
112 : internal::traits<Map>::OuterStrideAtCompileTime != Dynamic
113 ? Index(internal::traits<Map>::OuterStrideAtCompileTime)
114 : IsVectorAtCompileTime ? (this->size() * innerStride())
115 : int(Flags) & RowMajorBit ? (this->cols() * innerStride())
116 : (this->rows() * innerStride());
117 }
118
124 EIGEN_DEVICE_FUNC constexpr explicit inline Map(PointerArgType dataPtr, const StrideType& stride = StrideType())
125 : Base(cast_to_pointer_type(dataPtr)), m_stride(stride) {}
126
133 EIGEN_DEVICE_FUNC constexpr inline Map(PointerArgType dataPtr, Index size, const StrideType& stride = StrideType())
134 : Base(cast_to_pointer_type(dataPtr), size), m_stride(stride) {}
135
143 EIGEN_DEVICE_FUNC constexpr inline Map(PointerArgType dataPtr, Index rows, Index cols,
144 const StrideType& stride = StrideType())
145 : Base(cast_to_pointer_type(dataPtr), rows, cols), m_stride(stride) {}
146
147 EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Map)
148
149 protected:
150 StrideType m_stride;
151};
152
153} // end namespace Eigen
154
155#endif // EIGEN_MAP_H
A matrix or vector expression mapping an existing array of data.
Definition Map.h:97
constexpr Map(PointerArgType dataPtr, Index rows, Index cols, const StrideType &stride=StrideType())
Definition Map.h:143
constexpr Map(PointerArgType dataPtr, const StrideType &stride=StrideType())
Definition Map.h:124
constexpr Map(PointerArgType dataPtr, Index size, const StrideType &stride=StrideType())
Definition Map.h:133
constexpr unsigned int LvalueBit
Definition Constants.h:149
constexpr unsigned int RowMajorBit
Definition Constants.h:71