ARTS 2.5.10 (git: 2f1c442c)
matpackVI.h
Go to the documentation of this file.
1/* Copyright (C) 2001-2012 Stefan Buehler <sbuehler@ltu.se>
2
3 This program is free software; you can redistribute it and/or modify it
4 under the terms of the GNU General Public License as published by the
5 Free Software Foundation; either version 2, or (at your option) any
6 later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16 USA. */
17
28#ifndef matpackVI_h
29#define matpackVI_h
30
31#include <utility>
32
33#include "matpackV.h"
34#include "matpack_concepts.h"
35
36#define CHECK(x) \
37 ARTS_ASSERT(0 <= x); \
38 ARTS_ASSERT(x < m##x##r.mextent)
39#define OFFSET(x) m##x##r.mstart + x* m##x##r.mstride
40
44 public:
45 // Constructors:
47 Iterator6D() = default;
48
50 Iterator6D(const Tensor5View& x, Index stride)
51 : msv(x), mstride(stride) { /* Nothing to do here. */
52 }
53
54 // Operators:
57 msv.mdata += mstride;
58 return *this;
59 }
60
65 bool operator!=(const Iterator6D& other) const {
68 other.msv.mdata + other.msv.msr.mstart + other.msv.mbr.mstart +
69 other.msv.mpr.mstart + other.msv.mrr.mstart + other.msv.mcr.mstart)
70 return true;
71 return false;
72 }
73
76 Tensor5View* operator->() { return &msv; }
77
79 Tensor5View& operator*() { return msv; }
80
81 private:
86};
87
90 public:
91 // Constructors:
93 ConstIterator6D() = default;
94
97 : msv(std::move(x)), mstride(stride) { /* Nothing to do here. */
98 }
99
100 // Operators:
103 msv.mdata += mstride;
104 return *this;
105 }
106
111 bool operator!=(const ConstIterator6D& other) const {
114 other.msv.mdata + other.msv.msr.mstart + other.msv.mbr.mstart +
115 other.msv.mpr.mstart + other.msv.mrr.mstart + other.msv.mcr.mstart)
116 return true;
117 return false;
118 }
119
122 const ConstTensor5View* operator->() const { return &msv; }
123
125 const ConstTensor5View& operator*() const { return msv; }
126
127 private:
132};
133
134// Declare class Tensor6:
135class Tensor6;
136
151 public:
152 constexpr ConstTensor6View(const ConstTensor6View&) = default;
153 constexpr ConstTensor6View(ConstTensor6View&&) = default;
156
157 // Member functions:
158 [[nodiscard]] Index nvitrines() const noexcept { return mvr.mextent; }
159 [[nodiscard]] Index nshelves() const noexcept { return msr.mextent; }
160 [[nodiscard]] Index nbooks() const noexcept { return mbr.mextent; }
161 [[nodiscard]] Index npages() const noexcept { return mpr.mextent; }
162 [[nodiscard]] Index nrows() const noexcept { return mrr.mextent; }
163 [[nodiscard]] Index ncols() const noexcept { return mcr.mextent; }
164
165 // Total size
166 [[nodiscard]] Index size() const noexcept {
167 return nvitrines() * nshelves() * nbooks() * npages() * nrows() * ncols();
168 }
169 [[nodiscard]] bool empty() const noexcept { return size() == 0; }
170
172 [[nodiscard]] Shape<6> shape() const {
173 return {nvitrines(), nshelves(), nbooks(), npages(), nrows(), ncols()};
174 }
175
176 // Const index operators:
177
178 // Result 6D (1 combination)
179 // ------
181 const Range& s,
182 const Range& b,
183 const Range& p,
184 const Range& r,
185 const Range& c) const;
186
187 // Result 5D (6 combinations)
188 // -----|
190 const Range& s,
191 const Range& b,
192 const Range& p,
193 const Range& r,
194 Index c) const;
195 // ----|-
197 const Range& s,
198 const Range& b,
199 const Range& p,
200 Index r,
201 const Range& c) const;
202 // ---|--
204 const Range& s,
205 const Range& b,
206 Index p,
207 const Range& r,
208 const Range& c) const;
209 // --|---
211 const Range& s,
212 Index b,
213 const Range& p,
214 const Range& r,
215 const Range& c) const;
216 // -|----
218 Index s,
219 const Range& b,
220 const Range& p,
221 const Range& r,
222 const Range& c) const;
223 // |-----
225 const Range& s,
226 const Range& b,
227 const Range& p,
228 const Range& r,
229 const Range& c) const;
230
231 // Result 4D (5+4+3+2+1 = 15 combinations)
232 // ----||
234 const Range& s,
235 const Range& b,
236 const Range& p,
237 Index r,
238 Index c) const;
239 // ---|-|
241 const Range& s,
242 const Range& b,
243 Index p,
244 const Range& r,
245 Index c) const;
246 // --|--|
248 const Range& s,
249 Index b,
250 const Range& p,
251 const Range& r,
252 Index c) const;
253 // -|---|
255 Index s,
256 const Range& b,
257 const Range& p,
258 const Range& r,
259 Index c) const;
260 // |----|
262 const Range& s,
263 const Range& b,
264 const Range& p,
265 const Range& r,
266 Index c) const;
267 // ---||-
269 const Range& s,
270 const Range& b,
271 Index p,
272 Index r,
273 const Range& c) const;
274 // --|-|-
276 const Range& s,
277 Index b,
278 const Range& p,
279 Index r,
280 const Range& c) const;
281 // -|--|-
283 Index s,
284 const Range& b,
285 const Range& p,
286 Index r,
287 const Range& c) const;
288 // |---|-
290 const Range& s,
291 const Range& b,
292 const Range& p,
293 Index r,
294 const Range& c) const;
295 // --||--
297 const Range& s,
298 Index b,
299 Index p,
300 const Range& r,
301 const Range& c) const;
302 // -|-|--
304 Index s,
305 const Range& b,
306 Index p,
307 const Range& r,
308 const Range& c) const;
309 // |--|--
311 const Range& s,
312 const Range& b,
313 Index p,
314 const Range& r,
315 const Range& c) const;
316 // -||---
318 Index s,
319 Index b,
320 const Range& p,
321 const Range& r,
322 const Range& c) const;
323 // |-|---
325 const Range& s,
326 Index b,
327 const Range& p,
328 const Range& r,
329 const Range& c) const;
330 // ||----
332 Index s,
333 const Range& b,
334 const Range& p,
335 const Range& r,
336 const Range& c) const;
337
338 // Result 3D (4+3+2+1+ 3+2+1+ 2+1 +1 = 20 combinations)
339 // ---|||
341 const Range& s,
342 const Range& b,
343 Index p,
344 Index r,
345 Index c) const;
346 // --|-||
348 const Range& s,
349 Index b,
350 const Range& p,
351 Index r,
352 Index c) const;
353 // -|--||
355 Index s,
356 const Range& b,
357 const Range& p,
358 Index r,
359 Index c) const;
360 // |---||
362 const Range& s,
363 const Range& b,
364 const Range& p,
365 Index r,
366 Index c) const;
367 // --||-|
369 const Range& s,
370 Index b,
371 Index p,
372 const Range& r,
373 Index c) const;
374 // -|-|-|
376 Index s,
377 const Range& b,
378 Index p,
379 const Range& r,
380 Index c) const;
381 // |--|-|
383 const Range& s,
384 const Range& b,
385 Index p,
386 const Range& r,
387 Index c) const;
388 // -||--|
390 Index s,
391 Index b,
392 const Range& p,
393 const Range& r,
394 Index c) const;
395 // |-|--|
397 const Range& s,
398 Index b,
399 const Range& p,
400 const Range& r,
401 Index c) const;
402 // ||---|
404 Index s,
405 const Range& b,
406 const Range& p,
407 const Range& r,
408 Index c) const;
409 // --|||-
411 const Range& s,
412 Index b,
413 Index p,
414 Index r,
415 const Range& c) const;
416 // -|-||-
418 Index s,
419 const Range& b,
420 Index p,
421 Index r,
422 const Range& c) const;
423 // |--||-
425 const Range& s,
426 const Range& b,
427 Index p,
428 Index r,
429 const Range& c) const;
430 // -||-|-
432 Index s,
433 Index b,
434 const Range& p,
435 Index r,
436 const Range& c) const;
437 // |-|-|-
439 const Range& s,
440 Index b,
441 const Range& p,
442 Index r,
443 const Range& c) const;
444 // ||--|-
446 Index s,
447 const Range& b,
448 const Range& p,
449 Index r,
450 const Range& c) const;
451 // -|||--
453 Index s,
454 Index b,
455 Index p,
456 const Range& r,
457 const Range& c) const;
458 // |-||--
460 const Range& s,
461 Index b,
462 Index p,
463 const Range& r,
464 const Range& c) const;
465 // ||-|--
467 Index s,
468 const Range& b,
469 Index p,
470 const Range& r,
471 const Range& c) const;
472 // |||---
474 Index s,
475 Index b,
476 const Range& p,
477 const Range& r,
478 const Range& c) const;
479
480 // Result 2D (15 combinations)
481 // IIII--
483 Index v, Index s, Index b, Index p, const Range& r, const Range& c) const;
484 // III-I-
486 Index v, Index s, Index b, const Range& p, Index r, const Range& c) const;
487 // II-II-
489 Index v, Index s, const Range& b, Index p, Index r, const Range& c) const;
490 // I-III-
492 Index v, const Range& s, Index b, Index p, Index r, const Range& c) const;
493 // -IIII-
495 const Range& v, Index s, Index b, Index p, Index r, const Range& c) const;
496 // III--I
498 Index v, Index s, Index b, const Range& p, const Range& r, Index c) const;
499 // II-I-I
501 Index v, Index s, const Range& b, Index p, const Range& r, Index c) const;
502 // I-II-I
504 Index v, const Range& s, Index b, Index p, const Range& r, Index c) const;
505 // -III-I
507 const Range& v, Index s, Index b, Index p, const Range& r, Index c) const;
508 // II--II
510 Index v, Index s, const Range& b, const Range& p, Index r, Index c) const;
511 // I-I-II
513 Index v, const Range& s, Index b, const Range& p, Index r, Index c) const;
514 // -II-II
516 const Range& v, Index s, Index b, const Range& p, Index r, Index c) const;
517 // I--III
519 Index v, const Range& s, const Range& b, Index p, Index r, Index c) const;
520 // -I-III
522 const Range& v, Index s, const Range& b, Index p, Index r, Index c) const;
523 // --IIII
525 const Range& v, const Range& s, Index b, Index p, Index r, Index c) const;
526
527 // Result 1D (6 combinations)
528 // IIIII-
530 Index v, Index s, Index b, Index p, Index r, const Range& c) const;
531 // IIII-I
533 Index v, Index s, Index b, Index p, const Range& r, Index c) const;
534 // III-II
536 Index v, Index s, Index b, const Range& p, Index r, Index c) const;
537 // II-III
539 Index v, Index s, const Range& b, Index p, Index r, Index c) const;
540 // I-IIII
542 Index v, const Range& s, Index b, Index p, Index r, Index c) const;
543 // -IIIII
545 const Range& v, Index s, Index b, Index p, Index r, Index c) const;
546
547 // Result scalar (1 combination)
548 // IIIIII
550 Index v, Index s, Index b, Index p, Index r, Index c) const {
551 CHECK(v);
552 CHECK(s);
553 CHECK(b);
554 CHECK(p);
555 CHECK(r);
556 CHECK(c);
557 return get(v, s, b, p, r, c);
558 }
559
561 [[nodiscard]] Numeric get(
562 Index v, Index s, Index b, Index p, Index r, Index c) const {
563 return *(mdata + OFFSET(v) + OFFSET(s) + OFFSET(b) + OFFSET(p) + OFFSET(r) +
564 OFFSET(c));
565 }
566
567 // Functions returning iterators:
568 [[nodiscard]] ConstIterator6D begin() const;
569 [[nodiscard]] ConstIterator6D end() const;
570
571 // Destructor:
572 virtual ~ConstTensor6View() = default;
573
574 // Friends:
575 friend class ConstIterator7D;
576 friend class Tensor6View;
577 friend class ConstTensor7View;
578
579 friend std::ostream& operator<<(std::ostream& os, const ConstTensor6View& v);
580
581 // Special constructor to make a Tensor6 view of a Tensor5.
583
584 protected:
585 // Constructors:
586 ConstTensor6View() = default;
588 const Range& v,
589 const Range& s,
590 const Range& b,
591 const Range& p,
592 const Range& r,
593 const Range& c);
595 const Range& pv,
596 const Range& ps,
597 const Range& pb,
598 const Range& pp,
599 const Range& pr,
600 const Range& pc,
601 const Range& nv,
602 const Range& ns,
603 const Range& nb,
604 const Range& np,
605 const Range& nr,
606 const Range& nc);
607
608 // Data members:
609 // -------------
611 Range mvr{0, 0, 1};
613 Range msr{0, 0, 1};
615 Range mbr{0, 0, 1};
617 Range mpr{0, 0, 1};
619 Range mrr{0, 0, 1};
621 Range mcr{0, 0, 1};
623 Numeric* mdata{nullptr};
624};
625
636 public:
637 // Make const methods visible from base class
640 using ConstTensor6View::operator();
642
643 constexpr Tensor6View(const Tensor6View&) = default;
644
645 // Non-const index operators:
646
647 // Result 6D (1 combination)
648 // ------
650 const Range& s,
651 const Range& b,
652 const Range& p,
653 const Range& r,
654 const Range& c);
655
656 // Result 5D (6 combinations)
657 // -----|
659 const Range& s,
660 const Range& b,
661 const Range& p,
662 const Range& r,
663 Index c);
664 // ----|-
666 const Range& s,
667 const Range& b,
668 const Range& p,
669 Index r,
670 const Range& c);
671 // ---|--
673 const Range& s,
674 const Range& b,
675 Index p,
676 const Range& r,
677 const Range& c);
678 // --|---
680 const Range& s,
681 Index b,
682 const Range& p,
683 const Range& r,
684 const Range& c);
685 // -|----
687 Index s,
688 const Range& b,
689 const Range& p,
690 const Range& r,
691 const Range& c);
692 // |-----
694 const Range& s,
695 const Range& b,
696 const Range& p,
697 const Range& r,
698 const Range& c);
699
700 // Result 4D (5+4+3+2+1 = 15 combinations)
701 // ----||
703 const Range& s,
704 const Range& b,
705 const Range& p,
706 Index r,
707 Index c);
708 // ---|-|
710 const Range& s,
711 const Range& b,
712 Index p,
713 const Range& r,
714 Index c);
715 // --|--|
717 const Range& s,
718 Index b,
719 const Range& p,
720 const Range& r,
721 Index c);
722 // -|---|
724 Index s,
725 const Range& b,
726 const Range& p,
727 const Range& r,
728 Index c);
729 // |----|
731 const Range& s,
732 const Range& b,
733 const Range& p,
734 const Range& r,
735 Index c);
736 // ---||-
738 const Range& s,
739 const Range& b,
740 Index p,
741 Index r,
742 const Range& c);
743 // --|-|-
745 const Range& s,
746 Index b,
747 const Range& p,
748 Index r,
749 const Range& c);
750 // -|--|-
752 Index s,
753 const Range& b,
754 const Range& p,
755 Index r,
756 const Range& c);
757 // |---|-
759 const Range& s,
760 const Range& b,
761 const Range& p,
762 Index r,
763 const Range& c);
764 // --||--
766 const Range& s,
767 Index b,
768 Index p,
769 const Range& r,
770 const Range& c);
771 // -|-|--
773 Index s,
774 const Range& b,
775 Index p,
776 const Range& r,
777 const Range& c);
778 // |--|--
780 const Range& s,
781 const Range& b,
782 Index p,
783 const Range& r,
784 const Range& c);
785 // -||---
787 Index s,
788 Index b,
789 const Range& p,
790 const Range& r,
791 const Range& c);
792 // |-|---
794 const Range& s,
795 Index b,
796 const Range& p,
797 const Range& r,
798 const Range& c);
799 // ||----
801 Index s,
802 const Range& b,
803 const Range& p,
804 const Range& r,
805 const Range& c);
806
807 // Result 3D (4+3+2+1+ 3+2+1+ 2+1 +1 = 20 combinations)
808 // ---|||
810 const Range& s,
811 const Range& b,
812 Index p,
813 Index r,
814 Index c);
815 // --|-||
817 const Range& s,
818 Index b,
819 const Range& p,
820 Index r,
821 Index c);
822 // -|--||
824 Index s,
825 const Range& b,
826 const Range& p,
827 Index r,
828 Index c);
829 // |---||
831 const Range& s,
832 const Range& b,
833 const Range& p,
834 Index r,
835 Index c);
836 // --||-|
838 const Range& s,
839 Index b,
840 Index p,
841 const Range& r,
842 Index c);
843 // -|-|-|
845 Index s,
846 const Range& b,
847 Index p,
848 const Range& r,
849 Index c);
850 // |--|-|
852 const Range& s,
853 const Range& b,
854 Index p,
855 const Range& r,
856 Index c);
857 // -||--|
859 Index s,
860 Index b,
861 const Range& p,
862 const Range& r,
863 Index c);
864 // |-|--|
866 const Range& s,
867 Index b,
868 const Range& p,
869 const Range& r,
870 Index c);
871 // ||---|
873 Index s,
874 const Range& b,
875 const Range& p,
876 const Range& r,
877 Index c);
878 // --|||-
880 const Range& s,
881 Index b,
882 Index p,
883 Index r,
884 const Range& c);
885 // -|-||-
887 Index s,
888 const Range& b,
889 Index p,
890 Index r,
891 const Range& c);
892 // |--||-
894 const Range& s,
895 const Range& b,
896 Index p,
897 Index r,
898 const Range& c);
899 // -||-|-
901 Index s,
902 Index b,
903 const Range& p,
904 Index r,
905 const Range& c);
906 // |-|-|-
908 const Range& s,
909 Index b,
910 const Range& p,
911 Index r,
912 const Range& c);
913 // ||--|-
915 Index s,
916 const Range& b,
917 const Range& p,
918 Index r,
919 const Range& c);
920 // -|||--
922 Index s,
923 Index b,
924 Index p,
925 const Range& r,
926 const Range& c);
927 // |-||--
929 const Range& s,
930 Index b,
931 Index p,
932 const Range& r,
933 const Range& c);
934 // ||-|--
936 Index s,
937 const Range& b,
938 Index p,
939 const Range& r,
940 const Range& c);
941 // |||---
943 Index s,
944 Index b,
945 const Range& p,
946 const Range& r,
947 const Range& c);
948
949 // Result 2D (15 combinations)
950 // IIII--
952 Index v, Index s, Index b, Index p, const Range& r, const Range& c);
953 // III-I-
955 Index v, Index s, Index b, const Range& p, Index r, const Range& c);
956 // II-II-
958 Index v, Index s, const Range& b, Index p, Index r, const Range& c);
959 // I-III-
961 Index v, const Range& s, Index b, Index p, Index r, const Range& c);
962 // -IIII-
964 const Range& v, Index s, Index b, Index p, Index r, const Range& c);
965 // III--I
967 Index v, Index s, Index b, const Range& p, const Range& r, Index c);
968 // II-I-I
970 Index v, Index s, const Range& b, Index p, const Range& r, Index c);
971 // I-II-I
973 Index v, const Range& s, Index b, Index p, const Range& r, Index c);
974 // -III-I
976 const Range& v, Index s, Index b, Index p, const Range& r, Index c);
977 // II--II
979 Index v, Index s, const Range& b, const Range& p, Index r, Index c);
980 // I-I-II
982 Index v, const Range& s, Index b, const Range& p, Index r, Index c);
983 // -II-II
985 const Range& v, Index s, Index b, const Range& p, Index r, Index c);
986 // I--III
988 Index v, const Range& s, const Range& b, Index p, Index r, Index c);
989 // -I-III
991 const Range& v, Index s, const Range& b, Index p, Index r, Index c);
992 // --IIII
994 const Range& v, const Range& s, Index b, Index p, Index r, Index c);
995
996 // Result 1D (6 combinations)
997 // IIIII-
999 Index v, Index s, Index b, Index p, Index r, const Range& c);
1000 // IIII-I
1002 Index v, Index s, Index b, Index p, const Range& r, Index c);
1003 // III-II
1005 Index v, Index s, Index b, const Range& p, Index r, Index c);
1006 // II-III
1008 Index v, Index s, const Range& b, Index p, Index r, Index c);
1009 // I-IIII
1011 Index v, const Range& s, Index b, Index p, Index r, Index c);
1012 // -IIIII
1014 const Range& v, Index s, Index b, Index p, Index r, Index c);
1015
1016#define GETFUN(v, s, b, p, r, c) \
1017 *(mdata + OFFSET(v) + OFFSET(s) + OFFSET(b) + OFFSET(p) + OFFSET(r) + \
1018 OFFSET(c))
1019 // Result scalar (1 combination)
1020 // IIIIII
1022 CHECK(v);
1023 CHECK(s);
1024 CHECK(b);
1025 CHECK(p);
1026 CHECK(r);
1027 CHECK(c);
1028 return GETFUN(v, s, b, p, r, c);
1029 }
1030
1033 return GETFUN(v, s, b, p, r, c);
1034 }
1035#undef GETFUN
1036
1037 // Conversion to a plain C-array
1038 [[nodiscard]] const Numeric* get_c_array() const ARTS_NOEXCEPT;
1040
1041 // Functions returning iterators:
1042 Iterator6D begin();
1043 Iterator6D end();
1044
1045 // Assignment operators:
1046 Tensor6View& operator=(const ConstTensor6View& v);
1047 Tensor6View& operator=(const Tensor6View& v);
1048 Tensor6View& operator=(const Tensor6& v);
1049 Tensor6View& operator=(Numeric x);
1050
1051 // Other operators:
1052 Tensor6View& operator*=(Numeric x);
1053 Tensor6View& operator/=(Numeric x);
1054 Tensor6View& operator+=(Numeric x);
1055 Tensor6View& operator-=(Numeric x);
1056
1057 Tensor6View& operator*=(const ConstTensor6View& x);
1058 Tensor6View& operator/=(const ConstTensor6View& x);
1059 Tensor6View& operator+=(const ConstTensor6View& x);
1060 Tensor6View& operator-=(const ConstTensor6View& x);
1061
1062 // Destructor:
1063 ~Tensor6View() override = default;
1064
1065 // Friends:
1066 friend class Iterator7D;
1067 friend class Tensor7View;
1068
1069 // Special constructor to make a Tensor6 view of a Tensor5.
1070 Tensor6View(const Tensor5View& a);
1071
1072 protected:
1073 // Constructors:
1074 Tensor6View() = default;
1075 Tensor6View(Numeric* data,
1076 const Range& v,
1077 const Range& s,
1078 const Range& b,
1079 const Range& p,
1080 const Range& r,
1081 const Range& c);
1082 Tensor6View(Numeric* data,
1083 const Range& pv,
1084 const Range& ps,
1085 const Range& pb,
1086 const Range& pp,
1087 const Range& pr,
1088 const Range& pc,
1089 const Range& nv,
1090 const Range& ns,
1091 const Range& nb,
1092 const Range& np,
1093 const Range& nr,
1094 const Range& nc);
1095};
1096
1105class Tensor6 : public Tensor6View {
1106 public:
1107 static constexpr bool matpack_type{true};
1108
1109 // Constructors:
1110 Tensor6() = default;
1111 Tensor6(Index v, Index s, Index b, Index p, Index r, Index c);
1112 Tensor6(Index v, Index s, Index b, Index p, Index r, Index c, Numeric fill);
1113 Tensor6(const ConstTensor6View& v);
1114 Tensor6(const Tensor6& v);
1115 Tensor6(Tensor6&& v) noexcept : Tensor6View(std::forward<Tensor6View>(v)) {
1116 v.mdata = nullptr;
1117 }
1118
1121 : Tensor6(matpack::vitrine_size(init), matpack::shelf_size(init),
1122 matpack::book_size(init), matpack::page_size(init),
1123 matpack::row_size(init), matpack::column_size(init)) {
1124 *this = init;
1125 }
1126
1129 if (const auto s = matpack::shape<Index, 6>(init); shape().data not_eq s)
1130 resize(s[0], s[1], s[2], s[3], s[4], s[5]);
1131
1132 auto [I, J, K, L, M, N] = shape().data;
1133 for (Index i = 0; i < I; i++)
1134 for (Index j = 0; j < J; j++)
1135 for (Index k = 0; k < K; k++)
1136 for (Index x = 0; x < L; x++)
1137 for (Index m = 0; m < M; m++)
1138 for (Index n = 0; n < N; n++)
1139 operator()(i, j, k, x, m, n) = init(i, j, k, x, m, n);
1140
1141 return *this;
1142 }
1143
1158 const Range& r0,
1159 const Range& r1,
1160 const Range& r2,
1161 const Range& r3,
1162 const Range& r4,
1163 const Range& r5) ARTS_NOEXCEPT
1164 : Tensor6View(d, r0, r1, r2, r3, r4, r5) {
1165 ARTS_ASSERT(not(r0.get_extent() < 0), "Must have size");
1166 ARTS_ASSERT(not(r1.get_extent() < 0), "Must have size");
1167 ARTS_ASSERT(not(r2.get_extent() < 0), "Must have size");
1168 ARTS_ASSERT(not(r3.get_extent() < 0), "Must have size");
1169 ARTS_ASSERT(not(r4.get_extent() < 0), "Must have size");
1170 ARTS_ASSERT(not(r5.get_extent() < 0), "Must have size");
1171 }
1172
1173 // Assignment operators:
1174 Tensor6& operator=(const Tensor6& x);
1177
1178 // Resize function:
1179 void resize(Index v, Index s, Index b, Index p, Index r, Index c);
1180
1181 // Swap function:
1182 friend void swap(Tensor6& t1, Tensor6& t2) noexcept;
1183
1184 // Destructor:
1185 ~Tensor6() noexcept override;
1186
1188 template <std::size_t dim0>
1189 Vector reduce_rank() && ARTS_NOEXCEPT {
1190 static_assert(dim0 < 6, "Bad Dimension, Out-of-Bounds");
1191
1192 Range r0(0,
1193 dim0 == 0 ? nvitrines()
1194 : dim0 == 1 ? nshelves()
1195 : dim0 == 2 ? nbooks()
1196 : dim0 == 3 ? npages()
1197 : dim0 == 4 ? nrows()
1198 : ncols());
1199
1200 Vector out(mdata, r0);
1201 ARTS_ASSERT(size() == out.size(),
1202 "Can only reduce size on same size input");
1203 mdata = nullptr;
1204 return out;
1205 }
1206
1208 template <std::size_t dim0, std::size_t dim1>
1210 static_assert(dim1 < 6, "Bad Dimension, Out-of-Bounds");
1211 static_assert(dim0 < dim1, "Bad Dimensions, dim1 must be larger than dim0");
1212
1213 const Range r1(0,
1214 dim1 == 1 ? nshelves()
1215 : dim1 == 2 ? nbooks()
1216 : dim1 == 3 ? npages()
1217 : dim1 == 4 ? nrows()
1218 : ncols());
1219 const Range r0(0,
1220 dim0 == 0 ? nvitrines()
1221 : dim0 == 1 ? nshelves()
1222 : dim0 == 2 ? nbooks()
1223 : dim0 == 3 ? npages()
1224 : nrows(),
1225 r1.get_extent());
1226
1227 Matrix out(mdata, r0, r1);
1228 ARTS_ASSERT(size() == out.size(),
1229 "Can only reduce size on same size input");
1230 mdata = nullptr;
1231 return out;
1232 }
1233
1235 template <std::size_t dim0, std::size_t dim1, std::size_t dim2>
1237 static_assert(dim2 < 6, "Bad Dimension, Out-of-Bounds");
1238 static_assert(dim0 < dim1, "Bad Dimensions, dim1 must be larger than dim0");
1239 static_assert(dim1 < dim2, "Bad Dimensions, dim2 must be larger than dim1");
1240
1241 const Range r2(0,
1242 dim2 == 2 ? nbooks()
1243 : dim2 == 3 ? npages()
1244 : dim2 == 4 ? nrows()
1245 : ncols());
1246 const Range r1(0,
1247 dim1 == 1 ? nshelves()
1248 : dim1 == 2 ? nbooks()
1249 : dim1 == 3 ? npages()
1250 : nrows(),
1251 r2.get_extent());
1252 const Range r0(0,
1253 dim0 == 0 ? nvitrines()
1254 : dim0 == 1 ? nshelves()
1255 : dim0 == 2 ? nbooks()
1256 : npages(),
1257 r1.get_extent() * r2.get_extent());
1258
1259 Tensor3 out(mdata, r0, r1, r2);
1260 ARTS_ASSERT(size() == out.size(),
1261 "Can only reduce size on same size input");
1262 mdata = nullptr;
1263 return out;
1264 }
1265
1267 template <std::size_t dim0,
1268 std::size_t dim1,
1269 std::size_t dim2,
1270 std::size_t dim3>
1272 static_assert(dim3 < 6, "Bad Dimension, Out-of-Bounds");
1273 static_assert(dim0 < dim1, "Bad Dimensions, dim1 must be larger than dim0");
1274 static_assert(dim1 < dim2, "Bad Dimensions, dim2 must be larger than dim1");
1275 static_assert(dim2 < dim3, "Bad Dimensions, dim3 must be larger than dim2");
1276
1277 const Range r3(0, dim3 == 3 ? npages() : dim3 == 4 ? nrows() : ncols());
1278 const Range r2(0,
1279 dim2 == 2 ? nbooks()
1280 : dim2 == 3 ? npages()
1281 : nrows(),
1282 r3.get_extent());
1283 const Range r1(0,
1284 dim1 == 1 ? nshelves()
1285 : dim1 == 2 ? nbooks()
1286 : npages(),
1287 r2.get_extent() * r3.get_extent());
1288 const Range r0(0,
1289 dim0 == 0 ? nvitrines()
1290 : dim0 == 1 ? nshelves()
1291 : nbooks(),
1292 r1.get_extent() * r2.get_extent() * r3.get_extent());
1293
1294 Tensor4 out(mdata, r0, r1, r2, r3);
1295 ARTS_ASSERT(size() == out.size(),
1296 "Can only reduce size on same size input");
1297 mdata = nullptr;
1298 return out;
1299 }
1300
1302 template <std::size_t dim0,
1303 std::size_t dim1,
1304 std::size_t dim2,
1305 std::size_t dim3,
1306 std::size_t dim4>
1308 static_assert(dim4 < 6, "Bad Dimension, Out-of-Bounds");
1309 static_assert(dim0 < dim1, "Bad Dimensions, dim1 must be larger than dim0");
1310 static_assert(dim1 < dim2, "Bad Dimensions, dim2 must be larger than dim1");
1311 static_assert(dim2 < dim3, "Bad Dimensions, dim3 must be larger than dim2");
1312 static_assert(dim3 < dim4, "Bad Dimensions, dim4 must be larger than dim3");
1313
1314 const Range r4(0, dim4 == 4 ? nrows() : ncols());
1315 const Range r3(0, dim3 == 3 ? npages() : nrows(), r4.get_extent());
1316 const Range r2(
1317 0, dim2 == 2 ? nbooks() : npages(), r3.get_extent() * r4.get_extent());
1318 const Range r1(0,
1319 dim1 == 1 ? nshelves() : nbooks(),
1320 r2.get_extent() * r3.get_extent() * r4.get_extent());
1321 const Range r0(
1322 0,
1323 dim0 == 0 ? nvitrines() : nshelves(),
1324 r1.get_extent() * r2.get_extent() * r3.get_extent() * r4.get_extent());
1325
1326 Tensor5 out(mdata, r0, r1, r2, r3, r4);
1327 ARTS_ASSERT(size() == out.size(),
1328 "Can only reduce size on same size input");
1329 mdata = nullptr;
1330 return out;
1331 }
1332
1333 template <class F>
1334 void transform_elementwise(F&& func) {
1335 std::transform(mdata, mdata + size(), mdata, func);
1336 }
1337};
1338
1339// Function declarations:
1340// ----------------------
1341
1342void copy(ConstIterator6D origin,
1343 const ConstIterator6D& end,
1344 Iterator6D target);
1345
1346void copy(Numeric x, Iterator6D target, const Iterator6D& end);
1347
1348void transform(Tensor6View y, double (&my_func)(double), ConstTensor6View x);
1349
1350Numeric max(const ConstTensor6View& x);
1351
1352Numeric min(const ConstTensor6View& x);
1353
1355// Helper function for debugging
1356#ifndef NDEBUG
1357
1359 Tensor6View& tv, Index v, Index s, Index b, Index p, Index r, Index c);
1360
1361#endif
1363
1366
1368
1369#endif // matpackVI_h
base max(const Array< base > &x)
Max function.
Definition: array.h:145
base min(const Array< base > &x)
Min function.
Definition: array.h:161
This can be used to make arrays out of anything.
Definition: array.h:48
Const version of Iterator6D.
Definition: matpackVI.h:89
ConstTensor5View msv
Current position.
Definition: matpackVI.h:129
const ConstTensor5View * operator->() const
The -> operator is needed, so that we can write i->begin() to get the 1D iterators.
Definition: matpackVI.h:122
ConstIterator6D()=default
Default constructor.
ConstIterator6D(ConstTensor5View x, Index stride)
Explicit constructor.
Definition: matpackVI.h:96
Index mstride
Stride.
Definition: matpackVI.h:131
ConstIterator6D & operator++()
Prefix increment operator.
Definition: matpackVI.h:102
const ConstTensor5View & operator*() const
Dereferencing.
Definition: matpackVI.h:125
bool operator!=(const ConstIterator6D &other) const
Not equal operator, needed for algorithms like copy.
Definition: matpackVI.h:111
Const version of Iterator7D.
Definition: matpackVII.h:86
A constant view of a Matrix.
Definition: matpackI.h:1065
Index size() const noexcept
Definition: matpackI.h:1085
A constant view of a Tensor3.
Definition: matpackIII.h:133
Index size() const noexcept
Definition: matpackIII.h:154
A constant view of a Tensor4.
Definition: matpackIV.h:133
Index size() const noexcept
Definition: matpackIV.h:149
A constant view of a Tensor5.
Definition: matpackV.h:144
Range mpr
The page range of mdata that is actually used.
Definition: matpackV.h:330
Range mcr
The column range of mdata that is actually used.
Definition: matpackV.h:334
Numeric * mdata
Pointer to the plain C array that holds the data.
Definition: matpackV.h:336
Index size() const noexcept
Definition: matpackV.h:161
Range mbr
The book range of mdata that is actually used.
Definition: matpackV.h:328
Range msr
The shelf range of mdata that is actually used.
Definition: matpackV.h:326
Range mrr
The row range of mdata that is actually used.
Definition: matpackV.h:332
A constant view of a Tensor6.
Definition: matpackVI.h:150
constexpr ConstTensor6View(ConstTensor6View &&)=default
ConstIterator6D begin() const
Return const iterator to first sub-tensor.
Definition: matpackVI.cc:848
ConstTensor6View & operator=(ConstTensor6View &&)=default
ConstIterator6D end() const
Return const iterator behind last sub-tensor.
Definition: matpackVI.cc:855
virtual ~ConstTensor6View()=default
Range mvr
The vitrine range of mdata that is actually used.
Definition: matpackVI.h:611
Range mcr
The column range of mdata that is actually used.
Definition: matpackVI.h:621
Range mbr
The book range of mdata that is actually used.
Definition: matpackVI.h:615
Numeric * mdata
Pointer to the plain C array that holds the data.
Definition: matpackVI.h:623
Range mrr
The row range of mdata that is actually used.
Definition: matpackVI.h:619
Index size() const noexcept
Definition: matpackVI.h:166
Index nbooks() const noexcept
Definition: matpackVI.h:160
Index nvitrines() const noexcept
Definition: matpackVI.h:158
Numeric get(Index v, Index s, Index b, Index p, Index r, Index c) const
Get element implementation without assertions.
Definition: matpackVI.h:561
bool empty() const noexcept
Definition: matpackVI.h:169
ConstTensor6View operator()(const Range &v, const Range &s, const Range &b, const Range &p, const Range &r, const Range &c) const
Definition: matpackVI.cc:36
Index ncols() const noexcept
Definition: matpackVI.h:163
constexpr ConstTensor6View(const ConstTensor6View &)=default
friend std::ostream & operator<<(std::ostream &os, const ConstTensor6View &v)
Output operator.
Definition: matpackVI.cc:929
Numeric operator()(Index v, Index s, Index b, Index p, Index r, Index c) const
Definition: matpackVI.h:549
Index npages() const noexcept
Definition: matpackVI.h:161
Index nshelves() const noexcept
Definition: matpackVI.h:159
ConstTensor6View & operator=(const ConstTensor6View &)=default
Range mpr
The page range of mdata that is actually used.
Definition: matpackVI.h:617
Index nrows() const noexcept
Definition: matpackVI.h:162
Shape< 6 > shape() const
Definition: matpackVI.h:172
Range msr
The shelf range of mdata that is actually used.
Definition: matpackVI.h:613
ConstTensor6View()=default
A constant view of a Tensor7.
Definition: matpackVII.h:148
A constant view of a Vector.
Definition: matpackI.h:521
Index size() const noexcept
Definition: matpackI.h:550
The outermost iterator class for rank 6 tensors.
Definition: matpackVI.h:43
Iterator6D & operator++()
Prefix increment operator.
Definition: matpackVI.h:56
Iterator6D(const Tensor5View &x, Index stride)
Explicit constructor.
Definition: matpackVI.h:50
bool operator!=(const Iterator6D &other) const
Not equal operator, needed for algorithms like copy.
Definition: matpackVI.h:65
Tensor5View & operator*()
Dereferencing.
Definition: matpackVI.h:79
Tensor5View msv
Current position.
Definition: matpackVI.h:83
Tensor5View * operator->()
The -> operator is needed, so that we can write i->begin() to get the 1D iterators.
Definition: matpackVI.h:76
Iterator6D()=default
Default constructor.
Index mstride
Stride.
Definition: matpackVI.h:85
Implementation of Tensors of Rank 7.
Definition: matpackVII.h:39
The MatrixView class.
Definition: matpackI.h:1188
The Matrix class.
Definition: matpackI.h:1285
The range class.
Definition: matpackI.h:160
Index mstart
The start index.
Definition: matpackI.h:377
constexpr Index get_extent() const noexcept
Returns the extent of the range.
Definition: matpackI.h:343
Index mextent
The number of elements.
Definition: matpackI.h:380
The Tensor3View class.
Definition: matpackIII.h:251
The Tensor3 class.
Definition: matpackIII.h:352
The Tensor4View class.
Definition: matpackIV.h:296
The Tensor4 class.
Definition: matpackIV.h:435
The Tensor5View class.
Definition: matpackV.h:348
The Tensor5 class.
Definition: matpackV.h:524
The Tensor6View class.
Definition: matpackVI.h:635
Iterator6D end()
Return iterator behind last sub-tensor.
Definition: matpackVI.cc:1759
Numeric & operator()(Index v, Index s, Index b, Index p, Index r, Index c)
Definition: matpackVI.h:1021
Iterator6D begin()
Return iterator to first sub-tensor.
Definition: matpackVI.cc:1753
Tensor6View()=default
Numeric & get(Index v, Index s, Index b, Index p, Index r, Index c)
Get element implementation without assertions.
Definition: matpackVI.h:1032
Tensor6View & operator=(const ConstTensor6View &v)
Assignment operator.
Definition: matpackVI.cc:1774
const Numeric * get_c_array() const ARTS_NOEXCEPT
Conversion to plain C-array.
Definition: matpackVI.cc:1721
constexpr Tensor6View(const Tensor6View &)=default
Tensor6View operator()(const Range &v, const Range &s, const Range &b, const Range &p, const Range &r, const Range &c)
Definition: matpackVI.cc:954
The Tensor6 class.
Definition: matpackVI.h:1105
Tensor5 reduce_rank() &&ARTS_NOEXCEPT
Definition: matpackVI.h:1307
Tensor6(Numeric *d, const Range &r0, const Range &r1, const Range &r2, const Range &r3, const Range &r4, const Range &r5) ARTS_NOEXCEPT
Definition: matpackVI.h:1157
Tensor6 & operator=(const matpack::tensor6_like_not_tensor6 auto &init)
Set from a tensor type.
Definition: matpackVI.h:1128
void transform_elementwise(F &&func)
Definition: matpackVI.h:1334
Tensor6(const matpack::tensor6_like_not_tensor6 auto &init)
Initialization from a tensor type.
Definition: matpackVI.h:1120
Tensor6()=default
Tensor3 reduce_rank() &&ARTS_NOEXCEPT
Definition: matpackVI.h:1236
Tensor4 reduce_rank() &&ARTS_NOEXCEPT
Definition: matpackVI.h:1271
Tensor6(Tensor6 &&v) noexcept
Definition: matpackVI.h:1115
Matrix reduce_rank() &&ARTS_NOEXCEPT
Definition: matpackVI.h:1209
The Tensor7View class.
Definition: matpackVII.h:1308
The VectorView class.
Definition: matpackI.h:674
The Vector class.
Definition: matpackI.h:910
A concept precluding Arts types but allowing the tensor-like object.
#define ARTS_NOEXCEPT
Definition: debug.h:99
#define ARTS_ASSERT(condition,...)
Definition: debug.h:102
void copy(ConstIterator6D origin, const ConstIterator6D &end, Iterator6D target)
Copy data between begin and end to target.
Definition: matpackVI.cc:2007
#define CHECK(x)
Implementation of Tensors of Rank 6.
Definition: matpackVI.h:36
void transform(Tensor6View y, double(&my_func)(double), ConstTensor6View x)
A generic transform function for tensors, which can be used to implement mathematical functions opera...
Definition: matpackVI.cc:2250
Numeric debug_tensor6view_get_elem(Tensor6View &tv, Index v, Index s, Index b, Index p, Index r, Index c)
Helper function to access tensor elements.
Definition: matpackVI.cc:2328
#define OFFSET(x)
Definition: matpackVI.h:39
#define GETFUN(v, s, b, p, r, c)
Definition: matpackVI.h:1016
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:33
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
void swap(ComplexVector &v1, ComplexVector &v2) noexcept
Swaps two objects.
#define N
Definition: rng.cc:164
#define M
Definition: rng.cc:165
Helper shape class.
Definition: matpackI.h:387
#define d
#define v
#define a
#define c
#define b