BlockMethods.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) 2008-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
5 // Copyright (C) 2006-2010 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_BLOCKMETHODS_H
27 #define EIGEN_BLOCKMETHODS_H
28 
29 #ifndef EIGEN_PARSED_BY_DOXYGEN
30 
32 typedef Block<Derived, internal::traits<Derived>::RowsAtCompileTime, 1, !IsRowMajor> ColXpr;
33 typedef const Block<const Derived, internal::traits<Derived>::RowsAtCompileTime, 1, !IsRowMajor> ConstColXpr;
35 typedef Block<Derived, 1, internal::traits<Derived>::ColsAtCompileTime, IsRowMajor> RowXpr;
36 typedef const Block<const Derived, 1, internal::traits<Derived>::ColsAtCompileTime, IsRowMajor> ConstRowXpr;
38 typedef Block<Derived, internal::traits<Derived>::RowsAtCompileTime, Dynamic, !IsRowMajor> ColsBlockXpr;
39 typedef const Block<const Derived, internal::traits<Derived>::RowsAtCompileTime, Dynamic, !IsRowMajor> ConstColsBlockXpr;
41 typedef Block<Derived, Dynamic, internal::traits<Derived>::ColsAtCompileTime, IsRowMajor> RowsBlockXpr;
42 typedef const Block<const Derived, Dynamic, internal::traits<Derived>::ColsAtCompileTime, IsRowMajor> ConstRowsBlockXpr;
44 template<int N> struct NColsBlockXpr { typedef Block<Derived, internal::traits<Derived>::RowsAtCompileTime, N, !IsRowMajor> Type; };
45 template<int N> struct ConstNColsBlockXpr { typedef const Block<const Derived, internal::traits<Derived>::RowsAtCompileTime, N, !IsRowMajor> Type; };
47 template<int N> struct NRowsBlockXpr { typedef Block<Derived, N, internal::traits<Derived>::ColsAtCompileTime, IsRowMajor> Type; };
48 template<int N> struct ConstNRowsBlockXpr { typedef const Block<const Derived, N, internal::traits<Derived>::ColsAtCompileTime, IsRowMajor> Type; };
49 
50 
51 #endif // not EIGEN_PARSED_BY_DOXYGEN
52 
69 inline Block<Derived> block(Index startRow, Index startCol, Index blockRows, Index blockCols)
70 {
71  return Block<Derived>(derived(), startRow, startCol, blockRows, blockCols);
72 }
73 
75 inline const Block<const Derived> block(Index startRow, Index startCol, Index blockRows, Index blockCols) const
76 {
77  return Block<const Derived>(derived(), startRow, startCol, blockRows, blockCols);
78 }
79 
80 
81 
82 
93 inline Block<Derived> topRightCorner(Index cRows, Index cCols)
94 {
95  return Block<Derived>(derived(), 0, cols() - cCols, cRows, cCols);
96 }
97 
99 inline const Block<const Derived> topRightCorner(Index cRows, Index cCols) const
100 {
101  return Block<const Derived>(derived(), 0, cols() - cCols, cRows, cCols);
102 }
103 
113 template<int CRows, int CCols>
114 inline Block<Derived, CRows, CCols> topRightCorner()
115 {
116  return Block<Derived, CRows, CCols>(derived(), 0, cols() - CCols);
117 }
118 
120 template<int CRows, int CCols>
121 inline const Block<const Derived, CRows, CCols> topRightCorner() const
122 {
123  return Block<const Derived, CRows, CCols>(derived(), 0, cols() - CCols);
124 }
125 
126 
127 
128 
139 inline Block<Derived> topLeftCorner(Index cRows, Index cCols)
140 {
141  return Block<Derived>(derived(), 0, 0, cRows, cCols);
142 }
143 
145 inline const Block<const Derived> topLeftCorner(Index cRows, Index cCols) const
146 {
147  return Block<const Derived>(derived(), 0, 0, cRows, cCols);
148 }
149 
159 template<int CRows, int CCols>
160 inline Block<Derived, CRows, CCols> topLeftCorner()
161 {
162  return Block<Derived, CRows, CCols>(derived(), 0, 0);
163 }
164 
166 template<int CRows, int CCols>
167 inline const Block<const Derived, CRows, CCols> topLeftCorner() const
168 {
169  return Block<const Derived, CRows, CCols>(derived(), 0, 0);
170 }
171 
172 
173 
184 inline Block<Derived> bottomRightCorner(Index cRows, Index cCols)
185 {
186  return Block<Derived>(derived(), rows() - cRows, cols() - cCols, cRows, cCols);
187 }
188 
190 inline const Block<const Derived> bottomRightCorner(Index cRows, Index cCols) const
191 {
192  return Block<const Derived>(derived(), rows() - cRows, cols() - cCols, cRows, cCols);
193 }
194 
204 template<int CRows, int CCols>
205 inline Block<Derived, CRows, CCols> bottomRightCorner()
206 {
207  return Block<Derived, CRows, CCols>(derived(), rows() - CRows, cols() - CCols);
208 }
209 
211 template<int CRows, int CCols>
212 inline const Block<const Derived, CRows, CCols> bottomRightCorner() const
213 {
214  return Block<const Derived, CRows, CCols>(derived(), rows() - CRows, cols() - CCols);
215 }
216 
217 
218 
229 inline Block<Derived> bottomLeftCorner(Index cRows, Index cCols)
230 {
231  return Block<Derived>(derived(), rows() - cRows, 0, cRows, cCols);
232 }
233 
235 inline const Block<const Derived> bottomLeftCorner(Index cRows, Index cCols) const
236 {
237  return Block<const Derived>(derived(), rows() - cRows, 0, cRows, cCols);
238 }
239 
249 template<int CRows, int CCols>
250 inline Block<Derived, CRows, CCols> bottomLeftCorner()
251 {
252  return Block<Derived, CRows, CCols>(derived(), rows() - CRows, 0);
253 }
254 
256 template<int CRows, int CCols>
257 inline const Block<const Derived, CRows, CCols> bottomLeftCorner() const
258 {
259  return Block<const Derived, CRows, CCols>(derived(), rows() - CRows, 0);
260 }
261 
262 
263 
273 inline RowsBlockXpr topRows(Index n)
274 {
275  return RowsBlockXpr(derived(), 0, 0, n, cols());
276 }
277 
279 inline ConstRowsBlockXpr topRows(Index n) const
280 {
281  return ConstRowsBlockXpr(derived(), 0, 0, n, cols());
282 }
283 
293 template<int N>
295 {
296  return typename NRowsBlockXpr<N>::Type(derived(), 0, 0, N, cols());
297 }
298 
300 template<int N>
301 inline typename ConstNRowsBlockXpr<N>::Type topRows() const
302 {
303  return typename ConstNRowsBlockXpr<N>::Type(derived(), 0, 0, N, cols());
304 }
305 
306 
307 
317 inline RowsBlockXpr bottomRows(Index n)
318 {
319  return RowsBlockXpr(derived(), rows() - n, 0, n, cols());
320 }
321 
323 inline ConstRowsBlockXpr bottomRows(Index n) const
324 {
325  return ConstRowsBlockXpr(derived(), rows() - n, 0, n, cols());
326 }
327 
337 template<int N>
339 {
340  return typename NRowsBlockXpr<N>::Type(derived(), rows() - N, 0, N, cols());
341 }
342 
344 template<int N>
345 inline typename ConstNRowsBlockXpr<N>::Type bottomRows() const
346 {
347  return typename ConstNRowsBlockXpr<N>::Type(derived(), rows() - N, 0, N, cols());
348 }
349 
350 
351 
362 inline RowsBlockXpr middleRows(Index startRow, Index numRows)
363 {
364  return RowsBlockXpr(derived(), startRow, 0, numRows, cols());
365 }
366 
368 inline ConstRowsBlockXpr middleRows(Index startRow, Index numRows) const
369 {
370  return ConstRowsBlockXpr(derived(), startRow, 0, numRows, cols());
371 }
372 
383 template<int N>
384 inline typename NRowsBlockXpr<N>::Type middleRows(Index startRow)
385 {
386  return typename NRowsBlockXpr<N>::Type(derived(), startRow, 0, N, cols());
387 }
388 
390 template<int N>
391 inline typename ConstNRowsBlockXpr<N>::Type middleRows(Index startRow) const
392 {
393  return typename ConstNRowsBlockXpr<N>::Type(derived(), startRow, 0, N, cols());
394 }
395 
396 
397 
407 inline ColsBlockXpr leftCols(Index n)
408 {
409  return ColsBlockXpr(derived(), 0, 0, rows(), n);
410 }
411 
413 inline ConstColsBlockXpr leftCols(Index n) const
414 {
415  return ConstColsBlockXpr(derived(), 0, 0, rows(), n);
416 }
417 
427 template<int N>
429 {
430  return typename NColsBlockXpr<N>::Type(derived(), 0, 0, rows(), N);
431 }
432 
434 template<int N>
435 inline typename ConstNColsBlockXpr<N>::Type leftCols() const
436 {
437  return typename ConstNColsBlockXpr<N>::Type(derived(), 0, 0, rows(), N);
438 }
439 
440 
441 
451 inline ColsBlockXpr rightCols(Index n)
452 {
453  return ColsBlockXpr(derived(), 0, cols() - n, rows(), n);
454 }
455 
457 inline ConstColsBlockXpr rightCols(Index n) const
458 {
459  return ConstColsBlockXpr(derived(), 0, cols() - n, rows(), n);
460 }
461 
471 template<int N>
473 {
474  return typename NColsBlockXpr<N>::Type(derived(), 0, cols() - N, rows(), N);
475 }
476 
478 template<int N>
479 inline typename ConstNColsBlockXpr<N>::Type rightCols() const
480 {
481  return typename ConstNColsBlockXpr<N>::Type(derived(), 0, cols() - N, rows(), N);
482 }
483 
484 
485 
496 inline ColsBlockXpr middleCols(Index startCol, Index numCols)
497 {
498  return ColsBlockXpr(derived(), 0, startCol, rows(), numCols);
499 }
500 
502 inline ConstColsBlockXpr middleCols(Index startCol, Index numCols) const
503 {
504  return ConstColsBlockXpr(derived(), 0, startCol, rows(), numCols);
505 }
506 
517 template<int N>
518 inline typename NColsBlockXpr<N>::Type middleCols(Index startCol)
519 {
520  return typename NColsBlockXpr<N>::Type(derived(), 0, startCol, rows(), N);
521 }
522 
524 template<int N>
525 inline typename ConstNColsBlockXpr<N>::Type middleCols(Index startCol) const
526 {
527  return typename ConstNColsBlockXpr<N>::Type(derived(), 0, startCol, rows(), N);
528 }
529 
530 
531 
548 template<int BlockRows, int BlockCols>
549 inline Block<Derived, BlockRows, BlockCols> block(Index startRow, Index startCol)
550 {
551  return Block<Derived, BlockRows, BlockCols>(derived(), startRow, startCol);
552 }
553 
555 template<int BlockRows, int BlockCols>
556 inline const Block<const Derived, BlockRows, BlockCols> block(Index startRow, Index startCol) const
557 {
558  return Block<const Derived, BlockRows, BlockCols>(derived(), startRow, startCol);
559 }
560 
567 inline ColXpr col(Index i)
568 {
569  return ColXpr(derived(), i);
570 }
571 
573 inline ConstColXpr col(Index i) const
574 {
575  return ConstColXpr(derived(), i);
576 }
577 
584 inline RowXpr row(Index i)
585 {
586  return RowXpr(derived(), i);
587 }
588 
590 inline ConstRowXpr row(Index i) const
591 {
592  return ConstRowXpr(derived(), i);
593 }
594 
595 #endif // EIGEN_BLOCKMETHODS_H