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