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 
12 #ifndef EIGEN_PARSED_BY_DOXYGEN
13 
14 /** \internal expression type of a column */
15 typedef Block<Derived, internal::traits<Derived>::RowsAtCompileTime, 1, !IsRowMajor> ColXpr;
16 typedef const Block<const Derived, internal::traits<Derived>::RowsAtCompileTime, 1, !IsRowMajor> ConstColXpr;
17 /** \internal expression type of a row */
18 typedef Block<Derived, 1, internal::traits<Derived>::ColsAtCompileTime, IsRowMajor> RowXpr;
19 typedef const Block<const Derived, 1, internal::traits<Derived>::ColsAtCompileTime, IsRowMajor> ConstRowXpr;
20 /** \internal expression type of a block of whole columns */
21 typedef Block<Derived, internal::traits<Derived>::RowsAtCompileTime, Dynamic, !IsRowMajor> ColsBlockXpr;
22 typedef const Block<const Derived, internal::traits<Derived>::RowsAtCompileTime, Dynamic, !IsRowMajor> ConstColsBlockXpr;
23 /** \internal expression type of a block of whole rows */
24 typedef Block<Derived, Dynamic, internal::traits<Derived>::ColsAtCompileTime, IsRowMajor> RowsBlockXpr;
25 typedef const Block<const Derived, Dynamic, internal::traits<Derived>::ColsAtCompileTime, IsRowMajor> ConstRowsBlockXpr;
26 /** \internal expression type of a block of whole columns */
27 template<int N> struct NColsBlockXpr { typedef Block<Derived, internal::traits<Derived>::RowsAtCompileTime, N, !IsRowMajor> Type; };
28 template<int N> struct ConstNColsBlockXpr { typedef const Block<const Derived, internal::traits<Derived>::RowsAtCompileTime, N, !IsRowMajor> Type; };
29 /** \internal expression type of a block of whole rows */
30 template<int N> struct NRowsBlockXpr { typedef Block<Derived, N, internal::traits<Derived>::ColsAtCompileTime, IsRowMajor> Type; };
31 template<int N> struct ConstNRowsBlockXpr { typedef const Block<const Derived, N, internal::traits<Derived>::ColsAtCompileTime, IsRowMajor> Type; };
32 
33 typedef VectorBlock<Derived> SegmentReturnType;
34 typedef const VectorBlock<const Derived> ConstSegmentReturnType;
35 template<int Size> struct FixedSegmentReturnType { typedef VectorBlock<Derived, Size> Type; };
36 template<int Size> struct ConstFixedSegmentReturnType { typedef const VectorBlock<const Derived, Size> Type; };
37 
38 #endif // not EIGEN_PARSED_BY_DOXYGEN
39 
40 /** \returns a dynamic-size expression of a block in *this.
41   *
42   * \param startRow the first row in the block
43   * \param startCol the first column in the block
44   * \param blockRows the number of rows in the block
45   * \param blockCols the number of columns in the block
46   *
47   * Example: \include MatrixBase_block_int_int_int_int.cpp
48   * Output: \verbinclude MatrixBase_block_int_int_int_int.out
49   *
50   * \note Even though the returned expression has dynamic size, in the case
51   * when it is applied to a fixed-size matrix, it inherits a fixed maximal size,
52   * which means that evaluating it does not cause a dynamic memory allocation.
53   *
54   * \sa class Block, block(Index,Index)
55   */
block(Index startRow,Index startCol,Index blockRows,Index blockCols)56 inline Block<Derived> block(Index startRow, Index startCol, Index blockRows, Index blockCols)
57 {
58   return Block<Derived>(derived(), startRow, startCol, blockRows, blockCols);
59 }
60 
61 /** This is the const version of block(Index,Index,Index,Index). */
block(Index startRow,Index startCol,Index blockRows,Index blockCols)62 inline const Block<const Derived> block(Index startRow, Index startCol, Index blockRows, Index blockCols) const
63 {
64   return Block<const Derived>(derived(), startRow, startCol, blockRows, blockCols);
65 }
66 
67 
68 
69 
70 /** \returns a dynamic-size expression of a top-right corner of *this.
71   *
72   * \param cRows the number of rows in the corner
73   * \param cCols the number of columns in the corner
74   *
75   * Example: \include MatrixBase_topRightCorner_int_int.cpp
76   * Output: \verbinclude MatrixBase_topRightCorner_int_int.out
77   *
78   * \sa class Block, block(Index,Index,Index,Index)
79   */
topRightCorner(Index cRows,Index cCols)80 inline Block<Derived> topRightCorner(Index cRows, Index cCols)
81 {
82   return Block<Derived>(derived(), 0, cols() - cCols, cRows, cCols);
83 }
84 
85 /** This is the const version of topRightCorner(Index, Index).*/
topRightCorner(Index cRows,Index cCols)86 inline const Block<const Derived> topRightCorner(Index cRows, Index cCols) const
87 {
88   return Block<const Derived>(derived(), 0, cols() - cCols, cRows, cCols);
89 }
90 
91 /** \returns an expression of a fixed-size top-right corner of *this.
92   *
93   * \tparam CRows the number of rows in the corner
94   * \tparam CCols the number of columns in the corner
95   *
96   * Example: \include MatrixBase_template_int_int_topRightCorner.cpp
97   * Output: \verbinclude MatrixBase_template_int_int_topRightCorner.out
98   *
99   * \sa class Block, block<int,int>(Index,Index)
100   */
101 template<int CRows, int CCols>
topRightCorner()102 inline Block<Derived, CRows, CCols> topRightCorner()
103 {
104   return Block<Derived, CRows, CCols>(derived(), 0, cols() - CCols);
105 }
106 
107 /** This is the const version of topRightCorner<int, int>().*/
108 template<int CRows, int CCols>
topRightCorner()109 inline const Block<const Derived, CRows, CCols> topRightCorner() const
110 {
111   return Block<const Derived, CRows, CCols>(derived(), 0, cols() - CCols);
112 }
113 
114 /** \returns an expression of a top-right corner of *this.
115   *
116   * \tparam CRows number of rows in corner as specified at compile-time
117   * \tparam CCols number of columns in corner as specified at compile-time
118   * \param  cRows number of rows in corner as specified at run-time
119   * \param  cCols number of columns in corner as specified at run-time
120   *
121   * This function is mainly useful for corners where the number of rows is specified at compile-time
122   * and the number of columns is specified at run-time, or vice versa. The compile-time and run-time
123   * information should not contradict. In other words, \a cRows should equal \a CRows unless
124   * \a CRows is \a Dynamic, and the same for the number of columns.
125   *
126   * Example: \include MatrixBase_template_int_int_topRightCorner_int_int.cpp
127   * Output: \verbinclude MatrixBase_template_int_int_topRightCorner_int_int.out
128   *
129   * \sa class Block
130   */
131 template<int CRows, int CCols>
topRightCorner(Index cRows,Index cCols)132 inline Block<Derived, CRows, CCols> topRightCorner(Index cRows, Index cCols)
133 {
134   return Block<Derived, CRows, CCols>(derived(), 0, cols() - cCols, cRows, cCols);
135 }
136 
137 /** This is the const version of topRightCorner<int, int>(Index, Index).*/
138 template<int CRows, int CCols>
topRightCorner(Index cRows,Index cCols)139 inline const Block<const Derived, CRows, CCols> topRightCorner(Index cRows, Index cCols) const
140 {
141   return Block<const Derived, CRows, CCols>(derived(), 0, cols() - cCols, cRows, cCols);
142 }
143 
144 
145 
146 /** \returns a dynamic-size expression of a top-left corner of *this.
147   *
148   * \param cRows the number of rows in the corner
149   * \param cCols the number of columns in the corner
150   *
151   * Example: \include MatrixBase_topLeftCorner_int_int.cpp
152   * Output: \verbinclude MatrixBase_topLeftCorner_int_int.out
153   *
154   * \sa class Block, block(Index,Index,Index,Index)
155   */
topLeftCorner(Index cRows,Index cCols)156 inline Block<Derived> topLeftCorner(Index cRows, Index cCols)
157 {
158   return Block<Derived>(derived(), 0, 0, cRows, cCols);
159 }
160 
161 /** This is the const version of topLeftCorner(Index, Index).*/
topLeftCorner(Index cRows,Index cCols)162 inline const Block<const Derived> topLeftCorner(Index cRows, Index cCols) const
163 {
164   return Block<const Derived>(derived(), 0, 0, cRows, cCols);
165 }
166 
167 /** \returns an expression of a fixed-size top-left corner of *this.
168   *
169   * The template parameters CRows and CCols are the number of rows and columns in the corner.
170   *
171   * Example: \include MatrixBase_template_int_int_topLeftCorner.cpp
172   * Output: \verbinclude MatrixBase_template_int_int_topLeftCorner.out
173   *
174   * \sa class Block, block(Index,Index,Index,Index)
175   */
176 template<int CRows, int CCols>
topLeftCorner()177 inline Block<Derived, CRows, CCols> topLeftCorner()
178 {
179   return Block<Derived, CRows, CCols>(derived(), 0, 0);
180 }
181 
182 /** This is the const version of topLeftCorner<int, int>().*/
183 template<int CRows, int CCols>
topLeftCorner()184 inline const Block<const Derived, CRows, CCols> topLeftCorner() const
185 {
186   return Block<const Derived, CRows, CCols>(derived(), 0, 0);
187 }
188 
189 /** \returns an expression of a top-left corner of *this.
190   *
191   * \tparam CRows number of rows in corner as specified at compile-time
192   * \tparam CCols number of columns in corner as specified at compile-time
193   * \param  cRows number of rows in corner as specified at run-time
194   * \param  cCols number of columns in corner as specified at run-time
195   *
196   * This function is mainly useful for corners where the number of rows is specified at compile-time
197   * and the number of columns is specified at run-time, or vice versa. The compile-time and run-time
198   * information should not contradict. In other words, \a cRows should equal \a CRows unless
199   * \a CRows is \a Dynamic, and the same for the number of columns.
200   *
201   * Example: \include MatrixBase_template_int_int_topLeftCorner_int_int.cpp
202   * Output: \verbinclude MatrixBase_template_int_int_topLeftCorner_int_int.out
203   *
204   * \sa class Block
205   */
206 template<int CRows, int CCols>
topLeftCorner(Index cRows,Index cCols)207 inline Block<Derived, CRows, CCols> topLeftCorner(Index cRows, Index cCols)
208 {
209   return Block<Derived, CRows, CCols>(derived(), 0, 0, cRows, cCols);
210 }
211 
212 /** This is the const version of topLeftCorner<int, int>(Index, Index).*/
213 template<int CRows, int CCols>
topLeftCorner(Index cRows,Index cCols)214 inline const Block<const Derived, CRows, CCols> topLeftCorner(Index cRows, Index cCols) const
215 {
216   return Block<const Derived, CRows, CCols>(derived(), 0, 0, cRows, cCols);
217 }
218 
219 
220 
221 /** \returns a dynamic-size expression of a bottom-right corner of *this.
222   *
223   * \param cRows the number of rows in the corner
224   * \param cCols the number of columns in the corner
225   *
226   * Example: \include MatrixBase_bottomRightCorner_int_int.cpp
227   * Output: \verbinclude MatrixBase_bottomRightCorner_int_int.out
228   *
229   * \sa class Block, block(Index,Index,Index,Index)
230   */
bottomRightCorner(Index cRows,Index cCols)231 inline Block<Derived> bottomRightCorner(Index cRows, Index cCols)
232 {
233   return Block<Derived>(derived(), rows() - cRows, cols() - cCols, cRows, cCols);
234 }
235 
236 /** This is the const version of bottomRightCorner(Index, Index).*/
bottomRightCorner(Index cRows,Index cCols)237 inline const Block<const Derived> bottomRightCorner(Index cRows, Index cCols) const
238 {
239   return Block<const Derived>(derived(), rows() - cRows, cols() - cCols, cRows, cCols);
240 }
241 
242 /** \returns an expression of a fixed-size bottom-right corner of *this.
243   *
244   * The template parameters CRows and CCols are the number of rows and columns in the corner.
245   *
246   * Example: \include MatrixBase_template_int_int_bottomRightCorner.cpp
247   * Output: \verbinclude MatrixBase_template_int_int_bottomRightCorner.out
248   *
249   * \sa class Block, block(Index,Index,Index,Index)
250   */
251 template<int CRows, int CCols>
bottomRightCorner()252 inline Block<Derived, CRows, CCols> bottomRightCorner()
253 {
254   return Block<Derived, CRows, CCols>(derived(), rows() - CRows, cols() - CCols);
255 }
256 
257 /** This is the const version of bottomRightCorner<int, int>().*/
258 template<int CRows, int CCols>
bottomRightCorner()259 inline const Block<const Derived, CRows, CCols> bottomRightCorner() const
260 {
261   return Block<const Derived, CRows, CCols>(derived(), rows() - CRows, cols() - CCols);
262 }
263 
264 /** \returns an expression of a bottom-right corner of *this.
265   *
266   * \tparam CRows number of rows in corner as specified at compile-time
267   * \tparam CCols number of columns in corner as specified at compile-time
268   * \param  cRows number of rows in corner as specified at run-time
269   * \param  cCols number of columns in corner as specified at run-time
270   *
271   * This function is mainly useful for corners where the number of rows is specified at compile-time
272   * and the number of columns is specified at run-time, or vice versa. The compile-time and run-time
273   * information should not contradict. In other words, \a cRows should equal \a CRows unless
274   * \a CRows is \a Dynamic, and the same for the number of columns.
275   *
276   * Example: \include MatrixBase_template_int_int_bottomRightCorner_int_int.cpp
277   * Output: \verbinclude MatrixBase_template_int_int_bottomRightCorner_int_int.out
278   *
279   * \sa class Block
280   */
281 template<int CRows, int CCols>
bottomRightCorner(Index cRows,Index cCols)282 inline Block<Derived, CRows, CCols> bottomRightCorner(Index cRows, Index cCols)
283 {
284   return Block<Derived, CRows, CCols>(derived(), rows() - cRows, cols() - cCols, cRows, cCols);
285 }
286 
287 /** This is the const version of bottomRightCorner<int, int>(Index, Index).*/
288 template<int CRows, int CCols>
bottomRightCorner(Index cRows,Index cCols)289 inline const Block<const Derived, CRows, CCols> bottomRightCorner(Index cRows, Index cCols) const
290 {
291   return Block<const Derived, CRows, CCols>(derived(), rows() - cRows, cols() - cCols, cRows, cCols);
292 }
293 
294 
295 
296 /** \returns a dynamic-size expression of a bottom-left corner of *this.
297   *
298   * \param cRows the number of rows in the corner
299   * \param cCols the number of columns in the corner
300   *
301   * Example: \include MatrixBase_bottomLeftCorner_int_int.cpp
302   * Output: \verbinclude MatrixBase_bottomLeftCorner_int_int.out
303   *
304   * \sa class Block, block(Index,Index,Index,Index)
305   */
bottomLeftCorner(Index cRows,Index cCols)306 inline Block<Derived> bottomLeftCorner(Index cRows, Index cCols)
307 {
308   return Block<Derived>(derived(), rows() - cRows, 0, cRows, cCols);
309 }
310 
311 /** This is the const version of bottomLeftCorner(Index, Index).*/
bottomLeftCorner(Index cRows,Index cCols)312 inline const Block<const Derived> bottomLeftCorner(Index cRows, Index cCols) const
313 {
314   return Block<const Derived>(derived(), rows() - cRows, 0, cRows, cCols);
315 }
316 
317 /** \returns an expression of a fixed-size bottom-left corner of *this.
318   *
319   * The template parameters CRows and CCols are the number of rows and columns in the corner.
320   *
321   * Example: \include MatrixBase_template_int_int_bottomLeftCorner.cpp
322   * Output: \verbinclude MatrixBase_template_int_int_bottomLeftCorner.out
323   *
324   * \sa class Block, block(Index,Index,Index,Index)
325   */
326 template<int CRows, int CCols>
bottomLeftCorner()327 inline Block<Derived, CRows, CCols> bottomLeftCorner()
328 {
329   return Block<Derived, CRows, CCols>(derived(), rows() - CRows, 0);
330 }
331 
332 /** This is the const version of bottomLeftCorner<int, int>().*/
333 template<int CRows, int CCols>
bottomLeftCorner()334 inline const Block<const Derived, CRows, CCols> bottomLeftCorner() const
335 {
336   return Block<const Derived, CRows, CCols>(derived(), rows() - CRows, 0);
337 }
338 
339 /** \returns an expression of a bottom-left corner of *this.
340   *
341   * \tparam CRows number of rows in corner as specified at compile-time
342   * \tparam CCols number of columns in corner as specified at compile-time
343   * \param  cRows number of rows in corner as specified at run-time
344   * \param  cCols number of columns in corner as specified at run-time
345   *
346   * This function is mainly useful for corners where the number of rows is specified at compile-time
347   * and the number of columns is specified at run-time, or vice versa. The compile-time and run-time
348   * information should not contradict. In other words, \a cRows should equal \a CRows unless
349   * \a CRows is \a Dynamic, and the same for the number of columns.
350   *
351   * Example: \include MatrixBase_template_int_int_bottomLeftCorner_int_int.cpp
352   * Output: \verbinclude MatrixBase_template_int_int_bottomLeftCorner_int_int.out
353   *
354   * \sa class Block
355   */
356 template<int CRows, int CCols>
bottomLeftCorner(Index cRows,Index cCols)357 inline Block<Derived, CRows, CCols> bottomLeftCorner(Index cRows, Index cCols)
358 {
359   return Block<Derived, CRows, CCols>(derived(), rows() - cRows, 0, cRows, cCols);
360 }
361 
362 /** This is the const version of bottomLeftCorner<int, int>(Index, Index).*/
363 template<int CRows, int CCols>
bottomLeftCorner(Index cRows,Index cCols)364 inline const Block<const Derived, CRows, CCols> bottomLeftCorner(Index cRows, Index cCols) const
365 {
366   return Block<const Derived, CRows, CCols>(derived(), rows() - cRows, 0, cRows, cCols);
367 }
368 
369 
370 
371 /** \returns a block consisting of the top rows of *this.
372   *
373   * \param n the number of rows in the block
374   *
375   * Example: \include MatrixBase_topRows_int.cpp
376   * Output: \verbinclude MatrixBase_topRows_int.out
377   *
378   * \sa class Block, block(Index,Index,Index,Index)
379   */
topRows(Index n)380 inline RowsBlockXpr topRows(Index n)
381 {
382   return RowsBlockXpr(derived(), 0, 0, n, cols());
383 }
384 
385 /** This is the const version of topRows(Index).*/
topRows(Index n)386 inline ConstRowsBlockXpr topRows(Index n) const
387 {
388   return ConstRowsBlockXpr(derived(), 0, 0, n, cols());
389 }
390 
391 /** \returns a block consisting of the top rows of *this.
392   *
393   * \tparam N the number of rows in the block as specified at compile-time
394   * \param n the number of rows in the block as specified at run-time
395   *
396   * The compile-time and run-time information should not contradict. In other words,
397   * \a n should equal \a N unless \a N is \a Dynamic.
398   *
399   * Example: \include MatrixBase_template_int_topRows.cpp
400   * Output: \verbinclude MatrixBase_template_int_topRows.out
401   *
402   * \sa class Block, block(Index,Index,Index,Index)
403   */
404 template<int N>
405 inline typename NRowsBlockXpr<N>::Type topRows(Index n = N)
406 {
407   return typename NRowsBlockXpr<N>::Type(derived(), 0, 0, n, cols());
408 }
409 
410 /** This is the const version of topRows<int>().*/
411 template<int N>
412 inline typename ConstNRowsBlockXpr<N>::Type topRows(Index n = N) const
413 {
414   return typename ConstNRowsBlockXpr<N>::Type(derived(), 0, 0, n, cols());
415 }
416 
417 
418 
419 /** \returns a block consisting of the bottom rows of *this.
420   *
421   * \param n the number of rows in the block
422   *
423   * Example: \include MatrixBase_bottomRows_int.cpp
424   * Output: \verbinclude MatrixBase_bottomRows_int.out
425   *
426   * \sa class Block, block(Index,Index,Index,Index)
427   */
bottomRows(Index n)428 inline RowsBlockXpr bottomRows(Index n)
429 {
430   return RowsBlockXpr(derived(), rows() - n, 0, n, cols());
431 }
432 
433 /** This is the const version of bottomRows(Index).*/
bottomRows(Index n)434 inline ConstRowsBlockXpr bottomRows(Index n) const
435 {
436   return ConstRowsBlockXpr(derived(), rows() - n, 0, n, cols());
437 }
438 
439 /** \returns a block consisting of the bottom rows of *this.
440   *
441   * \tparam N the number of rows in the block as specified at compile-time
442   * \param n the number of rows in the block as specified at run-time
443   *
444   * The compile-time and run-time information should not contradict. In other words,
445   * \a n should equal \a N unless \a N is \a Dynamic.
446   *
447   * Example: \include MatrixBase_template_int_bottomRows.cpp
448   * Output: \verbinclude MatrixBase_template_int_bottomRows.out
449   *
450   * \sa class Block, block(Index,Index,Index,Index)
451   */
452 template<int N>
453 inline typename NRowsBlockXpr<N>::Type bottomRows(Index n = N)
454 {
455   return typename NRowsBlockXpr<N>::Type(derived(), rows() - n, 0, n, cols());
456 }
457 
458 /** This is the const version of bottomRows<int>().*/
459 template<int N>
460 inline typename ConstNRowsBlockXpr<N>::Type bottomRows(Index n = N) const
461 {
462   return typename ConstNRowsBlockXpr<N>::Type(derived(), rows() - n, 0, n, cols());
463 }
464 
465 
466 
467 /** \returns a block consisting of a range of rows of *this.
468   *
469   * \param startRow the index of the first row in the block
470   * \param n the number of rows in the block
471   *
472   * Example: \include DenseBase_middleRows_int.cpp
473   * Output: \verbinclude DenseBase_middleRows_int.out
474   *
475   * \sa class Block, block(Index,Index,Index,Index)
476   */
middleRows(Index startRow,Index n)477 inline RowsBlockXpr middleRows(Index startRow, Index n)
478 {
479   return RowsBlockXpr(derived(), startRow, 0, n, cols());
480 }
481 
482 /** This is the const version of middleRows(Index,Index).*/
middleRows(Index startRow,Index n)483 inline ConstRowsBlockXpr middleRows(Index startRow, Index n) const
484 {
485   return ConstRowsBlockXpr(derived(), startRow, 0, n, cols());
486 }
487 
488 /** \returns a block consisting of a range of rows of *this.
489   *
490   * \tparam N the number of rows in the block as specified at compile-time
491   * \param startRow the index of the first row in the block
492   * \param n the number of rows in the block as specified at run-time
493   *
494   * The compile-time and run-time information should not contradict. In other words,
495   * \a n should equal \a N unless \a N is \a Dynamic.
496   *
497   * Example: \include DenseBase_template_int_middleRows.cpp
498   * Output: \verbinclude DenseBase_template_int_middleRows.out
499   *
500   * \sa class Block, block(Index,Index,Index,Index)
501   */
502 template<int N>
503 inline typename NRowsBlockXpr<N>::Type middleRows(Index startRow, Index n = N)
504 {
505   return typename NRowsBlockXpr<N>::Type(derived(), startRow, 0, n, cols());
506 }
507 
508 /** This is the const version of middleRows<int>().*/
509 template<int N>
510 inline typename ConstNRowsBlockXpr<N>::Type middleRows(Index startRow, Index n = N) const
511 {
512   return typename ConstNRowsBlockXpr<N>::Type(derived(), startRow, 0, n, cols());
513 }
514 
515 
516 
517 /** \returns a block consisting of the left columns of *this.
518   *
519   * \param n the number of columns in the block
520   *
521   * Example: \include MatrixBase_leftCols_int.cpp
522   * Output: \verbinclude MatrixBase_leftCols_int.out
523   *
524   * \sa class Block, block(Index,Index,Index,Index)
525   */
leftCols(Index n)526 inline ColsBlockXpr leftCols(Index n)
527 {
528   return ColsBlockXpr(derived(), 0, 0, rows(), n);
529 }
530 
531 /** This is the const version of leftCols(Index).*/
leftCols(Index n)532 inline ConstColsBlockXpr leftCols(Index n) const
533 {
534   return ConstColsBlockXpr(derived(), 0, 0, rows(), n);
535 }
536 
537 /** \returns a block consisting of the left columns of *this.
538   *
539   * \tparam N the number of columns in the block as specified at compile-time
540   * \param n the number of columns in the block as specified at run-time
541   *
542   * The compile-time and run-time information should not contradict. In other words,
543   * \a n should equal \a N unless \a N is \a Dynamic.
544   *
545   * Example: \include MatrixBase_template_int_leftCols.cpp
546   * Output: \verbinclude MatrixBase_template_int_leftCols.out
547   *
548   * \sa class Block, block(Index,Index,Index,Index)
549   */
550 template<int N>
551 inline typename NColsBlockXpr<N>::Type leftCols(Index n = N)
552 {
553   return typename NColsBlockXpr<N>::Type(derived(), 0, 0, rows(), n);
554 }
555 
556 /** This is the const version of leftCols<int>().*/
557 template<int N>
558 inline typename ConstNColsBlockXpr<N>::Type leftCols(Index n = N) const
559 {
560   return typename ConstNColsBlockXpr<N>::Type(derived(), 0, 0, rows(), n);
561 }
562 
563 
564 
565 /** \returns a block consisting of the right columns of *this.
566   *
567   * \param n the number of columns in the block
568   *
569   * Example: \include MatrixBase_rightCols_int.cpp
570   * Output: \verbinclude MatrixBase_rightCols_int.out
571   *
572   * \sa class Block, block(Index,Index,Index,Index)
573   */
rightCols(Index n)574 inline ColsBlockXpr rightCols(Index n)
575 {
576   return ColsBlockXpr(derived(), 0, cols() - n, rows(), n);
577 }
578 
579 /** This is the const version of rightCols(Index).*/
rightCols(Index n)580 inline ConstColsBlockXpr rightCols(Index n) const
581 {
582   return ConstColsBlockXpr(derived(), 0, cols() - n, rows(), n);
583 }
584 
585 /** \returns a block consisting of the right columns of *this.
586   *
587   * \tparam N the number of columns in the block as specified at compile-time
588   * \param n the number of columns in the block as specified at run-time
589   *
590   * The compile-time and run-time information should not contradict. In other words,
591   * \a n should equal \a N unless \a N is \a Dynamic.
592   *
593   * Example: \include MatrixBase_template_int_rightCols.cpp
594   * Output: \verbinclude MatrixBase_template_int_rightCols.out
595   *
596   * \sa class Block, block(Index,Index,Index,Index)
597   */
598 template<int N>
599 inline typename NColsBlockXpr<N>::Type rightCols(Index n = N)
600 {
601   return typename NColsBlockXpr<N>::Type(derived(), 0, cols() - n, rows(), n);
602 }
603 
604 /** This is the const version of rightCols<int>().*/
605 template<int N>
606 inline typename ConstNColsBlockXpr<N>::Type rightCols(Index n = N) const
607 {
608   return typename ConstNColsBlockXpr<N>::Type(derived(), 0, cols() - n, rows(), n);
609 }
610 
611 
612 
613 /** \returns a block consisting of a range of columns of *this.
614   *
615   * \param startCol the index of the first column in the block
616   * \param numCols the number of columns in the block
617   *
618   * Example: \include DenseBase_middleCols_int.cpp
619   * Output: \verbinclude DenseBase_middleCols_int.out
620   *
621   * \sa class Block, block(Index,Index,Index,Index)
622   */
middleCols(Index startCol,Index numCols)623 inline ColsBlockXpr middleCols(Index startCol, Index numCols)
624 {
625   return ColsBlockXpr(derived(), 0, startCol, rows(), numCols);
626 }
627 
628 /** This is the const version of middleCols(Index,Index).*/
middleCols(Index startCol,Index numCols)629 inline ConstColsBlockXpr middleCols(Index startCol, Index numCols) const
630 {
631   return ConstColsBlockXpr(derived(), 0, startCol, rows(), numCols);
632 }
633 
634 /** \returns a block consisting of a range of columns of *this.
635   *
636   * \tparam N the number of columns in the block as specified at compile-time
637   * \param startCol the index of the first column in the block
638   * \param n the number of columns in the block as specified at run-time
639   *
640   * The compile-time and run-time information should not contradict. In other words,
641   * \a n should equal \a N unless \a N is \a Dynamic.
642   *
643   * Example: \include DenseBase_template_int_middleCols.cpp
644   * Output: \verbinclude DenseBase_template_int_middleCols.out
645   *
646   * \sa class Block, block(Index,Index,Index,Index)
647   */
648 template<int N>
649 inline typename NColsBlockXpr<N>::Type middleCols(Index startCol, Index n = N)
650 {
651   return typename NColsBlockXpr<N>::Type(derived(), 0, startCol, rows(), n);
652 }
653 
654 /** This is the const version of middleCols<int>().*/
655 template<int N>
656 inline typename ConstNColsBlockXpr<N>::Type middleCols(Index startCol, Index n = N) const
657 {
658   return typename ConstNColsBlockXpr<N>::Type(derived(), 0, startCol, rows(), n);
659 }
660 
661 
662 
663 /** \returns a fixed-size expression of a block in *this.
664   *
665   * The template parameters \a BlockRows and \a BlockCols are the number of
666   * rows and columns in the block.
667   *
668   * \param startRow the first row in the block
669   * \param startCol the first column in the block
670   *
671   * Example: \include MatrixBase_block_int_int.cpp
672   * Output: \verbinclude MatrixBase_block_int_int.out
673   *
674   * \note since block is a templated member, the keyword template has to be used
675   * if the matrix type is also a template parameter: \code m.template block<3,3>(1,1); \endcode
676   *
677   * \sa class Block, block(Index,Index,Index,Index)
678   */
679 template<int BlockRows, int BlockCols>
block(Index startRow,Index startCol)680 inline Block<Derived, BlockRows, BlockCols> block(Index startRow, Index startCol)
681 {
682   return Block<Derived, BlockRows, BlockCols>(derived(), startRow, startCol);
683 }
684 
685 /** This is the const version of block<>(Index, Index). */
686 template<int BlockRows, int BlockCols>
block(Index startRow,Index startCol)687 inline const Block<const Derived, BlockRows, BlockCols> block(Index startRow, Index startCol) const
688 {
689   return Block<const Derived, BlockRows, BlockCols>(derived(), startRow, startCol);
690 }
691 
692 /** \returns an expression of a block in *this.
693   *
694   * \tparam BlockRows number of rows in block as specified at compile-time
695   * \tparam BlockCols number of columns in block as specified at compile-time
696   * \param  startRow  the first row in the block
697   * \param  startCol  the first column in the block
698   * \param  blockRows number of rows in block as specified at run-time
699   * \param  blockCols number of columns in block as specified at run-time
700   *
701   * This function is mainly useful for blocks where the number of rows is specified at compile-time
702   * and the number of columns is specified at run-time, or vice versa. The compile-time and run-time
703   * information should not contradict. In other words, \a blockRows should equal \a BlockRows unless
704   * \a BlockRows is \a Dynamic, and the same for the number of columns.
705   *
706   * Example: \include MatrixBase_template_int_int_block_int_int_int_int.cpp
707   * Output: \verbinclude MatrixBase_template_int_int_block_int_int_int_int.cpp
708   *
709   * \sa class Block, block(Index,Index,Index,Index)
710   */
711 template<int BlockRows, int BlockCols>
block(Index startRow,Index startCol,Index blockRows,Index blockCols)712 inline Block<Derived, BlockRows, BlockCols> block(Index startRow, Index startCol,
713                                                   Index blockRows, Index blockCols)
714 {
715   return Block<Derived, BlockRows, BlockCols>(derived(), startRow, startCol, blockRows, blockCols);
716 }
717 
718 /** This is the const version of block<>(Index, Index, Index, Index). */
719 template<int BlockRows, int BlockCols>
block(Index startRow,Index startCol,Index blockRows,Index blockCols)720 inline const Block<const Derived, BlockRows, BlockCols> block(Index startRow, Index startCol,
721                                                               Index blockRows, Index blockCols) const
722 {
723   return Block<const Derived, BlockRows, BlockCols>(derived(), startRow, startCol, blockRows, blockCols);
724 }
725 
726 /** \returns an expression of the \a i-th column of *this. Note that the numbering starts at 0.
727   *
728   * Example: \include MatrixBase_col.cpp
729   * Output: \verbinclude MatrixBase_col.out
730   *
731   * \sa row(), class Block */
col(Index i)732 inline ColXpr col(Index i)
733 {
734   return ColXpr(derived(), i);
735 }
736 
737 /** This is the const version of col(). */
col(Index i)738 inline ConstColXpr col(Index i) const
739 {
740   return ConstColXpr(derived(), i);
741 }
742 
743 /** \returns an expression of the \a i-th row of *this. Note that the numbering starts at 0.
744   *
745   * Example: \include MatrixBase_row.cpp
746   * Output: \verbinclude MatrixBase_row.out
747   *
748   * \sa col(), class Block */
row(Index i)749 inline RowXpr row(Index i)
750 {
751   return RowXpr(derived(), i);
752 }
753 
754 /** This is the const version of row(). */
row(Index i)755 inline ConstRowXpr row(Index i) const
756 {
757   return ConstRowXpr(derived(), i);
758 }
759 
760 /** \returns a dynamic-size expression of a segment (i.e. a vector block) in *this.
761   *
762   * \only_for_vectors
763   *
764   * \param start the first coefficient in the segment
765   * \param n the number of coefficients in the segment
766   *
767   * Example: \include MatrixBase_segment_int_int.cpp
768   * Output: \verbinclude MatrixBase_segment_int_int.out
769   *
770   * \note Even though the returned expression has dynamic size, in the case
771   * when it is applied to a fixed-size vector, it inherits a fixed maximal size,
772   * which means that evaluating it does not cause a dynamic memory allocation.
773   *
774   * \sa class Block, segment(Index)
775   */
segment(Index start,Index n)776 inline SegmentReturnType segment(Index start, Index n)
777 {
778   EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
779   return SegmentReturnType(derived(), start, n);
780 }
781 
782 
783 /** This is the const version of segment(Index,Index).*/
segment(Index start,Index n)784 inline ConstSegmentReturnType segment(Index start, Index n) const
785 {
786   EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
787   return ConstSegmentReturnType(derived(), start, n);
788 }
789 
790 /** \returns a dynamic-size expression of the first coefficients of *this.
791   *
792   * \only_for_vectors
793   *
794   * \param n the number of coefficients in the segment
795   *
796   * Example: \include MatrixBase_start_int.cpp
797   * Output: \verbinclude MatrixBase_start_int.out
798   *
799   * \note Even though the returned expression has dynamic size, in the case
800   * when it is applied to a fixed-size vector, it inherits a fixed maximal size,
801   * which means that evaluating it does not cause a dynamic memory allocation.
802   *
803   * \sa class Block, block(Index,Index)
804   */
head(Index n)805 inline SegmentReturnType head(Index n)
806 {
807   EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
808   return SegmentReturnType(derived(), 0, n);
809 }
810 
811 /** This is the const version of head(Index).*/
head(Index n)812 inline ConstSegmentReturnType head(Index n) const
813 {
814   EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
815   return ConstSegmentReturnType(derived(), 0, n);
816 }
817 
818 /** \returns a dynamic-size expression of the last coefficients of *this.
819   *
820   * \only_for_vectors
821   *
822   * \param n the number of coefficients in the segment
823   *
824   * Example: \include MatrixBase_end_int.cpp
825   * Output: \verbinclude MatrixBase_end_int.out
826   *
827   * \note Even though the returned expression has dynamic size, in the case
828   * when it is applied to a fixed-size vector, it inherits a fixed maximal size,
829   * which means that evaluating it does not cause a dynamic memory allocation.
830   *
831   * \sa class Block, block(Index,Index)
832   */
tail(Index n)833 inline SegmentReturnType tail(Index n)
834 {
835   EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
836   return SegmentReturnType(derived(), this->size() - n, n);
837 }
838 
839 /** This is the const version of tail(Index).*/
tail(Index n)840 inline ConstSegmentReturnType tail(Index n) const
841 {
842   EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
843   return ConstSegmentReturnType(derived(), this->size() - n, n);
844 }
845 
846 /** \returns a fixed-size expression of a segment (i.e. a vector block) in \c *this
847   *
848   * \only_for_vectors
849   *
850   * \tparam N the number of coefficients in the segment as specified at compile-time
851   * \param start the index of the first element in the segment
852   * \param n the number of coefficients in the segment as specified at compile-time
853   *
854   * The compile-time and run-time information should not contradict. In other words,
855   * \a n should equal \a N unless \a N is \a Dynamic.
856   *
857   * Example: \include MatrixBase_template_int_segment.cpp
858   * Output: \verbinclude MatrixBase_template_int_segment.out
859   *
860   * \sa class Block
861   */
862 template<int N>
863 inline typename FixedSegmentReturnType<N>::Type segment(Index start, Index n = N)
864 {
865   EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
866   return typename FixedSegmentReturnType<N>::Type(derived(), start, n);
867 }
868 
869 /** This is the const version of segment<int>(Index).*/
870 template<int N>
871 inline typename ConstFixedSegmentReturnType<N>::Type segment(Index start, Index n = N) const
872 {
873   EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
874   return typename ConstFixedSegmentReturnType<N>::Type(derived(), start, n);
875 }
876 
877 /** \returns a fixed-size expression of the first coefficients of *this.
878   *
879   * \only_for_vectors
880   *
881   * \tparam N the number of coefficients in the segment as specified at compile-time
882   * \param  n the number of coefficients in the segment as specified at run-time
883   *
884   * The compile-time and run-time information should not contradict. In other words,
885   * \a n should equal \a N unless \a N is \a Dynamic.
886   *
887   * Example: \include MatrixBase_template_int_start.cpp
888   * Output: \verbinclude MatrixBase_template_int_start.out
889   *
890   * \sa class Block
891   */
892 template<int N>
893 inline typename FixedSegmentReturnType<N>::Type head(Index n = N)
894 {
895   EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
896   return typename FixedSegmentReturnType<N>::Type(derived(), 0, n);
897 }
898 
899 /** This is the const version of head<int>().*/
900 template<int N>
901 inline typename ConstFixedSegmentReturnType<N>::Type head(Index n = N) const
902 {
903   EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
904   return typename ConstFixedSegmentReturnType<N>::Type(derived(), 0, n);
905 }
906 
907 /** \returns a fixed-size expression of the last coefficients of *this.
908   *
909   * \only_for_vectors
910   *
911   * \tparam N the number of coefficients in the segment as specified at compile-time
912   * \param  n the number of coefficients in the segment as specified at run-time
913   *
914   * The compile-time and run-time information should not contradict. In other words,
915   * \a n should equal \a N unless \a N is \a Dynamic.
916   *
917   * Example: \include MatrixBase_template_int_end.cpp
918   * Output: \verbinclude MatrixBase_template_int_end.out
919   *
920   * \sa class Block
921   */
922 template<int N>
923 inline typename FixedSegmentReturnType<N>::Type tail(Index n = N)
924 {
925   EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
926   return typename FixedSegmentReturnType<N>::Type(derived(), size() - n);
927 }
928 
929 /** This is the const version of tail<int>.*/
930 template<int N>
931 inline typename ConstFixedSegmentReturnType<N>::Type tail(Index n = N) const
932 {
933   EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
934   return typename ConstFixedSegmentReturnType<N>::Type(derived(), size() - n);
935 }
936