~choreonoid/choreonoid/debian

« back to all changes in this revision

Viewing changes to thirdparty/eigen3/Eigen/src/Core/Stride.h

  • Committer: Thomas Moulard
  • Date: 2012-10-23 12:43:24 UTC
  • Revision ID: git-v1:351cf736ad49bc7a9a7b9767dee760a013517a5d
Tags: upstream/1.1.0
ImportedĀ UpstreamĀ versionĀ 1.1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
/** \class Stride
 
29
  * \ingroup Core_Module
 
30
  *
 
31
  * \brief Holds strides information for Map
 
32
  *
 
33
  * This class holds the strides information for mapping arrays with strides with class Map.
 
34
  *
 
35
  * It holds two values: the inner stride and the outer stride.
 
36
  *
 
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.
 
39
  *
 
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.
 
42
  *
 
43
  * These two values can be passed either at compile-time as template parameters, or at runtime as
 
44
  * arguments to the constructor.
 
45
  *
 
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.
 
49
  *
 
50
  * Here is an example:
 
51
  * \include Map_general_stride.cpp
 
52
  * Output: \verbinclude Map_general_stride.out
 
53
  *
 
54
  * \sa class InnerStride, class OuterStride, \ref TopicStorageOrders
 
55
  */
 
56
template<int _OuterStrideAtCompileTime, int _InnerStrideAtCompileTime>
 
57
class Stride
 
58
{
 
59
  public:
 
60
    typedef DenseIndex Index;
 
61
    enum {
 
62
      InnerStrideAtCompileTime = _InnerStrideAtCompileTime,
 
63
      OuterStrideAtCompileTime = _OuterStrideAtCompileTime
 
64
    };
 
65
 
 
66
    /** Default constructor, for use when strides are fixed at compile time */
 
67
    Stride()
 
68
      : m_outer(OuterStrideAtCompileTime), m_inner(InnerStrideAtCompileTime)
 
69
    {
 
70
      eigen_assert(InnerStrideAtCompileTime != Dynamic && OuterStrideAtCompileTime != Dynamic);
 
71
    }
 
72
 
 
73
    /** Constructor allowing to pass the strides at runtime */
 
74
    Stride(Index outerStride, Index innerStride)
 
75
      : m_outer(outerStride), m_inner(innerStride)
 
76
    {
 
77
      eigen_assert(innerStride>=0 && outerStride>=0);
 
78
    }
 
79
 
 
80
    /** Copy constructor */
 
81
    Stride(const Stride& other)
 
82
      : m_outer(other.outer()), m_inner(other.inner())
 
83
    {}
 
84
 
 
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(); }
 
89
 
 
90
  protected:
 
91
    internal::variable_if_dynamic<Index, OuterStrideAtCompileTime> m_outer;
 
92
    internal::variable_if_dynamic<Index, InnerStrideAtCompileTime> m_inner;
 
93
};
 
94
 
 
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>
 
99
{
 
100
    typedef Stride<0, Value> Base;
 
101
  public:
 
102
    typedef DenseIndex Index;
 
103
    InnerStride() : Base() {}
 
104
    InnerStride(Index v) : Base(0, v) {}
 
105
};
 
106
 
 
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>
 
111
{
 
112
    typedef Stride<Value, 0> Base;
 
113
  public:
 
114
    typedef DenseIndex Index;
 
115
    OuterStride() : Base() {}
 
116
    OuterStride(Index v) : Base(v,0) {}
 
117
};
 
118
 
 
119
#endif // EIGEN_STRIDE_H