BlockMethods.h
1// This file is part of Eigen, a lightweight C++ template library
2// for linear algebra.
3//
4// Copyright (C) 2008-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
5// Copyright (C) 2006-2010 Benoit Jacob <jacob.benoit.1@gmail.com>
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_BLOCKMETHODS_H
12#define EIGEN_BLOCKMETHODS_H
13
14#ifndef EIGEN_PARSED_BY_DOXYGEN
15
17typedef Block<Derived, internal::traits<Derived>::RowsAtCompileTime, 1, !IsRowMajor> ColXpr;
18typedef const Block<const Derived, internal::traits<Derived>::RowsAtCompileTime, 1, !IsRowMajor> ConstColXpr;
20typedef Block<Derived, 1, internal::traits<Derived>::ColsAtCompileTime, IsRowMajor> RowXpr;
21typedef const Block<const Derived, 1, internal::traits<Derived>::ColsAtCompileTime, IsRowMajor> ConstRowXpr;
23typedef Block<Derived, internal::traits<Derived>::RowsAtCompileTime, Dynamic, !IsRowMajor> ColsBlockXpr;
24typedef const Block<const Derived, internal::traits<Derived>::RowsAtCompileTime, Dynamic, !IsRowMajor> ConstColsBlockXpr;
26typedef Block<Derived, Dynamic, internal::traits<Derived>::ColsAtCompileTime, IsRowMajor> RowsBlockXpr;
27typedef const Block<const Derived, Dynamic, internal::traits<Derived>::ColsAtCompileTime, IsRowMajor> ConstRowsBlockXpr;
29template<int N> struct NColsBlockXpr { typedef Block<Derived, internal::traits<Derived>::RowsAtCompileTime, N, !IsRowMajor> Type; };
30template<int N> struct ConstNColsBlockXpr { typedef const Block<const Derived, internal::traits<Derived>::RowsAtCompileTime, N, !IsRowMajor> Type; };
32template<int N> struct NRowsBlockXpr { typedef Block<Derived, N, internal::traits<Derived>::ColsAtCompileTime, IsRowMajor> Type; };
33template<int N> struct ConstNRowsBlockXpr { typedef const Block<const Derived, N, internal::traits<Derived>::ColsAtCompileTime, IsRowMajor> Type; };
34
35
36#endif // not EIGEN_PARSED_BY_DOXYGEN
37
54inline Block<Derived> block(Index startRow, Index startCol, Index blockRows, Index blockCols)
55{
56 return Block<Derived>(derived(), startRow, startCol, blockRows, blockCols);
57}
58
60inline const Block<const Derived> block(Index startRow, Index startCol, Index blockRows, Index blockCols) const
61{
62 return Block<const Derived>(derived(), startRow, startCol, blockRows, blockCols);
63}
64
65
66
67
78inline Block<Derived> topRightCorner(Index cRows, Index cCols)
79{
80 return Block<Derived>(derived(), 0, cols() - cCols, cRows, cCols);
81}
82
84inline const Block<const Derived> topRightCorner(Index cRows, Index cCols) const
85{
86 return Block<const Derived>(derived(), 0, cols() - cCols, cRows, cCols);
87}
88
98template<int CRows, int CCols>
99inline Block<Derived, CRows, CCols> topRightCorner()
100{
101 return Block<Derived, CRows, CCols>(derived(), 0, cols() - CCols);
102}
103
105template<int CRows, int CCols>
106inline const Block<const Derived, CRows, CCols> topRightCorner() const
107{
108 return Block<const Derived, CRows, CCols>(derived(), 0, cols() - CCols);
109}
110
111
112
113
124inline Block<Derived> topLeftCorner(Index cRows, Index cCols)
125{
126 return Block<Derived>(derived(), 0, 0, cRows, cCols);
127}
128
130inline const Block<const Derived> topLeftCorner(Index cRows, Index cCols) const
131{
132 return Block<const Derived>(derived(), 0, 0, cRows, cCols);
133}
134
144template<int CRows, int CCols>
145inline Block<Derived, CRows, CCols> topLeftCorner()
146{
147 return Block<Derived, CRows, CCols>(derived(), 0, 0);
148}
149
151template<int CRows, int CCols>
152inline const Block<const Derived, CRows, CCols> topLeftCorner() const
153{
154 return Block<const Derived, CRows, CCols>(derived(), 0, 0);
155}
156
157
158
169inline Block<Derived> bottomRightCorner(Index cRows, Index cCols)
170{
171 return Block<Derived>(derived(), rows() - cRows, cols() - cCols, cRows, cCols);
172}
173
175inline const Block<const Derived> bottomRightCorner(Index cRows, Index cCols) const
176{
177 return Block<const Derived>(derived(), rows() - cRows, cols() - cCols, cRows, cCols);
178}
179
189template<int CRows, int CCols>
190inline Block<Derived, CRows, CCols> bottomRightCorner()
191{
192 return Block<Derived, CRows, CCols>(derived(), rows() - CRows, cols() - CCols);
193}
194
196template<int CRows, int CCols>
197inline const Block<const Derived, CRows, CCols> bottomRightCorner() const
198{
199 return Block<const Derived, CRows, CCols>(derived(), rows() - CRows, cols() - CCols);
200}
201
202
203
214inline Block<Derived> bottomLeftCorner(Index cRows, Index cCols)
215{
216 return Block<Derived>(derived(), rows() - cRows, 0, cRows, cCols);
217}
218
220inline const Block<const Derived> bottomLeftCorner(Index cRows, Index cCols) const
221{
222 return Block<const Derived>(derived(), rows() - cRows, 0, cRows, cCols);
223}
224
234template<int CRows, int CCols>
235inline Block<Derived, CRows, CCols> bottomLeftCorner()
236{
237 return Block<Derived, CRows, CCols>(derived(), rows() - CRows, 0);
238}
239
241template<int CRows, int CCols>
242inline const Block<const Derived, CRows, CCols> bottomLeftCorner() const
243{
244 return Block<const Derived, CRows, CCols>(derived(), rows() - CRows, 0);
245}
246
247
248
258inline RowsBlockXpr topRows(Index n)
259{
260 return RowsBlockXpr(derived(), 0, 0, n, cols());
261}
262
264inline ConstRowsBlockXpr topRows(Index n) const
265{
266 return ConstRowsBlockXpr(derived(), 0, 0, n, cols());
267}
268
278template<int N>
279inline typename NRowsBlockXpr<N>::Type topRows()
280{
281 return typename NRowsBlockXpr<N>::Type(derived(), 0, 0, N, cols());
282}
283
285template<int N>
286inline typename ConstNRowsBlockXpr<N>::Type topRows() const
287{
288 return typename ConstNRowsBlockXpr<N>::Type(derived(), 0, 0, N, cols());
289}
290
291
292
302inline RowsBlockXpr bottomRows(Index n)
303{
304 return RowsBlockXpr(derived(), rows() - n, 0, n, cols());
305}
306
308inline ConstRowsBlockXpr bottomRows(Index n) const
309{
310 return ConstRowsBlockXpr(derived(), rows() - n, 0, n, cols());
311}
312
322template<int N>
323inline typename NRowsBlockXpr<N>::Type bottomRows()
324{
325 return typename NRowsBlockXpr<N>::Type(derived(), rows() - N, 0, N, cols());
326}
327
329template<int N>
330inline typename ConstNRowsBlockXpr<N>::Type bottomRows() const
331{
332 return typename ConstNRowsBlockXpr<N>::Type(derived(), rows() - N, 0, N, cols());
333}
334
335
336
347inline RowsBlockXpr middleRows(Index startRow, Index numRows)
348{
349 return RowsBlockXpr(derived(), startRow, 0, numRows, cols());
350}
351
353inline ConstRowsBlockXpr middleRows(Index startRow, Index numRows) const
354{
355 return ConstRowsBlockXpr(derived(), startRow, 0, numRows, cols());
356}
357
368template<int N>
369inline typename NRowsBlockXpr<N>::Type middleRows(Index startRow)
370{
371 return typename NRowsBlockXpr<N>::Type(derived(), startRow, 0, N, cols());
372}
373
375template<int N>
376inline typename ConstNRowsBlockXpr<N>::Type middleRows(Index startRow) const
377{
378 return typename ConstNRowsBlockXpr<N>::Type(derived(), startRow, 0, N, cols());
379}
380
381
382
392inline ColsBlockXpr leftCols(Index n)
393{
394 return ColsBlockXpr(derived(), 0, 0, rows(), n);
395}
396
398inline ConstColsBlockXpr leftCols(Index n) const
399{
400 return ConstColsBlockXpr(derived(), 0, 0, rows(), n);
401}
402
412template<int N>
413inline typename NColsBlockXpr<N>::Type leftCols()
414{
415 return typename NColsBlockXpr<N>::Type(derived(), 0, 0, rows(), N);
416}
417
419template<int N>
420inline typename ConstNColsBlockXpr<N>::Type leftCols() const
421{
422 return typename ConstNColsBlockXpr<N>::Type(derived(), 0, 0, rows(), N);
423}
424
425
426
436inline ColsBlockXpr rightCols(Index n)
437{
438 return ColsBlockXpr(derived(), 0, cols() - n, rows(), n);
439}
440
442inline ConstColsBlockXpr rightCols(Index n) const
443{
444 return ConstColsBlockXpr(derived(), 0, cols() - n, rows(), n);
445}
446
456template<int N>
457inline typename NColsBlockXpr<N>::Type rightCols()
458{
459 return typename NColsBlockXpr<N>::Type(derived(), 0, cols() - N, rows(), N);
460}
461
463template<int N>
464inline typename ConstNColsBlockXpr<N>::Type rightCols() const
465{
466 return typename ConstNColsBlockXpr<N>::Type(derived(), 0, cols() - N, rows(), N);
467}
468
469
470
481inline ColsBlockXpr middleCols(Index startCol, Index numCols)
482{
483 return ColsBlockXpr(derived(), 0, startCol, rows(), numCols);
484}
485
487inline ConstColsBlockXpr middleCols(Index startCol, Index numCols) const
488{
489 return ConstColsBlockXpr(derived(), 0, startCol, rows(), numCols);
490}
491
502template<int N>
503inline typename NColsBlockXpr<N>::Type middleCols(Index startCol)
504{
505 return typename NColsBlockXpr<N>::Type(derived(), 0, startCol, rows(), N);
506}
507
509template<int N>
510inline typename ConstNColsBlockXpr<N>::Type middleCols(Index startCol) const
511{
512 return typename ConstNColsBlockXpr<N>::Type(derived(), 0, startCol, rows(), N);
513}
514
515
516
533template<int BlockRows, int BlockCols>
534inline Block<Derived, BlockRows, BlockCols> block(Index startRow, Index startCol)
535{
536 return Block<Derived, BlockRows, BlockCols>(derived(), startRow, startCol);
537}
538
540template<int BlockRows, int BlockCols>
541inline const Block<const Derived, BlockRows, BlockCols> block(Index startRow, Index startCol) const
542{
543 return Block<const Derived, BlockRows, BlockCols>(derived(), startRow, startCol);
544}
545
552inline ColXpr col(Index i)
553{
554 return ColXpr(derived(), i);
555}
556
558inline ConstColXpr col(Index i) const
559{
560 return ConstColXpr(derived(), i);
561}
562
569inline RowXpr row(Index i)
570{
571 return RowXpr(derived(), i);
572}
573
575inline ConstRowXpr row(Index i) const
576{
577 return ConstRowXpr(derived(), i);
578}
579
580#endif // EIGEN_BLOCKMETHODS_H