Map.h
Go to the documentation of this file.
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 
14 // IWYU pragma: private
15 #include "./InternalHeaderCheck.h"
16 
17 namespace Eigen {
18 
19 namespace internal {
20 template <typename PlainObjectType, int MapOptions, typename StrideType>
21 struct traits<Map<PlainObjectType, MapOptions, StrideType> > : public traits<PlainObjectType> {
23  enum {
24  PlainObjectTypeInnerSize = ((traits<PlainObjectType>::Flags & RowMajorBit) == RowMajorBit)
25  ? PlainObjectType::ColsAtCompileTime
26  : PlainObjectType::RowsAtCompileTime,
27 
28  InnerStrideAtCompileTime = StrideType::InnerStrideAtCompileTime == 0
29  ? int(PlainObjectType::InnerStrideAtCompileTime)
30  : int(StrideType::InnerStrideAtCompileTime),
31  OuterStrideAtCompileTime = StrideType::OuterStrideAtCompileTime == 0
32  ? (InnerStrideAtCompileTime == Dynamic || PlainObjectTypeInnerSize == Dynamic
33  ? Dynamic
34  : int(InnerStrideAtCompileTime) * int(PlainObjectTypeInnerSize))
35  : int(StrideType::OuterStrideAtCompileTime),
36  Alignment = int(MapOptions) & int(AlignedMask),
37  Flags0 = TraitsBase::Flags & (~NestByRefBit),
38  Flags = is_lvalue<PlainObjectType>::value ? int(Flags0) : (int(Flags0) & ~LvalueBit)
39  };
40 
41  private:
42  enum { Options }; // Expressions don't have Options
43 };
44 } // namespace internal
45 
95 template <typename PlainObjectType, int MapOptions, typename StrideType>
96 class Map : public MapBase<Map<PlainObjectType, MapOptions, StrideType> > {
97  public:
98  typedef MapBase<Map> Base;
100 
101  typedef typename Base::PointerType PointerType;
103  EIGEN_DEVICE_FUNC inline PointerType cast_to_pointer_type(PointerArgType ptr) { return ptr; }
104 
106  return StrideType::InnerStrideAtCompileTime != 0 ? m_stride.inner() : 1;
107  }
108 
110  return StrideType::OuterStrideAtCompileTime != 0 ? m_stride.outer()
113  : IsVectorAtCompileTime ? (this->size() * innerStride())
114  : int(Flags) & RowMajorBit ? (this->cols() * innerStride())
115  : (this->rows() * innerStride());
116  }
117 
123  EIGEN_DEVICE_FUNC explicit inline Map(PointerArgType dataPtr, const StrideType& stride = StrideType())
124  : Base(cast_to_pointer_type(dataPtr)), m_stride(stride) {}
125 
132  EIGEN_DEVICE_FUNC inline Map(PointerArgType dataPtr, Index size, const StrideType& stride = StrideType())
133  : Base(cast_to_pointer_type(dataPtr), size), m_stride(stride) {}
134 
142  EIGEN_DEVICE_FUNC inline Map(PointerArgType dataPtr, Index rows, Index cols, const StrideType& stride = StrideType())
143  : Base(cast_to_pointer_type(dataPtr), rows, cols), m_stride(stride) {}
144 
146 
147  protected:
148  StrideType m_stride;
149 };
150 
151 } // end namespace Eigen
152 
153 #endif // EIGEN_MAP_H
#define EIGEN_CONSTEXPR
Definition: Macros.h:758
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:892
#define EIGEN_DENSE_PUBLIC_INTERFACE(Derived)
Definition: Macros.h:1171
#define EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Derived)
Macro to manually inherit assignment operators. This is necessary, because the implicitly defined ass...
Definition: Macros.h:1126
int rows
Definition: Tutorial_commainit_02.cpp:1
int cols
Definition: Tutorial_commainit_02.cpp:1
Scalar Scalar int size
Definition: benchVecAdd.cpp:17
Definition: ForwardDeclarations.h:150
A matrix or vector expression mapping an existing array of data.
Definition: Map.h:96
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index innerStride() const
Definition: Map.h:105
Base::PointerType PointerType
Definition: Map.h:101
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR Index outerStride() const
Definition: Map.h:109
StrideType m_stride
Definition: Map.h:148
EIGEN_DEVICE_FUNC Map(PointerArgType dataPtr, Index size, const StrideType &stride=StrideType())
Definition: Map.h:132
EIGEN_DEVICE_FUNC Map(PointerArgType dataPtr, Index rows, Index cols, const StrideType &stride=StrideType())
Definition: Map.h:142
MapBase< Map > Base
Definition: Map.h:98
EIGEN_DEVICE_FUNC Map(PointerArgType dataPtr, const StrideType &stride=StrideType())
Definition: Map.h:123
PointerType PointerArgType
Definition: Map.h:102
@ AlignedMask
Definition: Constants.h:241
const unsigned int LvalueBit
Definition: Constants.h:148
const unsigned int RowMajorBit
Definition: Constants.h:70
return int(ret)+1
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:70
squared absolute value
Definition: GlobalFunctions.h:87
const unsigned int NestByRefBit
Definition: Constants.h:173
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:83
const int Dynamic
Definition: Constants.h:25
Extend namespace for flags.
Definition: fsi_chan_precond_driver.cc:56
Definition: Eigen_Colamd.h:49
Definition: XprHelper.h:819
Definition: ForwardDeclarations.h:21