Eigen  3.2.92
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 
12 #ifndef EIGEN_PARSED_BY_DOXYGEN
13 
15 typedef Block<Derived, internal::traits<Derived>::RowsAtCompileTime, 1, !IsRowMajor> ColXpr;
16 typedef const Block<const Derived, internal::traits<Derived>::RowsAtCompileTime, 1, !IsRowMajor> ConstColXpr;
18 typedef Block<Derived, 1, internal::traits<Derived>::ColsAtCompileTime, IsRowMajor> RowXpr;
19 typedef const Block<const Derived, 1, internal::traits<Derived>::ColsAtCompileTime, IsRowMajor> ConstRowXpr;
21 typedef Block<Derived, internal::traits<Derived>::RowsAtCompileTime, Dynamic, !IsRowMajor> ColsBlockXpr;
22 typedef const Block<const Derived, internal::traits<Derived>::RowsAtCompileTime, Dynamic, !IsRowMajor> ConstColsBlockXpr;
24 typedef Block<Derived, Dynamic, internal::traits<Derived>::ColsAtCompileTime, IsRowMajor> RowsBlockXpr;
25 typedef const Block<const Derived, Dynamic, internal::traits<Derived>::ColsAtCompileTime, IsRowMajor> ConstRowsBlockXpr;
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; };
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 
56 EIGEN_DEVICE_FUNC
57 inline Block<Derived> block(Index startRow, Index startCol, Index blockRows, Index blockCols)
58 {
59  return Block<Derived>(derived(), startRow, startCol, blockRows, blockCols);
60 }
61 
63 EIGEN_DEVICE_FUNC
64 inline const Block<const Derived> block(Index startRow, Index startCol, Index blockRows, Index blockCols) const
65 {
66  return Block<const Derived>(derived(), startRow, startCol, blockRows, blockCols);
67 }
68 
69 
70 
71 
82 EIGEN_DEVICE_FUNC
83 inline Block<Derived> topRightCorner(Index cRows, Index cCols)
84 {
85  return Block<Derived>(derived(), 0, cols() - cCols, cRows, cCols);
86 }
87 
89 EIGEN_DEVICE_FUNC
90 inline const Block<const Derived> topRightCorner(Index cRows, Index cCols) const
91 {
92  return Block<const Derived>(derived(), 0, cols() - cCols, cRows, cCols);
93 }
94 
105 template<int CRows, int CCols>
106 EIGEN_DEVICE_FUNC
107 inline Block<Derived, CRows, CCols> topRightCorner()
108 {
109  return Block<Derived, CRows, CCols>(derived(), 0, cols() - CCols);
110 }
111 
113 template<int CRows, int CCols>
114 EIGEN_DEVICE_FUNC
115 inline const Block<const Derived, CRows, CCols> topRightCorner() const
116 {
117  return Block<const Derived, CRows, CCols>(derived(), 0, cols() - CCols);
118 }
119 
137 template<int CRows, int CCols>
138 inline Block<Derived, CRows, CCols> topRightCorner(Index cRows, Index cCols)
139 {
140  return Block<Derived, CRows, CCols>(derived(), 0, cols() - cCols, cRows, cCols);
141 }
142 
144 template<int CRows, int CCols>
145 inline const Block<const Derived, CRows, CCols> topRightCorner(Index cRows, Index cCols) const
146 {
147  return Block<const Derived, CRows, CCols>(derived(), 0, cols() - cCols, cRows, cCols);
148 }
149 
150 
151 
162 EIGEN_DEVICE_FUNC
163 inline Block<Derived> topLeftCorner(Index cRows, Index cCols)
164 {
165  return Block<Derived>(derived(), 0, 0, cRows, cCols);
166 }
167 
169 EIGEN_DEVICE_FUNC
170 inline const Block<const Derived> topLeftCorner(Index cRows, Index cCols) const
171 {
172  return Block<const Derived>(derived(), 0, 0, cRows, cCols);
173 }
174 
184 template<int CRows, int CCols>
185 EIGEN_DEVICE_FUNC
186 inline Block<Derived, CRows, CCols> topLeftCorner()
187 {
188  return Block<Derived, CRows, CCols>(derived(), 0, 0);
189 }
190 
192 template<int CRows, int CCols>
193 EIGEN_DEVICE_FUNC
194 inline const Block<const Derived, CRows, CCols> topLeftCorner() const
195 {
196  return Block<const Derived, CRows, CCols>(derived(), 0, 0);
197 }
198 
216 template<int CRows, int CCols>
217 inline Block<Derived, CRows, CCols> topLeftCorner(Index cRows, Index cCols)
218 {
219  return Block<Derived, CRows, CCols>(derived(), 0, 0, cRows, cCols);
220 }
221 
223 template<int CRows, int CCols>
224 inline const Block<const Derived, CRows, CCols> topLeftCorner(Index cRows, Index cCols) const
225 {
226  return Block<const Derived, CRows, CCols>(derived(), 0, 0, cRows, cCols);
227 }
228 
229 
230 
241 EIGEN_DEVICE_FUNC
242 inline Block<Derived> bottomRightCorner(Index cRows, Index cCols)
243 {
244  return Block<Derived>(derived(), rows() - cRows, cols() - cCols, cRows, cCols);
245 }
246 
248 EIGEN_DEVICE_FUNC
249 inline const Block<const Derived> bottomRightCorner(Index cRows, Index cCols) const
250 {
251  return Block<const Derived>(derived(), rows() - cRows, cols() - cCols, cRows, cCols);
252 }
253 
263 template<int CRows, int CCols>
264 EIGEN_DEVICE_FUNC
265 inline Block<Derived, CRows, CCols> bottomRightCorner()
266 {
267  return Block<Derived, CRows, CCols>(derived(), rows() - CRows, cols() - CCols);
268 }
269 
271 template<int CRows, int CCols>
272 EIGEN_DEVICE_FUNC
273 inline const Block<const Derived, CRows, CCols> bottomRightCorner() const
274 {
275  return Block<const Derived, CRows, CCols>(derived(), rows() - CRows, cols() - CCols);
276 }
277 
295 template<int CRows, int CCols>
296 inline Block<Derived, CRows, CCols> bottomRightCorner(Index cRows, Index cCols)
297 {
298  return Block<Derived, CRows, CCols>(derived(), rows() - cRows, cols() - cCols, cRows, cCols);
299 }
300 
302 template<int CRows, int CCols>
303 inline const Block<const Derived, CRows, CCols> bottomRightCorner(Index cRows, Index cCols) const
304 {
305  return Block<const Derived, CRows, CCols>(derived(), rows() - cRows, cols() - cCols, cRows, cCols);
306 }
307 
308 
309 
320 EIGEN_DEVICE_FUNC
321 inline Block<Derived> bottomLeftCorner(Index cRows, Index cCols)
322 {
323  return Block<Derived>(derived(), rows() - cRows, 0, cRows, cCols);
324 }
325 
327 EIGEN_DEVICE_FUNC
328 inline const Block<const Derived> bottomLeftCorner(Index cRows, Index cCols) const
329 {
330  return Block<const Derived>(derived(), rows() - cRows, 0, cRows, cCols);
331 }
332 
342 template<int CRows, int CCols>
343 EIGEN_DEVICE_FUNC
344 inline Block<Derived, CRows, CCols> bottomLeftCorner()
345 {
346  return Block<Derived, CRows, CCols>(derived(), rows() - CRows, 0);
347 }
348 
350 template<int CRows, int CCols>
351 EIGEN_DEVICE_FUNC
352 inline const Block<const Derived, CRows, CCols> bottomLeftCorner() const
353 {
354  return Block<const Derived, CRows, CCols>(derived(), rows() - CRows, 0);
355 }
356 
374 template<int CRows, int CCols>
375 inline Block<Derived, CRows, CCols> bottomLeftCorner(Index cRows, Index cCols)
376 {
377  return Block<Derived, CRows, CCols>(derived(), rows() - cRows, 0, cRows, cCols);
378 }
379 
381 template<int CRows, int CCols>
382 inline const Block<const Derived, CRows, CCols> bottomLeftCorner(Index cRows, Index cCols) const
383 {
384  return Block<const Derived, CRows, CCols>(derived(), rows() - cRows, 0, cRows, cCols);
385 }
386 
387 
388 
398 EIGEN_DEVICE_FUNC
399 inline RowsBlockXpr topRows(Index n)
400 {
401  return RowsBlockXpr(derived(), 0, 0, n, cols());
402 }
403 
405 EIGEN_DEVICE_FUNC
406 inline ConstRowsBlockXpr topRows(Index n) const
407 {
408  return ConstRowsBlockXpr(derived(), 0, 0, n, cols());
409 }
410 
424 template<int N>
425 EIGEN_DEVICE_FUNC
426 inline typename NRowsBlockXpr<N>::Type topRows(Index n = N)
427 {
428  return typename NRowsBlockXpr<N>::Type(derived(), 0, 0, n, cols());
429 }
430 
432 template<int N>
433 EIGEN_DEVICE_FUNC
434 inline typename ConstNRowsBlockXpr<N>::Type topRows(Index n = N) const
435 {
436  return typename ConstNRowsBlockXpr<N>::Type(derived(), 0, 0, n, cols());
437 }
438 
439 
440 
450 EIGEN_DEVICE_FUNC
451 inline RowsBlockXpr bottomRows(Index n)
452 {
453  return RowsBlockXpr(derived(), rows() - n, 0, n, cols());
454 }
455 
457 EIGEN_DEVICE_FUNC
458 inline ConstRowsBlockXpr bottomRows(Index n) const
459 {
460  return ConstRowsBlockXpr(derived(), rows() - n, 0, n, cols());
461 }
462 
476 template<int N>
477 EIGEN_DEVICE_FUNC
478 inline typename NRowsBlockXpr<N>::Type bottomRows(Index n = N)
479 {
480  return typename NRowsBlockXpr<N>::Type(derived(), rows() - n, 0, n, cols());
481 }
482 
484 template<int N>
485 EIGEN_DEVICE_FUNC
486 inline typename ConstNRowsBlockXpr<N>::Type bottomRows(Index n = N) const
487 {
488  return typename ConstNRowsBlockXpr<N>::Type(derived(), rows() - n, 0, n, cols());
489 }
490 
491 
492 
503 EIGEN_DEVICE_FUNC
504 inline RowsBlockXpr middleRows(Index startRow, Index n)
505 {
506  return RowsBlockXpr(derived(), startRow, 0, n, cols());
507 }
508 
510 EIGEN_DEVICE_FUNC
511 inline ConstRowsBlockXpr middleRows(Index startRow, Index n) const
512 {
513  return ConstRowsBlockXpr(derived(), startRow, 0, n, cols());
514 }
515 
530 template<int N>
531 EIGEN_DEVICE_FUNC
532 inline typename NRowsBlockXpr<N>::Type middleRows(Index startRow, Index n = N)
533 {
534  return typename NRowsBlockXpr<N>::Type(derived(), startRow, 0, n, cols());
535 }
536 
538 template<int N>
539 EIGEN_DEVICE_FUNC
540 inline typename ConstNRowsBlockXpr<N>::Type middleRows(Index startRow, Index n = N) const
541 {
542  return typename ConstNRowsBlockXpr<N>::Type(derived(), startRow, 0, n, cols());
543 }
544 
545 
546 
556 EIGEN_DEVICE_FUNC
557 inline ColsBlockXpr leftCols(Index n)
558 {
559  return ColsBlockXpr(derived(), 0, 0, rows(), n);
560 }
561 
563 EIGEN_DEVICE_FUNC
564 inline ConstColsBlockXpr leftCols(Index n) const
565 {
566  return ConstColsBlockXpr(derived(), 0, 0, rows(), n);
567 }
568 
582 template<int N>
583 EIGEN_DEVICE_FUNC
584 inline typename NColsBlockXpr<N>::Type leftCols(Index n = N)
585 {
586  return typename NColsBlockXpr<N>::Type(derived(), 0, 0, rows(), n);
587 }
588 
590 template<int N>
591 EIGEN_DEVICE_FUNC
592 inline typename ConstNColsBlockXpr<N>::Type leftCols(Index n = N) const
593 {
594  return typename ConstNColsBlockXpr<N>::Type(derived(), 0, 0, rows(), n);
595 }
596 
597 
598 
608 EIGEN_DEVICE_FUNC
609 inline ColsBlockXpr rightCols(Index n)
610 {
611  return ColsBlockXpr(derived(), 0, cols() - n, rows(), n);
612 }
613 
615 EIGEN_DEVICE_FUNC
616 inline ConstColsBlockXpr rightCols(Index n) const
617 {
618  return ConstColsBlockXpr(derived(), 0, cols() - n, rows(), n);
619 }
620 
634 template<int N>
635 EIGEN_DEVICE_FUNC
636 inline typename NColsBlockXpr<N>::Type rightCols(Index n = N)
637 {
638  return typename NColsBlockXpr<N>::Type(derived(), 0, cols() - n, rows(), n);
639 }
640 
642 template<int N>
643 EIGEN_DEVICE_FUNC
644 inline typename ConstNColsBlockXpr<N>::Type rightCols(Index n = N) const
645 {
646  return typename ConstNColsBlockXpr<N>::Type(derived(), 0, cols() - n, rows(), n);
647 }
648 
649 
650 
661 EIGEN_DEVICE_FUNC
662 inline ColsBlockXpr middleCols(Index startCol, Index numCols)
663 {
664  return ColsBlockXpr(derived(), 0, startCol, rows(), numCols);
665 }
666 
668 EIGEN_DEVICE_FUNC
669 inline ConstColsBlockXpr middleCols(Index startCol, Index numCols) const
670 {
671  return ConstColsBlockXpr(derived(), 0, startCol, rows(), numCols);
672 }
673 
688 template<int N>
689 EIGEN_DEVICE_FUNC
690 inline typename NColsBlockXpr<N>::Type middleCols(Index startCol, Index n = N)
691 {
692  return typename NColsBlockXpr<N>::Type(derived(), 0, startCol, rows(), n);
693 }
694 
696 template<int N>
697 EIGEN_DEVICE_FUNC
698 inline typename ConstNColsBlockXpr<N>::Type middleCols(Index startCol, Index n = N) const
699 {
700  return typename ConstNColsBlockXpr<N>::Type(derived(), 0, startCol, rows(), n);
701 }
702 
703 
704 
721 template<int BlockRows, int BlockCols>
722 EIGEN_DEVICE_FUNC
723 inline Block<Derived, BlockRows, BlockCols> block(Index startRow, Index startCol)
724 {
725  return Block<Derived, BlockRows, BlockCols>(derived(), startRow, startCol);
726 }
727 
729 template<int BlockRows, int BlockCols>
730 EIGEN_DEVICE_FUNC
731 inline const Block<const Derived, BlockRows, BlockCols> block(Index startRow, Index startCol) const
732 {
733  return Block<const Derived, BlockRows, BlockCols>(derived(), startRow, startCol);
734 }
735 
755 template<int BlockRows, int BlockCols>
756 inline Block<Derived, BlockRows, BlockCols> block(Index startRow, Index startCol,
757  Index blockRows, Index blockCols)
758 {
759  return Block<Derived, BlockRows, BlockCols>(derived(), startRow, startCol, blockRows, blockCols);
760 }
761 
763 template<int BlockRows, int BlockCols>
764 inline const Block<const Derived, BlockRows, BlockCols> block(Index startRow, Index startCol,
765  Index blockRows, Index blockCols) const
766 {
767  return Block<const Derived, BlockRows, BlockCols>(derived(), startRow, startCol, blockRows, blockCols);
768 }
769 
776 EIGEN_DEVICE_FUNC
777 inline ColXpr col(Index i)
778 {
779  return ColXpr(derived(), i);
780 }
781 
783 EIGEN_DEVICE_FUNC
784 inline ConstColXpr col(Index i) const
785 {
786  return ConstColXpr(derived(), i);
787 }
788 
795 EIGEN_DEVICE_FUNC
796 inline RowXpr row(Index i)
797 {
798  return RowXpr(derived(), i);
799 }
800 
802 EIGEN_DEVICE_FUNC
803 inline ConstRowXpr row(Index i) const
804 {
805  return ConstRowXpr(derived(), i);
806 }
807 
824 EIGEN_DEVICE_FUNC
825 inline SegmentReturnType segment(Index start, Index n)
826 {
827  EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
828  return SegmentReturnType(derived(), start, n);
829 }
830 
831 
833 EIGEN_DEVICE_FUNC
834 inline ConstSegmentReturnType segment(Index start, Index n) const
835 {
836  EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
837  return ConstSegmentReturnType(derived(), start, n);
838 }
839 
855 EIGEN_DEVICE_FUNC
856 inline SegmentReturnType head(Index n)
857 {
858  EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
859  return SegmentReturnType(derived(), 0, n);
860 }
861 
863 EIGEN_DEVICE_FUNC
864 inline ConstSegmentReturnType head(Index n) const
865 {
866  EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
867  return ConstSegmentReturnType(derived(), 0, n);
868 }
869 
885 EIGEN_DEVICE_FUNC
886 inline SegmentReturnType tail(Index n)
887 {
888  EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
889  return SegmentReturnType(derived(), this->size() - n, n);
890 }
891 
893 EIGEN_DEVICE_FUNC
894 inline ConstSegmentReturnType tail(Index n) const
895 {
896  EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
897  return ConstSegmentReturnType(derived(), this->size() - n, n);
898 }
899 
916 template<int N>
917 EIGEN_DEVICE_FUNC
918 inline typename FixedSegmentReturnType<N>::Type segment(Index start, Index n = N)
919 {
920  EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
921  return typename FixedSegmentReturnType<N>::Type(derived(), start, n);
922 }
923 
925 template<int N>
926 EIGEN_DEVICE_FUNC
927 inline typename ConstFixedSegmentReturnType<N>::Type segment(Index start, Index n = N) const
928 {
929  EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
930  return typename ConstFixedSegmentReturnType<N>::Type(derived(), start, n);
931 }
932 
948 template<int N>
949 EIGEN_DEVICE_FUNC
950 inline typename FixedSegmentReturnType<N>::Type head(Index n = N)
951 {
952  EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
953  return typename FixedSegmentReturnType<N>::Type(derived(), 0, n);
954 }
955 
957 template<int N>
958 EIGEN_DEVICE_FUNC
959 inline typename ConstFixedSegmentReturnType<N>::Type head(Index n = N) const
960 {
961  EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
962  return typename ConstFixedSegmentReturnType<N>::Type(derived(), 0, n);
963 }
964 
980 template<int N>
981 EIGEN_DEVICE_FUNC
982 inline typename FixedSegmentReturnType<N>::Type tail(Index n = N)
983 {
984  EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
985  return typename FixedSegmentReturnType<N>::Type(derived(), size() - n);
986 }
987 
989 template<int N>
990 EIGEN_DEVICE_FUNC
991 inline typename ConstFixedSegmentReturnType<N>::Type tail(Index n = N) const
992 {
993  EIGEN_STATIC_ASSERT_VECTOR_ONLY(Derived)
994  return typename ConstFixedSegmentReturnType<N>::Type(derived(), size() - n);
995 }