1
// This file is part of Eigen, a lightweight C++ template library
4
// Copyright (C) 2010 Benoit Jacob <jacob.benoit.1@gmail.com>
6
// Eigen is free software; you can redistribute it and/or
7
// modify it under the terms of the GNU Lesser General Public
8
// License as published by the Free Software Foundation; either
9
// version 3 of the License, or (at your option) any later version.
11
// Alternatively, you can redistribute it and/or
12
// modify it under the terms of the GNU General Public License as
13
// published by the Free Software Foundation; either version 2 of
14
// the License, or (at your option) any later version.
16
// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
17
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18
// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
19
// GNU General Public License for more details.
21
// You should have received a copy of the GNU Lesser General Public
22
// License and a copy of the GNU General Public License along with
23
// Eigen. If not, see <http://www.gnu.org/licenses/>.
25
#ifndef EIGEN_STRIDE_H
26
#define EIGEN_STRIDE_H
29
* \ingroup Core_Module
31
* \brief Holds strides information for Map
33
* This class holds the strides information for mapping arrays with strides with class Map.
35
* It holds two values: the inner stride and the outer stride.
37
* The inner stride is the pointer increment between two consecutive entries within a given row of a
38
* row-major matrix or within a given column of a column-major matrix.
40
* The outer stride is the pointer increment between two consecutive rows of a row-major matrix or
41
* between two consecutive columns of a column-major matrix.
43
* These two values can be passed either at compile-time as template parameters, or at runtime as
44
* arguments to the constructor.
46
* Indeed, this class takes two template parameters:
47
* \param _OuterStrideAtCompileTime the outer stride, or Dynamic if you want to specify it at runtime.
48
* \param _InnerStrideAtCompileTime the inner stride, or Dynamic if you want to specify it at runtime.
51
* \include Map_general_stride.cpp
52
* Output: \verbinclude Map_general_stride.out
54
* \sa class InnerStride, class OuterStride, \ref TopicStorageOrders
56
template<int _OuterStrideAtCompileTime, int _InnerStrideAtCompileTime>
60
typedef DenseIndex Index;
62
InnerStrideAtCompileTime = _InnerStrideAtCompileTime,
63
OuterStrideAtCompileTime = _OuterStrideAtCompileTime
66
/** Default constructor, for use when strides are fixed at compile time */
68
: m_outer(OuterStrideAtCompileTime), m_inner(InnerStrideAtCompileTime)
70
eigen_assert(InnerStrideAtCompileTime != Dynamic && OuterStrideAtCompileTime != Dynamic);
73
/** Constructor allowing to pass the strides at runtime */
74
Stride(Index outerStride, Index innerStride)
75
: m_outer(outerStride), m_inner(innerStride)
77
eigen_assert(innerStride>=0 && outerStride>=0);
80
/** Copy constructor */
81
Stride(const Stride& other)
82
: m_outer(other.outer()), m_inner(other.inner())
85
/** \returns the outer stride */
86
inline Index outer() const { return m_outer.value(); }
87
/** \returns the inner stride */
88
inline Index inner() const { return m_inner.value(); }
91
internal::variable_if_dynamic<Index, OuterStrideAtCompileTime> m_outer;
92
internal::variable_if_dynamic<Index, InnerStrideAtCompileTime> m_inner;
95
/** \brief Convenience specialization of Stride to specify only an inner stride
96
* See class Map for some examples */
97
template<int Value = Dynamic>
98
class InnerStride : public Stride<0, Value>
100
typedef Stride<0, Value> Base;
102
typedef DenseIndex Index;
103
InnerStride() : Base() {}
104
InnerStride(Index v) : Base(0, v) {}
107
/** \brief Convenience specialization of Stride to specify only an outer stride
108
* See class Map for some examples */
109
template<int Value = Dynamic>
110
class OuterStride : public Stride<Value, 0>
112
typedef Stride<Value, 0> Base;
114
typedef DenseIndex Index;
115
OuterStride() : Base() {}
116
OuterStride(Index v) : Base(v,0) {}
119
#endif // EIGEN_STRIDE_H