~choreonoid/choreonoid/debian

« back to all changes in this revision

Viewing changes to thirdparty/eigen3/Eigen/src/Eigen2Support/Block.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) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr>
 
5
// Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
 
6
//
 
7
// Eigen is free software; you can redistribute it and/or
 
8
// modify it under the terms of the GNU Lesser General Public
 
9
// License as published by the Free Software Foundation; either
 
10
// version 3 of the License, or (at your option) any later version.
 
11
//
 
12
// Alternatively, you can redistribute it and/or
 
13
// modify it under the terms of the GNU General Public License as
 
14
// published by the Free Software Foundation; either version 2 of
 
15
// the License, or (at your option) any later version.
 
16
//
 
17
// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
 
18
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 
19
// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
 
20
// GNU General Public License for more details.
 
21
//
 
22
// You should have received a copy of the GNU Lesser General Public
 
23
// License and a copy of the GNU General Public License along with
 
24
// Eigen. If not, see <http://www.gnu.org/licenses/>.
 
25
 
 
26
#ifndef EIGEN_BLOCK2_H
 
27
#define EIGEN_BLOCK2_H
 
28
 
 
29
/** \returns a dynamic-size expression of a corner of *this.
 
30
  *
 
31
  * \param type the type of corner. Can be \a Eigen::TopLeft, \a Eigen::TopRight,
 
32
  * \a Eigen::BottomLeft, \a Eigen::BottomRight.
 
33
  * \param cRows the number of rows in the corner
 
34
  * \param cCols the number of columns in the corner
 
35
  *
 
36
  * Example: \include MatrixBase_corner_enum_int_int.cpp
 
37
  * Output: \verbinclude MatrixBase_corner_enum_int_int.out
 
38
  *
 
39
  * \note Even though the returned expression has dynamic size, in the case
 
40
  * when it is applied to a fixed-size matrix, it inherits a fixed maximal size,
 
41
  * which means that evaluating it does not cause a dynamic memory allocation.
 
42
  *
 
43
  * \sa class Block, block(Index,Index,Index,Index)
 
44
  */
 
45
template<typename Derived>
 
46
inline Block<Derived> DenseBase<Derived>
 
47
  ::corner(CornerType type, Index cRows, Index cCols)
 
48
{
 
49
  switch(type)
 
50
  {
 
51
    default:
 
52
      eigen_assert(false && "Bad corner type.");
 
53
    case TopLeft:
 
54
      return Block<Derived>(derived(), 0, 0, cRows, cCols);
 
55
    case TopRight:
 
56
      return Block<Derived>(derived(), 0, cols() - cCols, cRows, cCols);
 
57
    case BottomLeft:
 
58
      return Block<Derived>(derived(), rows() - cRows, 0, cRows, cCols);
 
59
    case BottomRight:
 
60
      return Block<Derived>(derived(), rows() - cRows, cols() - cCols, cRows, cCols);
 
61
  }
 
62
}
 
63
 
 
64
/** This is the const version of corner(CornerType, Index, Index).*/
 
65
template<typename Derived>
 
66
inline const Block<Derived>
 
67
DenseBase<Derived>::corner(CornerType type, Index cRows, Index cCols) const
 
68
{
 
69
  switch(type)
 
70
  {
 
71
    default:
 
72
      eigen_assert(false && "Bad corner type.");
 
73
    case TopLeft:
 
74
      return Block<Derived>(derived(), 0, 0, cRows, cCols);
 
75
    case TopRight:
 
76
      return Block<Derived>(derived(), 0, cols() - cCols, cRows, cCols);
 
77
    case BottomLeft:
 
78
      return Block<Derived>(derived(), rows() - cRows, 0, cRows, cCols);
 
79
    case BottomRight:
 
80
      return Block<Derived>(derived(), rows() - cRows, cols() - cCols, cRows, cCols);
 
81
  }
 
82
}
 
83
 
 
84
/** \returns a fixed-size expression of a corner of *this.
 
85
  *
 
86
  * \param type the type of corner. Can be \a Eigen::TopLeft, \a Eigen::TopRight,
 
87
  * \a Eigen::BottomLeft, \a Eigen::BottomRight.
 
88
  *
 
89
  * The template parameters CRows and CCols arethe number of rows and columns in the corner.
 
90
  *
 
91
  * Example: \include MatrixBase_template_int_int_corner_enum.cpp
 
92
  * Output: \verbinclude MatrixBase_template_int_int_corner_enum.out
 
93
  *
 
94
  * \sa class Block, block(Index,Index,Index,Index)
 
95
  */
 
96
template<typename Derived>
 
97
template<int CRows, int CCols>
 
98
inline Block<Derived, CRows, CCols>
 
99
DenseBase<Derived>::corner(CornerType type)
 
100
{
 
101
  switch(type)
 
102
  {
 
103
    default:
 
104
      eigen_assert(false && "Bad corner type.");
 
105
    case TopLeft:
 
106
      return Block<Derived, CRows, CCols>(derived(), 0, 0);
 
107
    case TopRight:
 
108
      return Block<Derived, CRows, CCols>(derived(), 0, cols() - CCols);
 
109
    case BottomLeft:
 
110
      return Block<Derived, CRows, CCols>(derived(), rows() - CRows, 0);
 
111
    case BottomRight:
 
112
      return Block<Derived, CRows, CCols>(derived(), rows() - CRows, cols() - CCols);
 
113
  }
 
114
}
 
115
 
 
116
/** This is the const version of corner<int, int>(CornerType).*/
 
117
template<typename Derived>
 
118
template<int CRows, int CCols>
 
119
inline const Block<Derived, CRows, CCols>
 
120
DenseBase<Derived>::corner(CornerType type) const
 
121
{
 
122
  switch(type)
 
123
  {
 
124
    default:
 
125
      eigen_assert(false && "Bad corner type.");
 
126
    case TopLeft:
 
127
      return Block<Derived, CRows, CCols>(derived(), 0, 0);
 
128
    case TopRight:
 
129
      return Block<Derived, CRows, CCols>(derived(), 0, cols() - CCols);
 
130
    case BottomLeft:
 
131
      return Block<Derived, CRows, CCols>(derived(), rows() - CRows, 0);
 
132
    case BottomRight:
 
133
      return Block<Derived, CRows, CCols>(derived(), rows() - CRows, cols() - CCols);
 
134
  }
 
135
}
 
136
 
 
137
#endif // EIGEN_BLOCK2_H