Stride.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) 2010 Benoit Jacob <jacob.benoit.1@gmail.com>
5 //
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.
10 //
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.
15 //
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.
20 //
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/>.
24 
25 #ifndef EIGEN_STRIDE_H
26 #define EIGEN_STRIDE_H
27 
28 namespace Eigen {
29 
58 template<int _OuterStrideAtCompileTime, int _InnerStrideAtCompileTime>
59 class Stride
60 {
61  public:
62  typedef DenseIndex Index;
63  enum {
64  InnerStrideAtCompileTime = _InnerStrideAtCompileTime,
65  OuterStrideAtCompileTime = _OuterStrideAtCompileTime
66  };
67 
71  {
73  }
74 
76  Stride(Index outerStride, Index innerStride)
77  : m_outer(outerStride), m_inner(innerStride)
78  {
79  eigen_assert(innerStride>=0 && outerStride>=0);
80  }
81 
83  Stride(const Stride& other)
84  : m_outer(other.outer()), m_inner(other.inner())
85  {}
86 
88  inline Index outer() const { return m_outer.value(); }
90  inline Index inner() const { return m_inner.value(); }
91 
92  protected:
93  internal::variable_if_dynamic<Index, OuterStrideAtCompileTime> m_outer;
94  internal::variable_if_dynamic<Index, InnerStrideAtCompileTime> m_inner;
95 };
96 
99 template<int Value = Dynamic>
100 class InnerStride : public Stride<0, Value>
101 {
102  typedef Stride<0, Value> Base;
103  public:
104  typedef DenseIndex Index;
105  InnerStride() : Base() {}
106  InnerStride(Index v) : Base(0, v) {}
107 };
108 
111 template<int Value = Dynamic>
112 class OuterStride : public Stride<Value, 0>
113 {
114  typedef Stride<Value, 0> Base;
115  public:
116  typedef DenseIndex Index;
117  OuterStride() : Base() {}
118  OuterStride(Index v) : Base(v,0) {}
119 };
120 
121 } // end namespace Eigen
122 
123 #endif // EIGEN_STRIDE_H