ARTS  2.4.0(git:4fb77825)
matpackIV.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 "matpackIV.h"
26 #include "exceptions.h"
27 
28 using std::runtime_error;
29 
33 
36 
40 
43 
44 // Functions for ConstTensor4View:
45 // ------------------------------
46 
48 
53  return (nbooks() == 0 || npages() == 0 || nrows() == 0 || ncols() == 0);
54 }
55 
58 
61 
64 
67 
72  const Range& p,
73  const Range& r,
74  const Range& c) const {
75  return ConstTensor4View(mdata, mbr, mpr, mrr, mcr, b, p, r, c);
76 }
77 
81  const Range& p,
82  const Range& r,
83  Index c) const {
84  // Check that c is valid:
85  assert(0 <= c);
86  assert(c < mcr.mextent);
87 
88  return ConstTensor3View(
89  mdata + mcr.mstart + c * mcr.mstride, mbr, mpr, mrr, b, p, r);
90 }
91 
95  const Range& p,
96  Index r,
97  const Range& c) const {
98  // Check that r is valid:
99  assert(0 <= r);
100  assert(r < mrr.mextent);
101 
102  return ConstTensor3View(
103  mdata + mrr.mstart + r * mrr.mstride, mbr, mpr, mcr, b, p, c);
104 }
105 
109  Index p,
110  const Range& r,
111  const Range& c) const {
112  // Check that p is valid:
113  assert(0 <= p);
114  assert(p < mpr.mextent);
115 
116  return ConstTensor3View(
117  mdata + mpr.mstart + p * mpr.mstride, mbr, mrr, mcr, b, r, c);
118 }
119 
123  const Range& p,
124  const Range& r,
125  const Range& c) const {
126  // Check that b is valid:
127  assert(0 <= b);
128  assert(b < mbr.mextent);
129 
130  return ConstTensor3View(
131  mdata + mbr.mstart + b * mbr.mstride, mpr, mrr, mcr, p, r, c);
132 }
133 
137  const Range& p,
138  Index r,
139  Index c) const {
140  // Check that r and c are valid:
141  assert(0 <= r);
142  assert(0 <= c);
143  assert(r < mrr.mextent);
144  assert(c < mcr.mextent);
145 
146  return ConstMatrixView(
147  mdata + mrr.mstart + r * mrr.mstride + mcr.mstart + c * mcr.mstride,
148  mbr,
149  mpr,
150  b,
151  p);
152 }
153 
157  Index p,
158  const Range& r,
159  Index c) const {
160  // Check that p and c are valid:
161  assert(0 <= p);
162  assert(0 <= c);
163  assert(p < mpr.mextent);
164  assert(c < mcr.mextent);
165 
166  return ConstMatrixView(
167  mdata + mpr.mstart + p * mpr.mstride + mcr.mstart + c * mcr.mstride,
168  mbr,
169  mrr,
170  b,
171  r);
172 }
173 
177  Index p,
178  Index r,
179  const Range& c) const {
180  // Check that p and r are valid:
181  assert(0 <= p);
182  assert(0 <= r);
183  assert(p < mpr.mextent);
184  assert(r < mrr.mextent);
185 
186  return ConstMatrixView(
187  mdata + mpr.mstart + p * mpr.mstride + mrr.mstart + r * mrr.mstride,
188  mbr,
189  mcr,
190  b,
191  c);
192 }
193 
197  const Range& p,
198  Index r,
199  const Range& c) const {
200  // Check that b and r are valid:
201  assert(0 <= b);
202  assert(0 <= r);
203  assert(b < mbr.mextent);
204  assert(r < mrr.mextent);
205 
206  return ConstMatrixView(
207  mdata + mbr.mstart + b * mbr.mstride + mrr.mstart + r * mrr.mstride,
208  mpr,
209  mcr,
210  p,
211  c);
212 }
213 
217  const Range& p,
218  const Range& r,
219  Index c) const {
220  // Check that b and c are valid:
221  assert(0 <= b);
222  assert(0 <= c);
223  assert(b < mbr.mextent);
224  assert(c < mcr.mextent);
225 
226  return ConstMatrixView(
229  mrr,
230  p,
231  r);
232 }
233 
237  Index p,
238  const Range& r,
239  const Range& c) const {
240  // Check that b and p are valid:
241  assert(0 <= b);
242  assert(0 <= p);
243  assert(b < mbr.mextent);
244  assert(p < mpr.mextent);
245 
246  return ConstMatrixView(
247  mdata + mbr.mstart + b * mbr.mstride + mpr.mstart + p * mpr.mstride,
248  mrr,
249  mcr,
250  r,
251  c);
252 }
253 
257  Index p,
258  Index r,
259  Index c) const {
260  // Check that p, r and c are valid:
261  assert(0 <= p);
262  assert(0 <= r);
263  assert(0 <= c);
264  assert(p < mpr.mextent);
265  assert(r < mrr.mextent);
266  assert(c < mcr.mextent);
267 
268  return ConstVectorView(mdata + mpr.mstart + p * mpr.mstride + mrr.mstart +
269  r * mrr.mstride + mcr.mstart + c * mcr.mstride,
270  mbr,
271  b);
272 }
273 
277  const Range& p,
278  Index r,
279  Index c) const {
280  // Check that b, r and c are valid:
281  assert(0 <= b);
282  assert(0 <= r);
283  assert(0 <= c);
284  assert(b < mbr.mextent);
285  assert(r < mrr.mextent);
286  assert(c < mcr.mextent);
287 
288  return ConstVectorView(mdata + mbr.mstart + b * mbr.mstride + mrr.mstart +
289  r * mrr.mstride + mcr.mstart + c * mcr.mstride,
290  mpr,
291  p);
292 }
293 
297  Index p,
298  const Range& r,
299  Index c) const {
300  // Check that b, p and c are valid:
301  assert(0 <= b);
302  assert(0 <= p);
303  assert(0 <= c);
304  assert(b < mbr.mextent);
305  assert(p < mpr.mextent);
306  assert(c < mcr.mextent);
307 
308  return ConstVectorView(mdata + mbr.mstart + b * mbr.mstride + mpr.mstart +
309  p * mpr.mstride + mcr.mstart + c * mcr.mstride,
310  mrr,
311  r);
312 }
313 
317  Index p,
318  Index r,
319  const Range& c) const {
320  // Check that b, p and r are valid:
321  assert(0 <= b);
322  assert(0 <= p);
323  assert(0 <= r);
324  assert(b < mbr.mextent);
325  assert(p < mpr.mextent);
326  assert(r < mrr.mextent);
327 
328  return ConstVectorView(mdata + mbr.mstart + b * mbr.mstride + mpr.mstart +
329  p * mpr.mstride + mrr.mstart + r * mrr.mstride,
330  mcr,
331  c);
332 }
333 
341  if (mbr.mstart != 0 ||
343  mpr.mstart != 0 || mpr.mstride != mrr.mextent * mcr.mextent ||
344  mrr.mstart != 0 || mrr.mstride != mcr.mextent || mcr.mstart != 0 ||
345  mcr.mstride != 1)
346  throw std::runtime_error(
347  "A Tensor4View can only be converted to a plain C-array if it's pointing to a continuous block of data");
348 
349  return mdata;
350 }
351 
359  if (mbr.mstart != 0 ||
361  mpr.mstart != 0 || mpr.mstride != mrr.mextent * mcr.mextent ||
362  mrr.mstart != 0 || mrr.mstride != mcr.mextent || mcr.mstart != 0 ||
363  mcr.mstride != 1)
364  throw std::runtime_error(
365  "A Tensor4View can only be converted to a plain C-array if it's pointing to a continuous block of data");
366 
367  return mdata;
368 }
369 
373  mbr.mstride);
374 }
375 
378  return ConstIterator4D(
380  mdata + mbr.mstart + (mbr.mextent) * mbr.mstride, mpr, mrr, mcr),
381  mbr.mstride);
382 }
383 
386  : mbr(0, 1, a.mpr.mextent * a.mrr.mextent * a.mcr.mextent),
387  mpr(a.mpr),
388  mrr(a.mrr),
389  mcr(a.mcr),
390  mdata(a.mdata) {
391  // Nothing to do here.
392 }
393 
399  const Range& br,
400  const Range& pr,
401  const Range& rr,
402  const Range& cr)
403  : mbr(br), mpr(pr), mrr(rr), mcr(cr), mdata(data) {
404  // Nothing to do here.
405 }
406 
415  const Range& pb,
416  const Range& pp,
417  const Range& pr,
418  const Range& pc,
419  const Range& nb,
420  const Range& np,
421  const Range& nr,
422  const Range& nc)
423  : mbr(pb, nb), mpr(pp, np), mrr(pr, nr), mcr(pc, nc), mdata(data) {
424  // Nothing to do here.
425 }
426 
430 std::ostream& operator<<(std::ostream& os, const ConstTensor4View& v) {
431  // Page iterators:
432  ConstIterator4D ib = v.begin();
433  const ConstIterator4D end_book = v.end();
434 
435  if (ib != end_book) {
436  os << *ib;
437  ++ib;
438  }
439 
440  for (; ib != end_book; ++ib) {
441  os << "\n\n";
442  os << *ib;
443  }
444 
445  return os;
446 }
447 
448 // Functions for Tensor4View:
449 // -------------------------
450 
455  const Range& p,
456  const Range& r,
457  const Range& c) {
458  return Tensor4View(mdata, mbr, mpr, mrr, mcr, b, p, r, c);
459 }
460 
464  const Range& p,
465  const Range& r,
466  Index c) {
467  // Check that c is valid:
468  assert(0 <= c);
469  assert(c < mcr.mextent);
470 
471  return Tensor3View(
472  mdata + mcr.mstart + c * mcr.mstride, mbr, mpr, mrr, b, p, r);
473 }
474 
478  const Range& p,
479  Index r,
480  const Range& c) {
481  // Check that r is valid:
482  assert(0 <= r);
483  assert(r < mrr.mextent);
484 
485  return Tensor3View(
486  mdata + mrr.mstart + r * mrr.mstride, mbr, mpr, mcr, b, p, c);
487 }
488 
492  Index p,
493  const Range& r,
494  const Range& c) {
495  // Check that p is valid:
496  assert(0 <= p);
497  assert(p < mpr.mextent);
498 
499  return Tensor3View(
500  mdata + mpr.mstart + p * mpr.mstride, mbr, mrr, mcr, b, r, c);
501 }
502 
506  const Range& p,
507  const Range& r,
508  const Range& c) {
509  // Check that b is valid:
510  assert(0 <= b);
511  assert(b < mbr.mextent);
512 
513  return Tensor3View(
514  mdata + mbr.mstart + b * mbr.mstride, mpr, mrr, mcr, p, r, c);
515 }
516 
520  const Range& p,
521  Index r,
522  Index c) {
523  // Check that r and c are valid:
524  assert(0 <= r);
525  assert(0 <= c);
526  assert(r < mrr.mextent);
527  assert(c < mcr.mextent);
528 
529  return MatrixView(
530  mdata + mrr.mstart + r * mrr.mstride + mcr.mstart + c * mcr.mstride,
531  mbr,
532  mpr,
533  b,
534  p);
535 }
536 
540  Index p,
541  const Range& r,
542  Index c) {
543  // Check that p and c are valid:
544  assert(0 <= p);
545  assert(0 <= c);
546  assert(p < mpr.mextent);
547  assert(c < mcr.mextent);
548 
549  return MatrixView(
550  mdata + mpr.mstart + p * mpr.mstride + mcr.mstart + c * mcr.mstride,
551  mbr,
552  mrr,
553  b,
554  r);
555 }
556 
560  Index p,
561  Index r,
562  const Range& c) {
563  // Check that p and r are valid:
564  assert(0 <= p);
565  assert(0 <= r);
566  assert(p < mpr.mextent);
567  assert(r < mrr.mextent);
568 
569  return MatrixView(
570  mdata + mpr.mstart + p * mpr.mstride + mrr.mstart + r * mrr.mstride,
571  mbr,
572  mcr,
573  b,
574  c);
575 }
576 
580  const Range& p,
581  Index r,
582  const Range& c) {
583  // Check that b and r are valid:
584  assert(0 <= b);
585  assert(0 <= r);
586  assert(b < mbr.mextent);
587  assert(r < mrr.mextent);
588 
589  return MatrixView(
590  mdata + mbr.mstart + b * mbr.mstride + mrr.mstart + r * mrr.mstride,
591  mpr,
592  mcr,
593  p,
594  c);
595 }
596 
600  const Range& p,
601  const Range& r,
602  Index c) {
603  // Check that b and c are valid:
604  assert(0 <= b);
605  assert(0 <= c);
606  assert(b < mbr.mextent);
607  assert(c < mcr.mextent);
608 
609  return MatrixView(
610  mdata + mbr.mstart + b * mbr.mstride + mcr.mstart + c * mcr.mstride,
611  mpr,
612  mrr,
613  p,
614  r);
615 }
616 
620  Index p,
621  const Range& r,
622  const Range& c) {
623  // Check that b and p are valid:
624  assert(0 <= b);
625  assert(0 <= p);
626  assert(b < mbr.mextent);
627  assert(p < mpr.mextent);
628 
629  return MatrixView(
630  mdata + mbr.mstart + b * mbr.mstride + mpr.mstart + p * mpr.mstride,
631  mrr,
632  mcr,
633  r,
634  c);
635 }
636 
640  // Check that p, r and c are valid:
641  assert(0 <= p);
642  assert(0 <= r);
643  assert(0 <= c);
644  assert(p < mpr.mextent);
645  assert(r < mrr.mextent);
646  assert(c < mcr.mextent);
647 
648  return VectorView(mdata + mpr.mstart + p * mpr.mstride + mrr.mstart +
649  r * mrr.mstride + mcr.mstart + c * mcr.mstride,
650  mbr,
651  b);
652 }
653 
657  // Check that b, r and c are valid:
658  assert(0 <= b);
659  assert(0 <= r);
660  assert(0 <= c);
661  assert(b < mbr.mextent);
662  assert(r < mrr.mextent);
663  assert(c < mcr.mextent);
664 
665  return VectorView(mdata + mbr.mstart + b * mbr.mstride + mrr.mstart +
666  r * mrr.mstride + mcr.mstart + c * mcr.mstride,
667  mpr,
668  p);
669 }
670 
674  // Check that b, p and c are valid:
675  assert(0 <= b);
676  assert(0 <= p);
677  assert(0 <= c);
678  assert(b < mbr.mextent);
679  assert(p < mpr.mextent);
680  assert(c < mcr.mextent);
681 
682  return VectorView(mdata + mbr.mstart + b * mbr.mstride + mpr.mstart +
683  p * mpr.mstride + mcr.mstart + c * mcr.mstride,
684  mrr,
685  r);
686 }
687 
691  // Check that b, p and r are valid:
692  assert(0 <= b);
693  assert(0 <= p);
694  assert(0 <= r);
695  assert(b < mbr.mextent);
696  assert(p < mpr.mextent);
697  assert(r < mrr.mextent);
698 
699  return VectorView(mdata + mbr.mstart + b * mbr.mstride + mpr.mstart +
700  p * mpr.mstride + mrr.mstart + r * mrr.mstride,
701  mcr,
702  c);
703 }
704 
708  mbr.mstride);
709 }
710 
713  return Iterator4D(
714  Tensor3View(
715  mdata + mbr.mstart + (mbr.mextent) * mbr.mstride, mpr, mrr, mcr),
716  mbr.mstride);
717 }
718 
724  // Check that sizes are compatible:
725  assert(mbr.mextent == m.mbr.mextent);
726  assert(mpr.mextent == m.mpr.mextent);
727  assert(mrr.mextent == m.mrr.mextent);
728  assert(mcr.mextent == m.mcr.mextent);
729 
730  copy(m.begin(), m.end(), begin());
731  return *this;
732 }
733 
740  // Check that sizes are compatible:
741  assert(mbr.mextent == m.mbr.mextent);
742  assert(mpr.mextent == m.mpr.mextent);
743  assert(mrr.mextent == m.mrr.mextent);
744  assert(mcr.mextent == m.mcr.mextent);
745 
746  copy(m.begin(), m.end(), begin());
747  return *this;
748 }
749 
754  // Check that sizes are compatible:
755  assert(mbr.mextent == m.mbr.mextent);
756  assert(mpr.mextent == m.mpr.mextent);
757  assert(mrr.mextent == m.mrr.mextent);
758  assert(mcr.mextent == m.mcr.mextent);
759 
760  copy(m.begin(), m.end(), begin());
761  return *this;
762 }
763 
767  copy(x, begin(), end());
768  return *this;
769 }
770 
771 // Some little helper functions:
772 //------------------------------
773 
776  const Iterator4D eb = end();
777  for (Iterator4D b = begin(); b != eb; ++b) {
778  *b *= x;
779  }
780  return *this;
781 }
782 
785  const Iterator4D eb = end();
786  for (Iterator4D b = begin(); b != eb; ++b) {
787  *b /= x;
788  }
789  return *this;
790 }
791 
794  const Iterator4D eb = end();
795  for (Iterator4D b = begin(); b != eb; ++b) {
796  *b += x;
797  }
798  return *this;
799 }
800 
803  const Iterator4D eb = end();
804  for (Iterator4D b = begin(); b != eb; ++b) {
805  *b -= x;
806  }
807  return *this;
808 }
809 
812  assert(nbooks() == x.nbooks());
813  assert(npages() == x.npages());
814  assert(nrows() == x.nrows());
815  assert(ncols() == x.ncols());
816  ConstIterator4D xb = x.begin();
817  Iterator4D b = begin();
818  const Iterator4D eb = end();
819  for (; b != eb; ++b, ++xb) {
820  *b *= *xb;
821  }
822  return *this;
823 }
824 
827  assert(nbooks() == x.nbooks());
828  assert(npages() == x.npages());
829  assert(nrows() == x.nrows());
830  assert(ncols() == x.ncols());
831  ConstIterator4D xb = x.begin();
832  Iterator4D b = begin();
833  const Iterator4D eb = end();
834  for (; b != eb; ++b, ++xb) {
835  *b /= *xb;
836  }
837  return *this;
838 }
839 
842  assert(nbooks() == x.nbooks());
843  assert(npages() == x.npages());
844  assert(nrows() == x.nrows());
845  assert(ncols() == x.ncols());
846  ConstIterator4D xb = x.begin();
847  Iterator4D b = begin();
848  const Iterator4D eb = end();
849  for (; b != eb; ++b, ++xb) {
850  *b += *xb;
851  }
852  return *this;
853 }
854 
857  assert(nbooks() == x.nbooks());
858  assert(npages() == x.npages());
859  assert(nrows() == x.nrows());
860  assert(ncols() == x.ncols());
861  ConstIterator4D xb = x.begin();
862  Iterator4D b = begin();
863  const Iterator4D eb = end();
864  for (; b != eb; ++b, ++xb) {
865  *b -= *xb;
866  }
867  return *this;
868 }
869 
873  a.mdata,
874  Range(0, 1, a.mpr.mextent * a.mrr.mextent * a.mcr.mextent),
875  a.mpr,
876  a.mrr,
877  a.mcr) {
878  // Nothing to do here.
879 }
880 
885  const Range& br,
886  const Range& pr,
887  const Range& rr,
888  const Range& cr)
889  : ConstTensor4View(data, br, pr, rr, cr) {
890  // Nothing to do here.
891 }
892 
912  const Range& pb,
913  const Range& pp,
914  const Range& pr,
915  const Range& pc,
916  const Range& nb,
917  const Range& np,
918  const Range& nr,
919  const Range& nc)
920  : ConstTensor4View(data, pb, pp, pr, pc, nb, np, nr, nc) {
921  // Nothing to do here.
922 }
923 
928 void copy(ConstIterator4D origin,
929  const ConstIterator4D& end,
930  Iterator4D target) {
931  for (; origin != end; ++origin, ++target) {
932  // We use the copy function for the next smaller rank of tensor
933  // recursively:
934  copy(origin->begin(), origin->end(), target->begin());
935  }
936 }
937 
939 void copy(Numeric x, Iterator4D target, const Iterator4D& end) {
940  for (; target != end; ++target) {
941  // We use the copy function for the next smaller rank of tensor
942  // recursively:
943  copy(x, target->begin(), target->end());
944  }
945 }
946 
947 // Functions for Tensor4:
948 // ---------------------
949 
953  : Tensor4View(new Numeric[b * p * r * c],
954  Range(0, b, p * r * c),
955  Range(0, p, r * c),
956  Range(0, r, c),
957  Range(0, c)) {
958  // Nothing to do here.
959 }
960 
963  : Tensor4View(new Numeric[b * p * r * c],
964  Range(0, b, p * r * c),
965  Range(0, p, r * c),
966  Range(0, r, c),
967  Range(0, c)) {
968  // Here we can access the raw memory directly, for slightly
969  // increased efficiency:
970  std::fill_n(mdata, b * p * r * c, fill);
971 }
972 
976  : Tensor4View(new Numeric[m.nbooks() * m.npages() * m.nrows() * m.ncols()],
977  Range(0, m.nbooks(), m.npages() * m.nrows() * m.ncols()),
978  Range(0, m.npages(), m.nrows() * m.ncols()),
979  Range(0, m.nrows(), m.ncols()),
980  Range(0, m.ncols())) {
981  copy(m.begin(), m.end(), begin());
982 }
983 
987  : Tensor4View(new Numeric[m.nbooks() * m.npages() * m.nrows() * m.ncols()],
988  Range(0, m.nbooks(), m.npages() * m.nrows() * m.ncols()),
989  Range(0, m.npages(), m.nrows() * m.ncols()),
990  Range(0, m.nrows(), m.ncols()),
991  Range(0, m.ncols())) {
992  // There is a catch here: If m is an empty tensor, then it will have
993  // dimensions of size 0. But these are used to initialize the stride
994  // for higher dimensions! Thus, this method has to be consistent
995  // with the behaviour of Range::Range. For now, Range::Range allows
996  // also stride 0.
997  std::memcpy(mdata,
998  m.mdata,
999  nbooks() * npages() * nrows() * ncols() * sizeof(Numeric));
1000 }
1001 
1003 
1027  if (this != &x) {
1028  resize(x.nbooks(), x.npages(), x.nrows(), x.ncols());
1029  std::memcpy(mdata,
1030  x.mdata,
1031  nbooks() * npages() * nrows() * ncols() * sizeof(Numeric));
1032  }
1033  return *this;
1034 }
1035 
1038  if (this != &x) {
1039  delete[] mdata;
1040  mdata = x.mdata;
1041  mbr = x.mbr;
1042  mpr = x.mpr;
1043  mrr = x.mrr;
1044  mcr = x.mcr;
1045  x.mbr = Range(0, 0);
1046  x.mpr = Range(0, 0);
1047  x.mrr = Range(0, 0);
1048  x.mcr = Range(0, 0);
1049  x.mdata = nullptr;
1050  }
1051  return *this;
1052 }
1053 
1057  std::fill_n(mdata, nbooks() * npages() * nrows() * ncols(), x);
1058  return *this;
1059 }
1060 
1065  assert(0 <= b);
1066  assert(0 <= p);
1067  assert(0 <= r);
1068  assert(0 <= c);
1069 
1070  if (mbr.mextent != b || mpr.mextent != p || mrr.mextent != r ||
1071  mcr.mextent != c) {
1072  delete[] mdata;
1073  mdata = new Numeric[b * p * r * c];
1074 
1075  mbr.mstart = 0;
1076  mbr.mextent = b;
1077  mbr.mstride = p * r * c;
1078 
1079  mpr.mstart = 0;
1080  mpr.mextent = p;
1081  mpr.mstride = r * c;
1082 
1083  mrr.mstart = 0;
1084  mrr.mextent = r;
1085  mrr.mstride = c;
1086 
1087  mcr.mstart = 0;
1088  mcr.mextent = c;
1089  mcr.mstride = 1;
1090  }
1091 }
1092 
1094 void swap(Tensor4& t1, Tensor4& t2) {
1095  std::swap(t1.mbr, t2.mbr);
1096  std::swap(t1.mpr, t2.mpr);
1097  std::swap(t1.mrr, t2.mrr);
1098  std::swap(t1.mcr, t2.mcr);
1099  std::swap(t1.mdata, t2.mdata);
1100 }
1101 
1105  // cout << "Destroying a Tensor4:\n"
1106  // << *this << "\n........................................\n";
1107  delete[] mdata;
1108 }
1109 
1125 void transform(Tensor4View y, double (&my_func)(double), ConstTensor4View x) {
1126  // Check dimensions:
1127  assert(y.nbooks() == x.nbooks());
1128  assert(y.npages() == x.npages());
1129  assert(y.nrows() == x.nrows());
1130  assert(y.ncols() == x.ncols());
1131 
1132  const ConstIterator4D xe = x.end();
1133  ConstIterator4D xi = x.begin();
1134  Iterator4D yi = y.begin();
1135  for (; xi != xe; ++xi, ++yi) {
1136  // Use the transform function of lower dimensional tensors
1137  // recursively:
1138  transform(*yi, my_func, *xi);
1139  }
1140 }
1141 
1144  const ConstIterator4D xe = x.end();
1145  ConstIterator4D xi = x.begin();
1146 
1147  // Initial value for max:
1148  Numeric themax = max(*xi);
1149  ++xi;
1150 
1151  for (; xi != xe; ++xi) {
1152  // Use the max function of lower dimensional tensors
1153  // recursively:
1154  Numeric maxi = max(*xi);
1155  if (maxi > themax) themax = maxi;
1156  }
1157 
1158  return themax;
1159 }
1160 
1163  const ConstIterator4D xe = x.end();
1164  ConstIterator4D xi = x.begin();
1165 
1166  // Initial value for min:
1167  Numeric themin = min(*xi);
1168  ++xi;
1169 
1170  for (; xi != xe; ++xi) {
1171  // Use the min function of lower dimensional tensors
1172  // recursively:
1173  Numeric mini = min(*xi);
1174  if (mini < themin) themin = mini;
1175  }
1176 
1177  return themin;
1178 }
1179 
1181 // Helper function for debugging
1182 #ifndef NDEBUG
1183 
1200  Tensor4View& tv, Index b, Index p, Index r, Index c) {
1201  return tv(b, p, r, c);
1202 }
1203 
1204 #endif
1205 
Tensor4::resize
void resize(Index b, Index p, Index r, Index c)
Resize function.
Definition: matpackIV.cc:1064
ConstTensor4View::mpr
Range mpr
The page range of mdata that is actually used.
Definition: matpackIV.h:266
MatrixView
The MatrixView class.
Definition: matpackI.h:1093
exceptions.h
The declarations of all the exception classes.
ConstTensor4View::end
ConstIterator4D end() const
Return const iterator behind last book.
Definition: matpackIV.cc:377
swap
void swap(Tensor4 &t1, Tensor4 &t2)
Swaps two objects.
Definition: matpackIV.cc:1094
min
Numeric min(const ConstTensor4View &x)
Min function, tensor version.
Definition: matpackIV.cc:1162
transform
void transform(Tensor4View y, double(&my_func)(double), ConstTensor4View x)
A generic transform function for tensors, which can be used to implement mathematical functions opera...
Definition: matpackIV.cc:1125
ConstTensor4View::ConstTensor4View
ConstTensor4View()=default
Tensor4View::operator*=
Tensor4View & operator*=(Numeric x)
Multiplication by scalar.
Definition: matpackIV.cc:775
Tensor4View::Tensor4View
Tensor4View()=default
ARTS::Var::y
Vector y(Workspace &ws) noexcept
Definition: autoarts.h:7401
ConstTensor4View::mbr
Range mbr
The book range of mdata that is actually used.
Definition: matpackIV.h:264
ConstTensor4View::operator()
ConstTensor4View operator()(const Range &b, const Range &p, const Range &r, const Range &c) const
Const index operator for subrange.
Definition: matpackIV.cc:71
ConstTensor4View::mcr
Range mcr
The column range of mdata that is actually used.
Definition: matpackIV.h:270
data
G0 G2 FVC Y DV Numeric Numeric Numeric Zeeman LowerQuantumNumbers void * data
Definition: arts_api_classes.cc:232
Tensor4::~Tensor4
virtual ~Tensor4()
Destructor for Tensor4.
Definition: matpackIV.cc:1104
Tensor4::operator=
Tensor4 & operator=(const Tensor4 &x)
Assignment operator from another tensor.
Definition: matpackIV.cc:1026
Range::mstart
Index mstart
The start index.
Definition: matpackI.h:346
Tensor4
The Tensor4 class.
Definition: matpackIV.h:421
Tensor3View::end
Iterator3D end()
Return iterator behind last page.
Definition: matpackIII.cc:337
Tensor4View::begin
Iterator4D begin()
Return iterator to first book.
Definition: matpackIV.cc:706
matpackIV.h
Iterator4D::operator->
Tensor3View * operator->()
The -> operator is needed, so that we can write i->begin() to get the 3D iterators.
Definition: matpackIV.cc:32
ConstIterator4D
Const version of Iterator4D.
Definition: matpackIV.h:77
ConstTensor4View
A constant view of a Tensor4.
Definition: matpackIV.h:133
Tensor3View
The Tensor3View class.
Definition: matpackIII.h:239
Tensor4View::operator+=
Tensor4View & operator+=(Numeric x)
Addition of scalar.
Definition: matpackIV.cc:793
ConstIterator4D::operator->
const ConstTensor3View * operator->() const
The -> operator is needed, so that we can write i->begin() to get the 3D iterators.
Definition: matpackIV.cc:39
ConstTensor3View::begin
ConstIterator3D begin() const
Return const iterator to first page.
Definition: matpackIII.cc:139
Tensor3View::begin
Iterator3D begin()
Return iterator to first page.
Definition: matpackIII.cc:332
Tensor4::Tensor4
Tensor4()=default
ConstTensor4View::empty
bool empty() const
Check if variable is empty.
Definition: matpackIV.cc:52
debug_tensor4view_get_elem
Numeric debug_tensor4view_get_elem(Tensor4View &tv, Index b, Index p, Index r, Index c)
Helper function to access tensor elements.
Definition: matpackIV.cc:1199
operator<<
std::ostream & operator<<(std::ostream &os, const ConstTensor4View &v)
Output operator.
Definition: matpackIV.cc:430
VectorView
The VectorView class.
Definition: matpackI.h:610
ConstTensor4View::ncols
Index ncols() const
Returns the number of columns.
Definition: matpackIV.cc:66
ConstTensor4View::begin
ConstIterator4D begin() const
Return const iterator to first book.
Definition: matpackIV.cc:371
Numeric
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:33
ConstTensor4View::npages
Index npages() const
Returns the number of pages.
Definition: matpackIV.cc:60
ConstTensor4View::nbooks
Index nbooks() const
Returns the number of books.
Definition: matpackIV.cc:57
ARTS::Var::npages
Index npages(Workspace &ws) noexcept
Definition: autoarts.h:4675
Tensor4View::operator=
Tensor4View & operator=(const ConstTensor4View &v)
Assignment operator.
Definition: matpackIV.cc:723
Iterator4D::msv
Tensor3View msv
Current position.
Definition: matpackIV.h:71
Tensor4View::operator/=
Tensor4View & operator/=(Numeric x)
Division by scalar.
Definition: matpackIV.cc:784
Tensor4View::end
Iterator4D end()
Return iterator behind last book.
Definition: matpackIV.cc:712
Zeeman::end
constexpr Rational end(Rational Ju, Rational Jl, Polarization type) noexcept
Gives the largest M for a polarization type of this transition.
Definition: zeemandata.h:108
eb
#define eb
Definition: legacy_continua.cc:22185
ConstMatrixView
A constant view of a Matrix.
Definition: matpackI.h:982
ARTS::Var::nrows
Index nrows(Workspace &ws) noexcept
Definition: autoarts.h:4682
ConstTensor4View::nrows
Index nrows() const
Returns the number of rows.
Definition: matpackIV.cc:63
ConstTensor3View::end
ConstIterator3D end() const
Return const iterator behind last page.
Definition: matpackIII.cc:145
ConstIterator4D::operator*
const ConstTensor3View & operator*() const
Dereferencing.
Definition: matpackIV.cc:42
Range
The range class.
Definition: matpackI.h:160
Range::mextent
Index mextent
The number of elements.
Definition: matpackI.h:353
Iterator4D::operator*
Tensor3View & operator*()
Dereferencing.
Definition: matpackIV.cc:35
Iterator4D
Implementation of Tensors of Rank 4.
Definition: matpackIV.h:38
copy
void copy(ConstIterator4D origin, const ConstIterator4D &end, Iterator4D target)
Copy data between begin and end to target.
Definition: matpackIV.cc:928
ConstTensor4View::mrr
Range mrr
The row range of mdata that is actually used.
Definition: matpackIV.h:268
ConstTensor3View
A constant view of a Tensor3.
Definition: matpackIII.h:132
Tensor4View
The Tensor4View class.
Definition: matpackIV.h:284
ConstIterator4D::msv
ConstTensor3View msv
Current position.
Definition: matpackIV.h:113
Tensor4View::operator-=
Tensor4View & operator-=(Numeric x)
Subtraction of scalar.
Definition: matpackIV.cc:802
ARTS::Var::x
Vector x(Workspace &ws) noexcept
Definition: autoarts.h:7346
Index
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
Tensor4View::operator()
Tensor4View operator()(const Range &b, const Range &p, const Range &r, const Range &c)
Index operator for subrange.
Definition: matpackIV.cc:454
max
Numeric max(const ConstTensor4View &x)
Max function, tensor version.
Definition: matpackIV.cc:1143
ARTS::Var::ncols
Index ncols(Workspace &ws) noexcept
Definition: autoarts.h:4546
Range::mstride
Index mstride
The stride.
Definition: matpackI.h:355
ConstVectorView
A constant view of a Vector.
Definition: matpackI.h:476
Tensor4View::get_c_array
const Numeric * get_c_array() const
Conversion to plain C-array.
Definition: matpackIV.cc:358
ConstTensor4View::mdata
Numeric * mdata
Pointer to the plain C array that holds the data.
Definition: matpackIV.h:272
ARTS::Var::nbooks
Index nbooks(Workspace &ws) noexcept
Definition: autoarts.h:4539