ARTS 2.5.0 (git: 9ee3ac6c)
matpackV.cc
Go to the documentation of this file.
1/* Copyright (C) 2002-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
25#include "matpackV.h"
26#include "exceptions.h"
27
28using std::runtime_error;
29
30// Functions for ConstTensor5View:
31// ------------------------------
32
34
39 return (nshelves() == 0 || nbooks() == 0 || npages() == 0 || nrows() == 0 ||
40 ncols() == 0);
41}
42
45
48
51
54
57
62 const Range& b,
63 const Range& p,
64 const Range& r,
65 const Range& c) const {
66 return ConstTensor5View(mdata, msr, mbr, mpr, mrr, mcr, s, b, p, r, c);
67}
68
72 const Range& b,
73 const Range& p,
74 const Range& r,
75 Index c) const {
76 // Check that c is valid:
77 ARTS_ASSERT(0 <= c);
79
80 return ConstTensor4View(
81 mdata + mcr.mstart + c * mcr.mstride, msr, mbr, mpr, mrr, s, b, p, r);
82}
83
87 const Range& b,
88 const Range& p,
89 Index r,
90 const Range& c) const {
91 // Check that r is valid:
92 ARTS_ASSERT(0 <= r);
94
95 return ConstTensor4View(
96 mdata + mrr.mstart + r * mrr.mstride, msr, mbr, mpr, mcr, s, b, p, c);
97}
98
102 const Range& b,
103 Index p,
104 const Range& r,
105 const Range& c) const {
106 // Check that p is valid:
107 ARTS_ASSERT(0 <= p);
109
110 return ConstTensor4View(
111 mdata + mpr.mstart + p * mpr.mstride, msr, mbr, mrr, mcr, s, b, r, c);
112}
113
117 Index b,
118 const Range& p,
119 const Range& r,
120 const Range& c) const {
121 // Check that b is valid:
122 ARTS_ASSERT(0 <= b);
124
125 return ConstTensor4View(
126 mdata + mbr.mstart + b * mbr.mstride, msr, mpr, mrr, mcr, s, p, r, c);
127}
128
132 const Range& b,
133 const Range& p,
134 const Range& r,
135 const Range& c) const {
136 // Check that s is valid:
137 ARTS_ASSERT(0 <= s);
139
140 return ConstTensor4View(
141 mdata + msr.mstart + s * msr.mstride, mbr, mpr, mrr, mcr, b, p, r, c);
142}
143
147 const Range& s, const Range& b, const Range& p, Index r, Index c) const {
148 // Check that r and c is valid:
149 ARTS_ASSERT(0 <= r);
150 ARTS_ASSERT(0 <= c);
153
154 return ConstTensor3View(
156 msr,
157 mbr,
158 mpr,
159 s,
160 b,
161 p);
162}
163
167 const Range& s, const Range& b, Index p, const Range& r, Index c) const {
168 // Check that p and c are valid:
169 ARTS_ASSERT(0 <= p);
170 ARTS_ASSERT(0 <= c);
173
174 return ConstTensor3View(
176 msr,
177 mbr,
178 mrr,
179 s,
180 b,
181 r);
182}
183
187 const Range& s, const Range& b, Index p, Index r, const Range& c) const {
188 // Check that p and r are valid:
189 ARTS_ASSERT(0 <= p);
190 ARTS_ASSERT(0 <= r);
193
194 return ConstTensor3View(
195 mdata + mpr.mstart + p * mpr.mstride + mrr.mstart + r * mrr.mstride,
196 msr,
197 mbr,
198 mcr,
199 s,
200 b,
201 c);
202}
203
207 const Range& s, Index b, const Range& p, Index r, const Range& c) const {
208 // Check that b and r are valid:
209 ARTS_ASSERT(0 <= b);
210 ARTS_ASSERT(0 <= r);
213
214 return ConstTensor3View(
216 msr,
217 mpr,
218 mcr,
219 s,
220 p,
221 c);
222}
223
227 const Range& s, Index b, const Range& p, const Range& r, Index c) const {
228 // Check that b and c are valid:
229 ARTS_ASSERT(0 <= b);
230 ARTS_ASSERT(0 <= c);
233
234 return ConstTensor3View(
236 msr,
237 mpr,
238 mrr,
239 s,
240 p,
241 r);
242}
243
247 const Range& s, Index b, Index p, const Range& r, const Range& c) const {
248 // Check that b and p are valid:
249 ARTS_ASSERT(0 <= b);
250 ARTS_ASSERT(0 <= p);
253
254 return ConstTensor3View(
256 msr,
257 mrr,
258 mcr,
259 s,
260 r,
261 c);
262}
263
267 Index s, const Range& b, Index p, const Range& r, const Range& c) const {
268 // Check that s and p are valid:
269 ARTS_ASSERT(0 <= s);
270 ARTS_ASSERT(0 <= p);
274 return ConstTensor3View(
275 mdata + msr.mstart + s * msr.mstride + mpr.mstart + p * mpr.mstride,
276 mbr,
277 mrr,
278 mcr,
279 b,
280 r,
281 c);
282}
283
287 Index s, const Range& b, const Range& p, Index r, const Range& c) const {
288 // Check that s and r are valid:
289 ARTS_ASSERT(0 <= s);
290 ARTS_ASSERT(0 <= r);
293
294 return ConstTensor3View(
295 mdata + msr.mstart + s * msr.mstride + mrr.mstart + r * mrr.mstride,
296 mbr,
297 mpr,
298 mcr,
299 b,
300 p,
301 c);
302}
303
307 Index s, const Range& b, const Range& p, const Range& r, Index c) const {
308 // Check that s and c are valid:
309 ARTS_ASSERT(0 <= s);
310 ARTS_ASSERT(0 <= c);
313
314 return ConstTensor3View(
316 mbr,
317 mpr,
318 mrr,
319 b,
320 p,
321 r);
322}
323
327 Index s, Index b, const Range& p, const Range& r, const Range& c) const {
328 // Check that s and b are valid:
329 ARTS_ASSERT(0 <= s);
330 ARTS_ASSERT(0 <= b);
333
334 return ConstTensor3View(
336 mpr,
337 mrr,
338 mcr,
339 p,
340 r,
341 c);
342}
343
347 const Range& s, const Range& b, Index p, Index r, Index c) const {
348 // Check that p, r and c are valid:
349 ARTS_ASSERT(0 <= p);
350 ARTS_ASSERT(0 <= r);
351 ARTS_ASSERT(0 <= c);
355
357 r * mrr.mstride + mcr.mstart + c * mcr.mstride,
358 msr,
359 mbr,
360 s,
361 b);
362}
363
367 const Range& s, Index b, const Range& p, Index r, Index c) const {
368 // Check that b, r and c are valid:
369 ARTS_ASSERT(0 <= b);
370 ARTS_ASSERT(0 <= r);
371 ARTS_ASSERT(0 <= c);
375
377 r * mpr.mstride + mcr.mstart + c * mcr.mstride,
378 msr,
379 mpr,
380 s,
381 p);
382}
383
387 const Range& s, Index b, Index p, const Range& r, Index c) const {
388 // Check that b, p and c are valid:
389 ARTS_ASSERT(0 <= b);
390 ARTS_ASSERT(0 <= p);
391 ARTS_ASSERT(0 <= c);
395
397 p * mpr.mstride + mcr.mstart + c * mcr.mstride,
398 msr,
399 mrr,
400 s,
401 r);
402}
403
407 const Range& s, Index b, Index p, Index r, const Range& c) const {
408 // Check that b, p and r are valid:
409 ARTS_ASSERT(0 <= b);
410 ARTS_ASSERT(0 <= p);
411 ARTS_ASSERT(0 <= r);
415
417 p * mpr.mstride + mrr.mstart + r * mrr.mstride,
418 msr,
419 mcr,
420 s,
421 c);
422}
423
427 Index s, const Range& b, Index p, Index r, const Range& c) const {
428 // Check that s, p and r are valid:
429 ARTS_ASSERT(0 <= s);
430 ARTS_ASSERT(0 <= p);
431 ARTS_ASSERT(0 <= r);
435
437 p * mpr.mstride + mrr.mstart + r * mrr.mstride,
438 mbr,
439 mcr,
440 b,
441 c);
442}
443
447 Index s, const Range& b, Index p, const Range& r, Index c) const {
448 // Check that s, p and c are valid:
449 ARTS_ASSERT(0 <= s);
450 ARTS_ASSERT(0 <= p);
451 ARTS_ASSERT(0 <= c);
455
457 p * mpr.mstride + mcr.mstart + c * mcr.mstride,
458 mbr,
459 mrr,
460 b,
461 r);
462}
463
467 Index s, const Range& b, const Range& p, Index r, Index c) const {
468 // Check that s, r and c are valid:
469 ARTS_ASSERT(0 <= s);
470 ARTS_ASSERT(0 <= r);
471 ARTS_ASSERT(0 <= c);
475
477 r * mrr.mstride + mcr.mstart + c * mcr.mstride,
478 mbr,
479 mpr,
480 b,
481 p);
482}
483
487 Index s, Index b, const Range& p, const Range& r, Index c) const {
488 // Check that s, b and c are valid:
489 ARTS_ASSERT(0 <= s);
490 ARTS_ASSERT(0 <= b);
491 ARTS_ASSERT(0 <= c);
495
497 b * mbr.mstride + mcr.mstart + c * mcr.mstride,
498 mpr,
499 mrr,
500 p,
501 r);
502}
503
507 Index s, Index b, const Range& p, Index r, const Range& c) const {
508 // Check that s, b and r are valid:
509 ARTS_ASSERT(0 <= s);
510 ARTS_ASSERT(0 <= b);
511 ARTS_ASSERT(0 <= r);
515
517 b * mbr.mstride + mrr.mstart + r * mrr.mstride,
518 mpr,
519 mcr,
520 p,
521 c);
522}
523
527 Index s, Index b, Index p, const Range& r, const Range& c) const {
528 // Check that s, b and p are valid:
529 ARTS_ASSERT(0 <= s);
530 ARTS_ASSERT(0 <= b);
531 ARTS_ASSERT(0 <= p);
535
537 b * mbr.mstride + mpr.mstart + p * mpr.mstride,
538 mrr,
539 mcr,
540 r,
541 c);
542}
543
547 const Range& s, Index b, Index p, Index r, Index c) const {
548 // Check that b, p, r and c are valid:
549 ARTS_ASSERT(0 <= b);
550 ARTS_ASSERT(0 <= p);
551 ARTS_ASSERT(0 <= r);
552 ARTS_ASSERT(0 <= c);
557
559 p * mpr.mstride + mrr.mstart + r * mrr.mstride +
560 mcr.mstart + c * mcr.mstride,
561 msr,
562 s);
563}
564
568 Index s, const Range& b, Index p, Index r, Index c) const {
569 // Check that s, p, r and c are valid:
570 ARTS_ASSERT(0 <= s);
571 ARTS_ASSERT(0 <= p);
572 ARTS_ASSERT(0 <= r);
573 ARTS_ASSERT(0 <= c);
578
580 p * mpr.mstride + mrr.mstart + r * mrr.mstride +
581 mcr.mstart + c * mcr.mstride,
582 mbr,
583 b);
584}
585
589 Index s, Index b, const Range& p, Index r, Index c) const {
590 // Check that s, b, r and c are valid:
591 ARTS_ASSERT(0 <= s);
592 ARTS_ASSERT(0 <= b);
593 ARTS_ASSERT(0 <= r);
594 ARTS_ASSERT(0 <= c);
599
601 b * mbr.mstride + mrr.mstart + r * mrr.mstride +
602 mcr.mstart + c * mcr.mstride,
603 mpr,
604 p);
605}
606
610 Index s, Index b, Index p, const Range& r, Index c) const {
611 // Check that s, b, p and c are valid:
612 ARTS_ASSERT(0 <= s);
613 ARTS_ASSERT(0 <= b);
614 ARTS_ASSERT(0 <= p);
615 ARTS_ASSERT(0 <= c);
620
622 b * mbr.mstride + mpr.mstart + p * mpr.mstride +
623 mcr.mstart + c * mcr.mstride,
624 mrr,
625 r);
626}
627
631 Index s, Index b, Index p, Index r, const Range& c) const {
632 // Check that s, b, p and r are valid:
633 ARTS_ASSERT(0 <= s);
634 ARTS_ASSERT(0 <= b);
635 ARTS_ASSERT(0 <= p);
636 ARTS_ASSERT(0 <= r);
641
643 b * mbr.mstride + mpr.mstart + p * mpr.mstride +
644 mrr.mstart + r * mrr.mstride,
645 mcr,
646 c);
647}
648
656 ARTS_ASSERT (not (msr.mstart != 0 ||
658 mbr.mstart != 0 ||
660 mpr.mstart != 0 || mpr.mstride != mrr.mextent * mcr.mextent ||
661 mrr.mstart != 0 || mrr.mstride != mcr.mextent || mcr.mstart != 0 ||
662 mcr.mstride != 1),
663 "A Tensor5View can only be converted to a plain C-array if it's pointing to a continuous block of data");
664
665 return mdata;
666}
667
675 ARTS_ASSERT (not (msr.mstart != 0 ||
677 mbr.mstart != 0 ||
679 mpr.mstart != 0 || mpr.mstride != mrr.mextent * mcr.mextent ||
680 mrr.mstart != 0 || mrr.mstride != mcr.mextent || mcr.mstart != 0 ||
681 mcr.mstride != 1),
682 "A Tensor5View can only be converted to a plain C-array if it's pointing to a continuous block of data");
683
684 return mdata;
685}
686
689 return ConstIterator5D(
691}
692
695 return ConstIterator5D(
698 msr.mstride);
699}
700
703 : msr(0, 1, a.mbr.mextent * a.mpr.mextent * a.mrr.mextent * a.mcr.mextent),
704 mbr(a.mbr),
705 mpr(a.mpr),
706 mrr(a.mrr),
707 mcr(a.mcr),
708 mdata(a.mdata) {
709 // Nothing to do here.
710}
711
717 const Range& sr,
718 const Range& br,
719 const Range& pr,
720 const Range& rr,
721 const Range& cr)
722 : msr(sr), mbr(br), mpr(pr), mrr(rr), mcr(cr), mdata(data) {
723 // Nothing to do here.
724}
725
734 const Range& ps,
735 const Range& pb,
736 const Range& pp,
737 const Range& pr,
738 const Range& pc,
739 const Range& ns,
740 const Range& nb,
741 const Range& np,
742 const Range& nr,
743 const Range& nc)
744 : msr(ps, ns),
745 mbr(pb, nb),
746 mpr(pp, np),
747 mrr(pr, nr),
748 mcr(pc, nc),
749 mdata(data) {
750 // Nothing to do here.
751}
752
756std::ostream& operator<<(std::ostream& os, const ConstTensor5View& v) {
757 // Page iterators:
758 ConstIterator5D is = v.begin();
759 const ConstIterator5D end_shelf = v.end();
760
761 if (is != end_shelf) {
762 os << *is;
763 ++is;
764 }
765
766 for (; is != end_shelf; ++is) {
767 os << "\n\n";
768 os << *is;
769 }
770
771 return os;
772}
773
774// Functions for Tensor5View:
775// -------------------------
776
781 const Range& b,
782 const Range& p,
783 const Range& r,
784 const Range& c) {
785 return Tensor5View(mdata, msr, mbr, mpr, mrr, mcr, s, b, p, r, c);
786}
787
791 const Range& s, const Range& b, const Range& p, const Range& r, Index c) {
792 // Check that c is valid:
793 ARTS_ASSERT(0 <= c);
795
796 return Tensor4View(
797 mdata + mcr.mstart + c * mcr.mstride, msr, mbr, mpr, mrr, s, b, p, r);
798}
799
803 const Range& s, const Range& b, const Range& p, Index r, const Range& c) {
804 // Check that r is valid:
805 ARTS_ASSERT(0 <= r);
807
808 return Tensor4View(
809 mdata + mrr.mstart + r * mrr.mstride, msr, mbr, mpr, mcr, s, b, p, c);
810}
811
815 const Range& s, const Range& b, Index p, const Range& r, const Range& c) {
816 // Check that p is valid:
817 ARTS_ASSERT(0 <= p);
819
820 return Tensor4View(
821 mdata + mpr.mstart + p * mpr.mstride, msr, mbr, mrr, mcr, s, b, r, c);
822}
823
827 const Range& s, Index b, const Range& p, const Range& r, const Range& c) {
828 // Check that b is valid:
829 ARTS_ASSERT(0 <= b);
831
832 return Tensor4View(
833 mdata + mbr.mstart + b * mbr.mstride, msr, mpr, mrr, mcr, s, p, r, c);
834}
835
839 Index s, const Range& b, const Range& p, const Range& r, const Range& c) {
840 // Check that s is valid:
841 ARTS_ASSERT(0 <= s);
843
844 return Tensor4View(
845 mdata + msr.mstart + s * msr.mstride, mbr, mpr, mrr, mcr, b, p, r, c);
846}
847
851 const Range& s, const Range& b, const Range& p, Index r, Index c) {
852 // Check that r and c is valid:
853 ARTS_ASSERT(0 <= r);
854 ARTS_ASSERT(0 <= c);
857
858 return Tensor3View(
860 msr,
861 mbr,
862 mpr,
863 s,
864 b,
865 p);
866}
867
871 const Range& s, const Range& b, Index p, const Range& r, Index c) {
872 // Check that p and c are valid:
873 ARTS_ASSERT(0 <= p);
874 ARTS_ASSERT(0 <= c);
877
878 return Tensor3View(
880 msr,
881 mbr,
882 mrr,
883 s,
884 b,
885 r);
886}
887
891 const Range& s, const Range& b, Index p, Index r, const Range& c) {
892 // Check that p and r are valid:
893 ARTS_ASSERT(0 <= p);
894 ARTS_ASSERT(0 <= r);
897
898 return Tensor3View(
899 mdata + mpr.mstart + p * mpr.mstride + mrr.mstart + r * mrr.mstride,
900 msr,
901 mbr,
902 mcr,
903 s,
904 b,
905 c);
906}
907
911 const Range& s, Index b, const Range& p, Index r, const Range& c) {
912 // Check that b and r are valid:
913 ARTS_ASSERT(0 <= b);
914 ARTS_ASSERT(0 <= r);
917
918 return Tensor3View(
920 msr,
921 mpr,
922 mcr,
923 s,
924 p,
925 c);
926}
927
931 const Range& s, Index b, const Range& p, const Range& r, Index c) {
932 // Check that b and c are valid:
933 ARTS_ASSERT(0 <= b);
934 ARTS_ASSERT(0 <= c);
937
938 return Tensor3View(
940 msr,
941 mpr,
942 mrr,
943 s,
944 p,
945 r);
946}
947
951 const Range& s, Index b, Index p, const Range& r, const Range& c) {
952 // Check that b and p are valid:
953 ARTS_ASSERT(0 <= b);
954 ARTS_ASSERT(0 <= p);
957
958 return Tensor3View(
960 msr,
961 mrr,
962 mcr,
963 s,
964 r,
965 c);
966}
967
971 Index s, const Range& b, Index p, const Range& r, const Range& c) {
972 // Check that s and p are valid:
973 ARTS_ASSERT(0 <= s);
974 ARTS_ASSERT(0 <= p);
977
978 return Tensor3View(
979 mdata + msr.mstart + s * msr.mstride + mpr.mstart + p * mpr.mstride,
980 mbr,
981 mrr,
982 mcr,
983 b,
984 r,
985 c);
986}
987
991 Index s, const Range& b, const Range& p, Index r, const Range& c) {
992 // Check that s and r are valid:
993 ARTS_ASSERT(0 <= s);
994 ARTS_ASSERT(0 <= r);
997
998 return Tensor3View(
999 mdata + msr.mstart + s * msr.mstride + mrr.mstart + r * mrr.mstride,
1000 mbr,
1001 mpr,
1002 mcr,
1003 b,
1004 p,
1005 c);
1006}
1007
1011 Index s, const Range& b, const Range& p, const Range& r, Index c) {
1012 // Check that s and c are valid:
1013 ARTS_ASSERT(0 <= s);
1014 ARTS_ASSERT(0 <= c);
1015 ARTS_ASSERT(s < msr.mextent);
1017
1018 return Tensor3View(
1019 mdata + msr.mstart + s * msr.mstride + mcr.mstart + c * mcr.mstride,
1020 mbr,
1021 mpr,
1022 mrr,
1023 b,
1024 p,
1025 r);
1026}
1027
1031 Index s, Index b, const Range& p, const Range& r, const Range& c) {
1032 // Check that s and b are valid:
1033 ARTS_ASSERT(0 <= s);
1034 ARTS_ASSERT(0 <= b);
1035 ARTS_ASSERT(s < msr.mextent);
1037
1038 return Tensor3View(
1039 mdata + msr.mstart + s * msr.mstride + mbr.mstart + b * mbr.mstride,
1040 mpr,
1041 mrr,
1042 mcr,
1043 p,
1044 r,
1045 c);
1046}
1047
1051 const Range& s, const Range& b, Index p, Index r, Index c) {
1052 // Check that p, r and c are valid:
1053 ARTS_ASSERT(0 <= p);
1054 ARTS_ASSERT(0 <= r);
1055 ARTS_ASSERT(0 <= c);
1056 ARTS_ASSERT(p < mpr.mextent);
1057 ARTS_ASSERT(r < mrr.mextent);
1059
1060 return MatrixView(mdata + mpr.mstart + p * mpr.mstride + mrr.mstart +
1061 r * mrr.mstride + mcr.mstart + c * mcr.mstride,
1062 msr,
1063 mbr,
1064 s,
1065 b);
1066}
1067
1071 const Range& s, Index b, const Range& p, Index r, Index c) {
1072 // Check that b, r and c are valid:
1073 ARTS_ASSERT(0 <= b);
1074 ARTS_ASSERT(0 <= r);
1075 ARTS_ASSERT(0 <= c);
1077 ARTS_ASSERT(r < mrr.mextent);
1079
1080 return MatrixView(mdata + mbr.mstart + b * mbr.mstride + mrr.mstart +
1081 r * mpr.mstride + mcr.mstart + c * mcr.mstride,
1082 msr,
1083 mpr,
1084 s,
1085 p);
1086}
1087
1091 const Range& s, Index b, Index p, const Range& r, Index c) {
1092 // Check that b, p and c are valid:
1093 ARTS_ASSERT(0 <= b);
1094 ARTS_ASSERT(0 <= p);
1095 ARTS_ASSERT(0 <= c);
1097 ARTS_ASSERT(p < mpr.mextent);
1099
1100 return MatrixView(mdata + mbr.mstart + b * mbr.mstride + mpr.mstart +
1101 p * mpr.mstride + mcr.mstart + c * mcr.mstride,
1102 msr,
1103 mrr,
1104 s,
1105 r);
1106}
1107
1111 const Range& s, Index b, Index p, Index r, const Range& c) {
1112 // Check that b, p and r are valid:
1113 ARTS_ASSERT(0 <= b);
1114 ARTS_ASSERT(0 <= p);
1115 ARTS_ASSERT(0 <= r);
1117 ARTS_ASSERT(p < mpr.mextent);
1118 ARTS_ASSERT(r < mrr.mextent);
1119
1120 return MatrixView(mdata + mbr.mstart + b * mbr.mstride + mpr.mstart +
1121 p * mpr.mstride + mrr.mstart + r * mrr.mstride,
1122 msr,
1123 mcr,
1124 s,
1125 c);
1126}
1127
1131 Index s, const Range& b, Index p, Index r, const Range& c) {
1132 // Check that s, p and r are valid:
1133 ARTS_ASSERT(0 <= s);
1134 ARTS_ASSERT(0 <= p);
1135 ARTS_ASSERT(0 <= r);
1136 ARTS_ASSERT(s < msr.mextent);
1137 ARTS_ASSERT(p < mpr.mextent);
1138 ARTS_ASSERT(r < mrr.mextent);
1139
1140 return MatrixView(mdata + msr.mstart + s * msr.mstride + mpr.mstart +
1141 p * mpr.mstride + mrr.mstart + r * mrr.mstride,
1142 mbr,
1143 mcr,
1144 b,
1145 c);
1146}
1147
1151 Index s, const Range& b, Index p, const Range& r, Index c) {
1152 // Check that s, p and c are valid:
1153 ARTS_ASSERT(0 <= s);
1154 ARTS_ASSERT(0 <= p);
1155 ARTS_ASSERT(0 <= c);
1156 ARTS_ASSERT(s < msr.mextent);
1157 ARTS_ASSERT(p < mpr.mextent);
1159
1160 return MatrixView(mdata + msr.mstart + s * msr.mstride + mpr.mstart +
1161 p * mpr.mstride + mcr.mstart + c * mcr.mstride,
1162 mbr,
1163 mrr,
1164 b,
1165 r);
1166}
1167
1171 Index s, const Range& b, const Range& p, Index r, Index c) {
1172 // Check that s, r and c are valid:
1173 ARTS_ASSERT(0 <= s);
1174 ARTS_ASSERT(0 <= r);
1175 ARTS_ASSERT(0 <= c);
1176 ARTS_ASSERT(s < msr.mextent);
1177 ARTS_ASSERT(r < mrr.mextent);
1179
1180 return MatrixView(mdata + msr.mstart + s * msr.mstride + mrr.mstart +
1181 r * mrr.mstride + mcr.mstart + c * mcr.mstride,
1182 mbr,
1183 mpr,
1184 b,
1185 p);
1186}
1187
1191 Index s, Index b, const Range& p, const Range& r, Index c) {
1192 // Check that s, b and c are valid:
1193 ARTS_ASSERT(0 <= s);
1194 ARTS_ASSERT(0 <= b);
1195 ARTS_ASSERT(0 <= c);
1196 ARTS_ASSERT(s < msr.mextent);
1199
1200 return MatrixView(mdata + msr.mstart + s * msr.mstride + mbr.mstart +
1201 b * mbr.mstride + mcr.mstart + c * mcr.mstride,
1202 mpr,
1203 mrr,
1204 p,
1205 r);
1206}
1207
1211 Index s, Index b, const Range& p, Index r, const Range& c) {
1212 // Check that s, b and r are valid:
1213 ARTS_ASSERT(0 <= s);
1214 ARTS_ASSERT(0 <= b);
1215 ARTS_ASSERT(0 <= r);
1216 ARTS_ASSERT(s < msr.mextent);
1218 ARTS_ASSERT(r < mrr.mextent);
1219
1220 return MatrixView(mdata + msr.mstart + s * msr.mstride + mbr.mstart +
1221 b * mbr.mstride + mrr.mstart + r * mrr.mstride,
1222 mpr,
1223 mcr,
1224 p,
1225 c);
1226}
1227
1231 Index s, Index b, Index p, const Range& r, const Range& c) {
1232 // Check that s, b and p are valid:
1233 ARTS_ASSERT(0 <= s);
1234 ARTS_ASSERT(0 <= b);
1235 ARTS_ASSERT(0 <= p);
1236 ARTS_ASSERT(s < msr.mextent);
1238 ARTS_ASSERT(p < mpr.mextent);
1239
1240 return MatrixView(mdata + msr.mstart + s * msr.mstride + mbr.mstart +
1241 b * mbr.mstride + mpr.mstart + p * mpr.mstride,
1242 mrr,
1243 mcr,
1244 r,
1245 c);
1246}
1247
1251 const Range& s, Index b, Index p, Index r, Index c) {
1252 // Check that b, p, r and c are valid:
1253 ARTS_ASSERT(0 <= b);
1254 ARTS_ASSERT(0 <= p);
1255 ARTS_ASSERT(0 <= r);
1256 ARTS_ASSERT(0 <= c);
1258 ARTS_ASSERT(p < mpr.mextent);
1259 ARTS_ASSERT(r < mrr.mextent);
1261
1262 return VectorView(mdata + mbr.mstart + b * mbr.mstride + mpr.mstart +
1263 p * mpr.mstride + mrr.mstart + r * mrr.mstride +
1264 mcr.mstart + c * mcr.mstride,
1265 msr,
1266 s);
1267}
1268
1272 Index s, const Range& b, Index p, Index r, Index c) {
1273 // Check that s, p, r and c are valid:
1274 ARTS_ASSERT(0 <= s);
1275 ARTS_ASSERT(0 <= p);
1276 ARTS_ASSERT(0 <= r);
1277 ARTS_ASSERT(0 <= c);
1278 ARTS_ASSERT(s < msr.mextent);
1279 ARTS_ASSERT(p < mpr.mextent);
1280 ARTS_ASSERT(r < mrr.mextent);
1282
1283 return VectorView(mdata + msr.mstart + s * msr.mstride + mpr.mstart +
1284 p * mpr.mstride + mrr.mstart + r * mrr.mstride +
1285 mcr.mstart + c * mcr.mstride,
1286 mbr,
1287 b);
1288}
1289
1293 Index s, Index b, const Range& p, Index r, Index c) {
1294 // Check that s, b, r and c are valid:
1295 ARTS_ASSERT(0 <= s);
1296 ARTS_ASSERT(0 <= b);
1297 ARTS_ASSERT(0 <= r);
1298 ARTS_ASSERT(0 <= c);
1299 ARTS_ASSERT(s < msr.mextent);
1301 ARTS_ASSERT(r < mrr.mextent);
1303
1304 return VectorView(mdata + msr.mstart + s * msr.mstride + mbr.mstart +
1305 b * mbr.mstride + mrr.mstart + r * mrr.mstride +
1306 mcr.mstart + c * mcr.mstride,
1307 mpr,
1308 p);
1309}
1310
1314 Index s, Index b, Index p, const Range& r, Index c) {
1315 // Check that s, b, p and c are valid:
1316 ARTS_ASSERT(0 <= s);
1317 ARTS_ASSERT(0 <= b);
1318 ARTS_ASSERT(0 <= p);
1319 ARTS_ASSERT(0 <= c);
1320 ARTS_ASSERT(s < msr.mextent);
1322 ARTS_ASSERT(p < mpr.mextent);
1324
1325 return VectorView(mdata + msr.mstart + s * msr.mstride + mbr.mstart +
1326 b * mbr.mstride + mpr.mstart + p * mpr.mstride +
1327 mcr.mstart + c * mcr.mstride,
1328 mrr,
1329 r);
1330}
1331
1335 Index s, Index b, Index p, Index r, const Range& c) {
1336 // Check that s, b, p and r are valid:
1337 ARTS_ASSERT(0 <= s);
1338 ARTS_ASSERT(0 <= b);
1339 ARTS_ASSERT(0 <= p);
1340 ARTS_ASSERT(0 <= r);
1341 ARTS_ASSERT(s < msr.mextent);
1343 ARTS_ASSERT(p < mpr.mextent);
1344 ARTS_ASSERT(r < mrr.mextent);
1345
1346 return VectorView(mdata + msr.mstart + s * msr.mstride + mbr.mstart +
1347 b * mbr.mstride + mpr.mstart + p * mpr.mstride +
1348 mrr.mstart + r * mrr.mstride,
1349 mcr,
1350 c);
1351}
1352
1356 msr.mstride);
1357}
1358
1361 return Iterator5D(
1364 msr.mstride);
1365}
1366
1372 // Check that sizes are compatible:
1378
1379 copy(m.begin(), m.end(), begin());
1380 return *this;
1381}
1382
1389 // Check that sizes are compatible:
1395
1396 copy(m.begin(), m.end(), begin());
1397 return *this;
1398}
1399
1404 // Check that sizes are compatible:
1410
1411 copy(m.begin(), m.end(), begin());
1412 return *this;
1413}
1414
1418 copy(x, begin(), end());
1419 return *this;
1420}
1421
1422// Some little helper functions:
1423//------------------------------
1424
1427 const Iterator5D es = end();
1428 for (Iterator5D s = begin(); s != es; ++s) {
1429 *s *= x;
1430 }
1431 return *this;
1432}
1433
1436 const Iterator5D es = end();
1437 for (Iterator5D s = begin(); s != es; ++s) {
1438 *s /= x;
1439 }
1440 return *this;
1441}
1442
1445 const Iterator5D es = end();
1446 for (Iterator5D s = begin(); s != es; ++s) {
1447 *s += x;
1448 }
1449 return *this;
1450}
1451
1454 const Iterator5D es = end();
1455 for (Iterator5D s = begin(); s != es; ++s) {
1456 *s -= x;
1457 }
1458 return *this;
1459}
1460
1463 ARTS_ASSERT(nshelves() == x.nshelves());
1464 ARTS_ASSERT(nbooks() == x.nbooks());
1465 ARTS_ASSERT(npages() == x.npages());
1466 ARTS_ASSERT(nrows() == x.nrows());
1467 ARTS_ASSERT(ncols() == x.ncols());
1468 ConstIterator5D xs = x.begin();
1469 Iterator5D s = begin();
1470 const Iterator5D es = end();
1471 for (; s != es; ++s, ++xs) {
1472 *s *= *xs;
1473 }
1474 return *this;
1475}
1476
1479 ARTS_ASSERT(nshelves() == x.nshelves());
1480 ARTS_ASSERT(nbooks() == x.nbooks());
1481 ARTS_ASSERT(npages() == x.npages());
1482 ARTS_ASSERT(nrows() == x.nrows());
1483 ARTS_ASSERT(ncols() == x.ncols());
1484 ConstIterator5D xs = x.begin();
1485 Iterator5D s = begin();
1486 const Iterator5D es = end();
1487 for (; s != es; ++s, ++xs) {
1488 *s /= *xs;
1489 }
1490 return *this;
1491}
1492
1495 ARTS_ASSERT(nshelves() == x.nshelves());
1496 ARTS_ASSERT(nbooks() == x.nbooks());
1497 ARTS_ASSERT(npages() == x.npages());
1498 ARTS_ASSERT(nrows() == x.nrows());
1499 ARTS_ASSERT(ncols() == x.ncols());
1500 ConstIterator5D xs = x.begin();
1501 Iterator5D s = begin();
1502 const Iterator5D es = end();
1503 for (; s != es; ++s, ++xs) {
1504 *s += *xs;
1505 }
1506 return *this;
1507}
1508
1511 ARTS_ASSERT(nshelves() == x.nshelves());
1512 ARTS_ASSERT(nbooks() == x.nbooks());
1513 ARTS_ASSERT(npages() == x.npages());
1514 ARTS_ASSERT(nrows() == x.nrows());
1515 ARTS_ASSERT(ncols() == x.ncols());
1516 ConstIterator5D xs = x.begin();
1517 Iterator5D s = begin();
1518 const Iterator5D es = end();
1519 for (; s != es; ++s, ++xs) {
1520 *s -= *xs;
1521 }
1522 return *this;
1523}
1524
1528 a.mdata,
1529 Range(0,
1530 1,
1531 a.mbr.mextent * a.mpr.mextent * a.mrr.mextent * a.mcr.mextent),
1532 a.mbr,
1533 a.mpr,
1534 a.mrr,
1535 a.mcr) {
1536 // Nothing to do here.
1537}
1538
1543 const Range& sr,
1544 const Range& br,
1545 const Range& pr,
1546 const Range& rr,
1547 const Range& cr)
1548 : ConstTensor5View(data, sr, br, pr, rr, cr) {
1549 // Nothing to do here.
1550}
1551
1573 const Range& ps,
1574 const Range& pb,
1575 const Range& pp,
1576 const Range& pr,
1577 const Range& pc,
1578 const Range& ns,
1579 const Range& nb,
1580 const Range& np,
1581 const Range& nr,
1582 const Range& nc)
1583 : ConstTensor5View(data, ps, pb, pp, pr, pc, ns, nb, np, nr, nc) {
1584 // Nothing to do here.
1585}
1586
1592 const ConstIterator5D& end,
1593 Iterator5D target) {
1594 for (; origin != end; ++origin, ++target) {
1595 // We use the copy function for the next smaller rank of tensor
1596 // recursively:
1597 copy(origin->begin(), origin->end(), target->begin());
1598 }
1599}
1600
1602void copy(Numeric x, Iterator5D target, const Iterator5D& end) {
1603 for (; target != end; ++target) {
1604 // We use the copy function for the next smaller rank of tensor
1605 // recursively:
1606 copy(x, target->begin(), target->end());
1607 }
1608}
1609
1610// Functions for Tensor5:
1611// ---------------------
1612
1616 : Tensor5View(new Numeric[s * b * p * r * c],
1617 Range(0, s, b * p * r * c),
1618 Range(0, b, p * r * c),
1619 Range(0, p, r * c),
1620 Range(0, r, c),
1621 Range(0, c)) {
1622 // Nothing to do here.
1623}
1624
1627 : Tensor5View(new Numeric[s * b * p * r * c],
1628 Range(0, s, b * p * r * c),
1629 Range(0, b, p * r * c),
1630 Range(0, p, r * c),
1631 Range(0, r, c),
1632 Range(0, c)) {
1633 // Here we can access the raw memory directly, for slightly
1634 // increased efficiency:
1635 std::fill_n(mdata, s * b * p * r * c, fill);
1636}
1637
1641 : Tensor5View(
1642 new Numeric[m.nshelves() * m.nbooks() * m.npages() * m.nrows() *
1643 m.ncols()],
1644 Range(
1645 0, m.nshelves(), m.nbooks() * m.npages() * m.nrows() * m.ncols()),
1646 Range(0, m.nbooks(), m.npages() * m.nrows() * m.ncols()),
1647 Range(0, m.npages(), m.nrows() * m.ncols()),
1648 Range(0, m.nrows(), m.ncols()),
1649 Range(0, m.ncols())) {
1650 copy(m.begin(), m.end(), begin());
1651}
1652
1656 : Tensor5View(
1657 new Numeric[m.nshelves() * m.nbooks() * m.npages() * m.nrows() *
1658 m.ncols()],
1659 Range(
1660 0, m.nshelves(), m.nbooks() * m.npages() * m.nrows() * m.ncols()),
1661 Range(0, m.nbooks(), m.npages() * m.nrows() * m.ncols()),
1662 Range(0, m.npages(), m.nrows() * m.ncols()),
1663 Range(0, m.nrows(), m.ncols()),
1664 Range(0, m.ncols())) {
1665 // There is a catch here: If m is an empty tensor, then it will have
1666 // dimensions of size 0. But these are used to initialize the stride
1667 // for higher dimensions! Thus, this method has to be consistent
1668 // with the behaviour of Range::Range. For now, Range::Range allows
1669 // also stride 0.
1670 std::memcpy(
1671 mdata,
1672 m.mdata,
1673 nshelves() * nbooks() * npages() * nrows() * ncols() * sizeof(Numeric));
1674}
1675
1677
1701 if (this != &x) {
1702 resize(x.nshelves(), x.nbooks(), x.npages(), x.nrows(), x.ncols());
1703 std::memcpy(
1704 mdata,
1705 x.mdata,
1706 nshelves() * nbooks() * npages() * nrows() * ncols() * sizeof(Numeric));
1707 }
1708 return *this;
1709}
1710
1713 if (this != &x) {
1714 delete[] mdata;
1715 mdata = x.mdata;
1716 msr = x.msr;
1717 mbr = x.mbr;
1718 mpr = x.mpr;
1719 mrr = x.mrr;
1720 mcr = x.mcr;
1721 x.msr = Range(0, 0);
1722 x.mbr = Range(0, 0);
1723 x.mpr = Range(0, 0);
1724 x.mrr = Range(0, 0);
1725 x.mcr = Range(0, 0);
1726 x.mdata = nullptr;
1727 }
1728 return *this;
1729}
1730
1734 std::fill_n(mdata, nshelves() * nbooks() * npages() * nrows() * ncols(), x);
1735 return *this;
1736}
1737
1742 ARTS_ASSERT(0 <= s);
1743 ARTS_ASSERT(0 <= b);
1744 ARTS_ASSERT(0 <= p);
1745 ARTS_ASSERT(0 <= r);
1746 ARTS_ASSERT(0 <= c);
1747
1748 if (msr.mextent != s || mbr.mextent != b || mpr.mextent != p ||
1749 mrr.mextent != r || mcr.mextent != c) {
1750 delete[] mdata;
1751 mdata = new Numeric[s * b * p * r * c];
1752
1753 msr.mstart = 0;
1754 msr.mextent = s;
1755 msr.mstride = b * p * r * c;
1756
1757 mbr.mstart = 0;
1758 mbr.mextent = b;
1759 mbr.mstride = p * r * c;
1760
1761 mpr.mstart = 0;
1762 mpr.mextent = p;
1763 mpr.mstride = r * c;
1764
1765 mrr.mstart = 0;
1766 mrr.mextent = r;
1767 mrr.mstride = c;
1768
1769 mcr.mstart = 0;
1770 mcr.mextent = c;
1771 mcr.mstride = 1;
1772 }
1773}
1774
1776void swap(Tensor5& t1, Tensor5& t2) {
1777 std::swap(t1.msr, t2.msr);
1778 std::swap(t1.mbr, t2.mbr);
1779 std::swap(t1.mpr, t2.mpr);
1780 std::swap(t1.mrr, t2.mrr);
1781 std::swap(t1.mcr, t2.mcr);
1782 std::swap(t1.mdata, t2.mdata);
1783}
1784
1788 // cout << "Destroying a Tensor5:\n"
1789 // << *this << "\n........................................\n";
1790 delete[] mdata;
1791}
1792
1808void transform(Tensor5View y, double (&my_func)(double), ConstTensor5View x) {
1809 // Check dimensions:
1810 ARTS_ASSERT(y.nshelves() == x.nshelves());
1811 ARTS_ASSERT(y.nbooks() == x.nbooks());
1812 ARTS_ASSERT(y.npages() == x.npages());
1813 ARTS_ASSERT(y.nrows() == x.nrows());
1814 ARTS_ASSERT(y.ncols() == x.ncols());
1815
1816 const ConstIterator5D xe = x.end();
1817 ConstIterator5D xi = x.begin();
1818 Iterator5D yi = y.begin();
1819 for (; xi != xe; ++xi, ++yi) {
1820 // Use the transform function of lower dimensional tensors
1821 // recursively:
1822 transform(*yi, my_func, *xi);
1823 }
1824}
1825
1828 const ConstIterator5D xe = x.end();
1829 ConstIterator5D xi = x.begin();
1830
1831 // Initial value for max:
1832 Numeric themax = max(*xi);
1833 ++xi;
1834
1835 for (; xi != xe; ++xi) {
1836 // Use the max function of lower dimensional tensors
1837 // recursively:
1838 Numeric maxi = max(*xi);
1839 if (maxi > themax) themax = maxi;
1840 }
1841
1842 return themax;
1843}
1844
1847 const ConstIterator5D xe = x.end();
1848 ConstIterator5D xi = x.begin();
1849
1850 // Initial value for min:
1851 Numeric themin = min(*xi);
1852 ++xi;
1853
1854 for (; xi != xe; ++xi) {
1855 // Use the min function of lower dimensional tensors
1856 // recursively:
1857 Numeric mini = min(*xi);
1858 if (mini < themin) themin = mini;
1859 }
1860
1861 return themin;
1862}
1863
1865// Helper function for debugging
1866#ifndef NDEBUG
1867
1885 Tensor5View& tv, Index s, Index b, Index p, Index r, Index c) {
1886 return tv(s, b, p, r, c);
1887}
1888
1889#endif
Index nrows
Index nbooks
Index npages
void * data
Index nshelves
Index ncols
Const version of Iterator5D.
Definition: matpackV.h:85
A constant view of a Matrix.
Definition: matpackI.h:1014
A constant view of a Tensor3.
Definition: matpackIII.h:132
A constant view of a Tensor4.
Definition: matpackIV.h:133
ConstIterator4D end() const
Return const iterator behind last book.
Definition: matpackIV.cc:371
ConstIterator4D begin() const
Return const iterator to first book.
Definition: matpackIV.cc:365
A constant view of a Tensor5.
Definition: matpackV.h:143
Index ncols() const
Returns the number of columns.
Definition: matpackV.cc:56
Index nshelves() const
Returns the number of shelves.
Definition: matpackV.cc:44
ConstTensor5View operator()(const Range &s, const Range &b, const Range &p, const Range &r, const Range &c) const
Const index operator for subrange.
Definition: matpackV.cc:61
Range mpr
The page range of mdata that is actually used.
Definition: matpackV.h:315
Range mcr
The column range of mdata that is actually used.
Definition: matpackV.h:319
ConstTensor5View()=default
Numeric * mdata
Pointer to the plain C array that holds the data.
Definition: matpackV.h:321
ConstIterator5D end() const
Return const iterator behind last shelf.
Definition: matpackV.cc:694
Range mbr
The book range of mdata that is actually used.
Definition: matpackV.h:313
Range msr
The shelf range of mdata that is actually used.
Definition: matpackV.h:311
Range mrr
The row range of mdata that is actually used.
Definition: matpackV.h:317
Index npages() const
Returns the number of pages.
Definition: matpackV.cc:50
Index nrows() const
Returns the number of rows.
Definition: matpackV.cc:53
bool empty() const
Check if variable is empty.
Definition: matpackV.cc:38
ConstIterator5D begin() const
Return const iterator to first shelf.
Definition: matpackV.cc:688
Index nbooks() const
Returns the number of books.
Definition: matpackV.cc:47
A constant view of a Vector.
Definition: matpackI.h:489
Implementation of Tensors of Rank 5.
Definition: matpackV.h:38
The MatrixView class.
Definition: matpackI.h:1125
The range class.
Definition: matpackI.h:165
Index mstart
The start index.
Definition: matpackI.h:351
Index mstride
The stride.
Definition: matpackI.h:360
Index mextent
The number of elements.
Definition: matpackI.h:358
The Tensor3View class.
Definition: matpackIII.h:239
The Tensor4View class.
Definition: matpackIV.h:284
Iterator4D begin()
Return iterator to first book.
Definition: matpackIV.cc:700
Iterator4D end()
Return iterator behind last book.
Definition: matpackIV.cc:706
The Tensor5View class.
Definition: matpackV.h:333
Tensor5View & operator*=(Numeric x)
Multiplication by scalar.
Definition: matpackV.cc:1426
const Numeric * get_c_array() const ARTS_NOEXCEPT
Conversion to plain C-array.
Definition: matpackV.cc:674
Iterator5D end()
Return iterator behind last shelf.
Definition: matpackV.cc:1360
Tensor5View & operator-=(Numeric x)
Subtraction of scalar.
Definition: matpackV.cc:1453
Tensor5View & operator/=(Numeric x)
Division by scalar.
Definition: matpackV.cc:1435
Tensor5View operator()(const Range &s, const Range &b, const Range &p, const Range &r, const Range &c)
Index operator for subrange.
Definition: matpackV.cc:780
Iterator5D begin()
Return iterator to first shelf.
Definition: matpackV.cc:1354
Tensor5View()=default
Tensor5View & operator+=(Numeric x)
Addition of scalar.
Definition: matpackV.cc:1444
Tensor5View & operator=(const ConstTensor5View &v)
Assignment operator.
Definition: matpackV.cc:1371
The Tensor5 class.
Definition: matpackV.h:506
virtual ~Tensor5()
Destructor for Tensor5.
Definition: matpackV.cc:1787
void resize(Index s, Index b, Index p, Index r, Index c)
Resize function.
Definition: matpackV.cc:1741
Tensor5()=default
Tensor5 & operator=(const Tensor5 &x)
Assignment operator from another tensor.
Definition: matpackV.cc:1700
The VectorView class.
Definition: matpackI.h:626
#define ARTS_NOEXCEPT
Definition: debug.h:80
#define ARTS_ASSERT(condition,...)
Definition: debug.h:83
The declarations of all the exception classes.
#define ns
Numeric max(const ConstTensor5View &x)
Max function, tensor version.
Definition: matpackV.cc:1827
void copy(ConstIterator5D origin, const ConstIterator5D &end, Iterator5D target)
Copy data between begin and end to target.
Definition: matpackV.cc:1591
void transform(Tensor5View y, double(&my_func)(double), ConstTensor5View x)
A generic transform function for tensors, which can be used to implement mathematical functions opera...
Definition: matpackV.cc:1808
Numeric debug_tensor5view_get_elem(Tensor5View &tv, Index s, Index b, Index p, Index r, Index c)
Helper function to access tensor elements.
Definition: matpackV.cc:1884
Numeric min(const ConstTensor5View &x)
Min function, tensor version.
Definition: matpackV.cc:1846
void swap(Tensor5 &t1, Tensor5 &t2)
Swaps two objects.
Definition: matpackV.cc:1776
std::ostream & operator<<(std::ostream &os, const ConstTensor5View &v)
Output operator.
Definition: matpackV.cc:756
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:33
constexpr Rational end(Rational Ju, Rational Jl, Polarization type) noexcept
Gives the largest M for a polarization type of this transition.
Definition: zeemandata.h:109
#define v
#define a
#define c
#define b