ARTS  2.2.66
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 
28 using std::runtime_error;
29 
30 
31 // Functions for ConstTensor5View:
32 // ------------------------------
33 
36 {
37  return msr.mextent;
38 }
39 
42 {
43  return mbr.mextent;
44 }
45 
48 {
49  return mpr.mextent;
50 }
51 
54 {
55  return mrr.mextent;
56 }
57 
60 {
61  return mcr.mextent;
62 }
63 
68  const Range& b,
69  const Range& p,
70  const Range& r,
71  const Range& c) const
72 {
73  return ConstTensor5View(mdata,
74  msr, mbr, mpr, mrr, mcr,
75  s, b, p, r, c);
76 }
77 
81  const Range& b,
82  const Range& p,
83  const Range& r,
84  Index c ) const
85 {
86  // Check that c is valid:
87  assert( 0 <= c );
88  assert( c < mcr.mextent );
89 
90  return ConstTensor4View(mdata +
91  mcr.mstart + c * mcr.mstride,
92  msr, mbr, mpr, mrr,
93  s, b, p, r);
94 }
95 
99  const Range& b,
100  const Range& p,
101  Index r,
102  const Range& c) const
103 {
104  // Check that r is valid:
105  assert( 0 <= r );
106  assert( r < mrr.mextent );
107 
108  return ConstTensor4View(mdata +
109  mrr.mstart + r * mrr.mstride,
110  msr, mbr, mpr, mcr,
111  s, b, p, c);
112 }
113 
117  const Range& b,
118  Index p,
119  const Range& r,
120  const Range& c) const
121 {
122  // Check that p is valid:
123  assert( 0 <= p );
124  assert( p < mpr.mextent );
125 
126  return ConstTensor4View(mdata +
127  mpr.mstart + p * mpr.mstride,
128  msr, mbr, mrr, mcr,
129  s, b, r, c);
130 }
131 
135  Index b,
136  const Range& p,
137  const Range& r,
138  const Range& c) const
139 {
140  // Check that b is valid:
141  assert( 0 <= b );
142  assert( b < mbr.mextent );
143 
144  return ConstTensor4View(mdata +
145  mbr.mstart + b * mbr.mstride,
146  msr, mpr, mrr, mcr,
147  s, p, r, c);
148 }
149 
153  const Range& b,
154  const Range& p,
155  const Range& r,
156  const Range& c) const
157 {
158  // Check that s is valid:
159  assert( 0 <= s );
160  assert( s < msr.mextent );
161 
162  return ConstTensor4View(mdata +
163  msr.mstart + s * msr.mstride,
164  mbr, mpr, mrr, mcr,
165  b, p, r, c);
166 }
167 
171  const Range& b,
172  const Range& p,
173  Index r,
174  Index c ) const
175 {
176  // Check that r and c is valid:
177  assert( 0 <= r );
178  assert( 0 <= c );
179  assert( r < mrr.mextent );
180  assert( c < mcr.mextent );
181 
182  return ConstTensor3View(mdata +
183  mrr.mstart + r * mrr.mstride +
184  mcr.mstart + c * mcr.mstride,
185  msr, mbr, mpr,
186  s, b, p);
187 }
188 
192  const Range& b,
193  Index p,
194  const Range& r,
195  Index c ) const
196 {
197  // Check that p and c are valid:
198  assert( 0 <= p );
199  assert( 0 <= c );
200  assert( p < mpr.mextent );
201  assert( c < mcr.mextent );
202 
203  return ConstTensor3View(mdata +
204  mpr.mstart + p * mpr.mstride +
205  mcr.mstart + c * mcr.mstride,
206  msr, mbr, mrr,
207  s, b, r);
208 }
209 
213  const Range& b,
214  Index p,
215  Index r,
216  const Range& c) const
217 {
218  // Check that p and r are valid:
219  assert( 0 <= p );
220  assert( 0 <= r );
221  assert( p < mpr.mextent );
222  assert( r < mrr.mextent );
223 
224  return ConstTensor3View(mdata +
225  mpr.mstart + p * mpr.mstride +
226  mrr.mstart + r * mrr.mstride,
227  msr, mbr, mcr,
228  s, b, c);
229 }
230 
234  Index b,
235  const Range& p,
236  Index r,
237  const Range& c) const
238 {
239  // Check that b and r are valid:
240  assert( 0 <= b );
241  assert( 0 <= r );
242  assert( b < mbr.mextent );
243  assert( r < mrr.mextent );
244 
245  return ConstTensor3View(mdata +
246  mbr.mstart + b * mbr.mstride +
247  mrr.mstart + r * mrr.mstride,
248  msr, mpr, mcr,
249  s, p, c);
250 }
251 
255  Index b,
256  const Range& p,
257  const Range& r,
258  Index c ) const
259 {
260  // Check that b and c are valid:
261  assert( 0 <= b );
262  assert( 0 <= c );
263  assert( b < mbr.mextent );
264  assert( c < mcr.mextent );
265 
266  return ConstTensor3View(mdata +
267  mbr.mstart + b * mbr.mstride +
268  mcr.mstart + c * mcr.mstride,
269  msr, mpr, mrr,
270  s, p, r);
271 }
272 
276  Index b,
277  Index p,
278  const Range& r,
279  const Range& c) const
280 {
281  // Check that b and p are valid:
282  assert( 0 <= b );
283  assert( 0 <= p );
284  assert( b < mbr.mextent );
285  assert( p < mpr.mextent );
286 
287  return ConstTensor3View(mdata +
288  mbr.mstart + b * mbr.mstride +
289  mpr.mstart + p * mpr.mstride,
290  msr, mrr, mcr,
291  s, r, c);
292 }
293 
297  const Range& b,
298  Index p,
299  const Range& r,
300  const Range& c) const
301 {
302  // Check that s and p are valid:
303  assert( 0 <= s );
304  assert( 0 <= p );
305  assert( s < msr.mextent );
306  assert( p < mpr.mextent );
307 
308  return ConstTensor3View(mdata +
309  msr.mstart + s * msr.mstride +
310  mpr.mstart + p * mpr.mstride,
311  mbr, mrr, mcr,
312  b, r, c);
313 }
314 
318  const Range& b,
319  const Range& p,
320  Index r,
321  const Range& c) const
322 {
323  // Check that s and r are valid:
324  assert( 0 <= s );
325  assert( 0 <= r );
326  assert( s < msr.mextent );
327  assert( r < mrr.mextent );
328 
329  return ConstTensor3View(mdata +
330  msr.mstart + s * msr.mstride +
331  mrr.mstart + r * mrr.mstride,
332  mbr, mpr, mcr,
333  b, p, c);
334 }
335 
339  const Range& b,
340  const Range& p,
341  const Range& r,
342  Index c ) const
343 {
344  // Check that s and c are valid:
345  assert( 0 <= s );
346  assert( 0 <= c );
347  assert( s < msr.mextent );
348  assert( c < mcr.mextent );
349 
350  return ConstTensor3View(mdata +
351  msr.mstart + s * msr.mstride +
352  mcr.mstart + c * mcr.mstride,
353  mbr, mpr, mrr,
354  b, p, r);
355 }
356 
360  Index b,
361  const Range& p,
362  const Range& r,
363  const Range& c) const
364 {
365  // Check that s and b are valid:
366  assert( 0 <= s );
367  assert( 0 <= b );
368  assert( s < msr.mextent );
369  assert( b < mbr.mextent );
370 
371  return ConstTensor3View(mdata +
372  msr.mstart + s * msr.mstride +
373  mbr.mstart + b * mbr.mstride,
374  mpr, mrr, mcr,
375  p, r, c);
376 }
377 
381  const Range& b,
382  Index p,
383  Index r,
384  Index c ) const
385 {
386  // Check that p, r and c are valid:
387  assert( 0 <= p );
388  assert( 0 <= r );
389  assert( 0 <= c );
390  assert( p < mpr.mextent );
391  assert( r < mrr.mextent );
392  assert( c < mcr.mextent );
393 
394  return ConstMatrixView(mdata +
395  mpr.mstart + p * mpr.mstride +
396  mrr.mstart + r * mrr.mstride +
397  mcr.mstart + c * mcr.mstride,
398  msr, mbr,
399  s, b);
400 }
401 
405  Index b,
406  const Range& p,
407  Index r,
408  Index c ) const
409 {
410  // Check that b, r and c are valid:
411  assert( 0 <= b );
412  assert( 0 <= r );
413  assert( 0 <= c );
414  assert( b < mbr.mextent );
415  assert( r < mrr.mextent );
416  assert( c < mcr.mextent );
417 
418  return ConstMatrixView(mdata +
419  mbr.mstart + b * mbr.mstride +
420  mrr.mstart + r * mpr.mstride +
421  mcr.mstart + c * mcr.mstride,
422  msr, mpr,
423  s, p);
424 }
425 
429  Index b,
430  Index p,
431  const Range& r,
432  Index c ) const
433 {
434  // Check that b, p and c are valid:
435  assert( 0 <= b );
436  assert( 0 <= p );
437  assert( 0 <= c );
438  assert( b < mbr.mextent );
439  assert( p < mpr.mextent );
440  assert( c < mcr.mextent );
441 
442  return ConstMatrixView(mdata +
443  mbr.mstart + b * mbr.mstride +
444  mpr.mstart + p * mpr.mstride +
445  mcr.mstart + c * mcr.mstride,
446  msr, mrr,
447  s, r);
448 }
449 
453  Index b,
454  Index p,
455  Index r,
456  const Range& c) const
457 {
458  // Check that b, p and r are valid:
459  assert( 0 <= b );
460  assert( 0 <= p );
461  assert( 0 <= r );
462  assert( b < mbr.mextent );
463  assert( p < mpr.mextent );
464  assert( r < mrr.mextent );
465 
466  return ConstMatrixView(mdata +
467  mbr.mstart + b * mbr.mstride +
468  mpr.mstart + p * mpr.mstride +
469  mrr.mstart + r * mrr.mstride,
470  msr, mcr,
471  s, c);
472 }
473 
477  const Range& b,
478  Index p,
479  Index r,
480  const Range& c) const
481 {
482  // Check that s, p and r are valid:
483  assert( 0 <= s );
484  assert( 0 <= p );
485  assert( 0 <= r );
486  assert( s < msr.mextent );
487  assert( p < mpr.mextent );
488  assert( r < mrr.mextent );
489 
490  return ConstMatrixView(mdata +
491  msr.mstart + s * msr.mstride +
492  mpr.mstart + p * mpr.mstride +
493  mrr.mstart + r * mrr.mstride,
494  mbr, mcr,
495  b, c);
496 }
497 
501  const Range& b,
502  Index p,
503  const Range& r,
504  Index c ) const
505 {
506  // Check that s, p and c are valid:
507  assert( 0 <= s );
508  assert( 0 <= p );
509  assert( 0 <= c );
510  assert( s < msr.mextent );
511  assert( p < mpr.mextent );
512  assert( c < mcr.mextent );
513 
514  return ConstMatrixView(mdata +
515  msr.mstart + s * msr.mstride +
516  mpr.mstart + p * mpr.mstride +
517  mcr.mstart + c * mcr.mstride,
518  mbr, mrr,
519  b, r);
520 }
521 
525  const Range& b,
526  const Range& p,
527  Index r,
528  Index c ) const
529 {
530  // Check that s, r and c are valid:
531  assert( 0 <= s );
532  assert( 0 <= r );
533  assert( 0 <= c );
534  assert( s < msr.mextent );
535  assert( r < mrr.mextent );
536  assert( c < mcr.mextent );
537 
538  return ConstMatrixView(mdata +
539  msr.mstart + s * msr.mstride +
540  mrr.mstart + r * mrr.mstride +
541  mcr.mstart + c * mcr.mstride,
542  mbr, mpr,
543  b, p);
544 }
545 
549  Index b,
550  const Range& p,
551  const Range& r,
552  Index c ) const
553 {
554  // Check that s, b and c are valid:
555  assert( 0 <= s );
556  assert( 0 <= b );
557  assert( 0 <= c );
558  assert( s < msr.mextent );
559  assert( b < mbr.mextent );
560  assert( c < mcr.mextent );
561 
562  return ConstMatrixView(mdata +
563  msr.mstart + s * msr.mstride +
564  mbr.mstart + b * mbr.mstride +
565  mcr.mstart + c * mcr.mstride,
566  mpr, mrr,
567  p, r);
568 }
569 
573  Index b,
574  const Range& p,
575  Index r,
576  const Range& c) const
577 {
578  // Check that s, b and r are valid:
579  assert( 0 <= s );
580  assert( 0 <= b );
581  assert( 0 <= r );
582  assert( s < msr.mextent );
583  assert( b < mbr.mextent );
584  assert( r < mrr.mextent );
585 
586  return ConstMatrixView(mdata +
587  msr.mstart + s * msr.mstride +
588  mbr.mstart + b * mbr.mstride +
589  mrr.mstart + r * mrr.mstride,
590  mpr, mcr,
591  p, c);
592 }
593 
597  Index b,
598  Index p,
599  const Range& r,
600  const Range& c) const
601 {
602  // Check that s, b and p are valid:
603  assert( 0 <= s );
604  assert( 0 <= b );
605  assert( 0 <= p );
606  assert( s < msr.mextent );
607  assert( b < mbr.mextent );
608  assert( p < mpr.mextent );
609 
610  return ConstMatrixView(mdata +
611  msr.mstart + s * msr.mstride +
612  mbr.mstart + b * mbr.mstride +
613  mpr.mstart + p * mpr.mstride,
614  mrr, mcr,
615  r, c);
616 }
617 
621  Index b,
622  Index p,
623  Index r,
624  Index c ) const
625 {
626  // Check that b, p, r and c are valid:
627  assert( 0 <= b );
628  assert( 0 <= p );
629  assert( 0 <= r );
630  assert( 0 <= c );
631  assert( b < mbr.mextent );
632  assert( p < mpr.mextent );
633  assert( r < mrr.mextent );
634  assert( c < mcr.mextent );
635 
636  return ConstVectorView(mdata +
637  mbr.mstart + b * mbr.mstride +
638  mpr.mstart + p * mpr.mstride +
639  mrr.mstart + r * mrr.mstride +
640  mcr.mstart + c * mcr.mstride,
641  msr,
642  s);
643 }
644 
648  const Range& b,
649  Index p,
650  Index r,
651  Index c ) const
652 {
653  // Check that s, p, r and c are valid:
654  assert( 0 <= s );
655  assert( 0 <= p );
656  assert( 0 <= r );
657  assert( 0 <= c );
658  assert( s < msr.mextent );
659  assert( p < mpr.mextent );
660  assert( r < mrr.mextent );
661  assert( c < mcr.mextent );
662 
663  return ConstVectorView(mdata +
664  msr.mstart + s * msr.mstride +
665  mpr.mstart + p * mpr.mstride +
666  mrr.mstart + r * mrr.mstride +
667  mcr.mstart + c * mcr.mstride,
668  mbr,
669  b);
670 }
671 
675  Index b,
676  const Range& p,
677  Index r,
678  Index c ) const
679 {
680  // Check that s, b, r and c are valid:
681  assert( 0 <= s );
682  assert( 0 <= b );
683  assert( 0 <= r );
684  assert( 0 <= c );
685  assert( s < msr.mextent );
686  assert( b < mbr.mextent );
687  assert( r < mrr.mextent );
688  assert( c < mcr.mextent );
689 
690  return ConstVectorView(mdata +
691  msr.mstart + s * msr.mstride +
692  mbr.mstart + b * mbr.mstride +
693  mrr.mstart + r * mrr.mstride +
694  mcr.mstart + c * mcr.mstride,
695  mpr,
696  p);
697 }
698 
702  Index b,
703  Index p,
704  const Range& r,
705  Index c ) const
706 {
707  // Check that s, b, p and c are valid:
708  assert( 0 <= s );
709  assert( 0 <= b );
710  assert( 0 <= p );
711  assert( 0 <= c );
712  assert( s < msr.mextent );
713  assert( b < mbr.mextent );
714  assert( p < mpr.mextent );
715  assert( c < mcr.mextent );
716 
717  return ConstVectorView(mdata +
718  msr.mstart + s * msr.mstride +
719  mbr.mstart + b * mbr.mstride +
720  mpr.mstart + p * mpr.mstride +
721  mcr.mstart + c * mcr.mstride,
722  mrr,
723  r);
724 }
725 
729  Index b,
730  Index p,
731  Index r,
732  const Range& c) const
733 {
734  // Check that s, b, p and r are valid:
735  assert( 0 <= s );
736  assert( 0 <= b );
737  assert( 0 <= p );
738  assert( 0 <= r );
739  assert( s < msr.mextent );
740  assert( b < mbr.mextent );
741  assert( p < mpr.mextent );
742  assert( r < mrr.mextent );
743 
744  return ConstVectorView(mdata +
745  msr.mstart + s * msr.mstride +
746  mbr.mstart + b * mbr.mstride +
747  mpr.mstart + p * mpr.mstride +
748  mrr.mstart + r * mrr.mstride,
749  mcr,
750  c);
751 }
752 
753 
761 {
763  || mbr.mstart != 0 || mbr.mstride != mpr.mextent * mrr.mextent * mcr.mextent
764  || mpr.mstart != 0 || mpr.mstride != mrr.mextent * mcr.mextent
765  || mrr.mstart != 0 || mrr.mstride != mcr.mextent
766  || mcr.mstart != 0 || mcr.mstride != 1)
767  throw std::runtime_error("A Tensor5View can only be converted to a plain C-array if it's pointing to a continuous block of data");
768 
769  return mdata;
770 }
771 
779 {
781  || mbr.mstart != 0 || mbr.mstride != mpr.mextent * mrr.mextent * mcr.mextent
782  || mpr.mstart != 0 || mpr.mstride != mrr.mextent * mcr.mextent
783  || mrr.mstart != 0 || mrr.mstride != mcr.mextent
784  || mcr.mstart != 0 || mcr.mstride != 1)
785  throw std::runtime_error("A Tensor5View can only be converted to a plain C-array if it's pointing to a continuous block of data");
786 
787  return mdata;
788 }
789 
790 
793 {
795  mbr, mpr, mrr, mcr),
796  msr.mstride );
797 }
798 
801 {
803  (msr.mextent) * msr.mstride,
804  mbr, mpr, mrr, mcr),
805  msr.mstride );
806 }
807 
810  msr(0,1,
811  a.mbr.mextent*
812  a.mpr.mextent*
813  a.mrr.mextent*
814  a.mcr.mextent),
815  mbr(a.mbr),
816  mpr(a.mpr),
817  mrr(a.mrr),
818  mcr(a.mcr),
819  mdata(a.mdata)
820 {
821  // Nothing to do here.
822 }
823 
827  msr(0,0,1),
828  mbr(0,0,1),
829  mpr(0,0,1),
830  mrr(0,0,1),
831  mcr(0,0,1),
832  mdata(NULL)
833 {
834  // Nothing to do here.
835 }
836 
842  const Range& sr,
843  const Range& br,
844  const Range& pr,
845  const Range& rr,
846  const Range& cr) :
847  msr(sr),
848  mbr(br),
849  mpr(pr),
850  mrr(rr),
851  mcr(cr),
852  mdata(data)
853 {
854  // Nothing to do here.
855 }
856 
865  const Range& ps,
866  const Range& pb,
867  const Range& pp,
868  const Range& pr,
869  const Range& pc,
870  const Range& ns,
871  const Range& nb,
872  const Range& np,
873  const Range& nr,
874  const Range& nc) :
875  msr(ps,ns),
876  mbr(pb,nb),
877  mpr(pp,np),
878  mrr(pr,nr),
879  mcr(pc,nc),
880  mdata(data)
881 {
882  // Nothing to do here.
883 }
884 
888 std::ostream& operator<<(std::ostream& os, const ConstTensor5View& v)
889 {
890  // Page iterators:
891  ConstIterator5D is = v.begin();
892  const ConstIterator5D end_shelf = v.end();
893 
894  if ( is != end_shelf ) {
895  os << *is;
896  ++is;
897  }
898 
899  for ( ; is != end_shelf; ++is ) {
900  os << "\n\n";
901  os << *is;
902  }
903 
904  return os;
905 }
906 
907 
908 // Functions for Tensor5View:
909 // -------------------------
910 
916  const Range& b,
917  const Range& p,
918  const Range& r,
919  const Range& c) const
920 {
921  return ConstTensor5View::operator()(s,b,p,r,c);
922 }
923 
929  const Range& b,
930  const Range& p,
931  const Range& r,
932  Index c ) const
933 {
934  return ConstTensor5View::operator()(s,b,p,r,c);
935 }
936 
942  const Range& b,
943  const Range& p,
944  Index r,
945  const Range& c) const
946 {
947  return ConstTensor5View::operator()(s,b,p,r,c);
948 }
949 
955  const Range& b,
956  Index p,
957  const Range& r,
958  const Range& c) const
959 {
960  return ConstTensor5View::operator()(s,b,p,r,c);
961 }
962 
968  Index b,
969  const Range& p,
970  const Range& r,
971  const Range& c) const
972 {
973  return ConstTensor5View::operator()(s,b,p,r,c);
974 }
975 
981  const Range& b,
982  const Range& p,
983  const Range& r,
984  const Range& c) const
985 {
986  return ConstTensor5View::operator()(s,b,p,r,c);
987 }
988 
994  const Range& b,
995  const Range& p,
996  Index r,
997  Index c ) const
998 {
999  return ConstTensor5View::operator()(s,b,p,r,c);
1000 }
1001 
1007  const Range& b,
1008  Index p,
1009  const Range& r,
1010  Index c ) const
1011 {
1012  return ConstTensor5View::operator()(s,b,p,r,c);
1013 }
1014 
1020  const Range& b,
1021  Index p,
1022  Index r,
1023  const Range& c) const
1024 {
1025  return ConstTensor5View::operator()(s,b,p,r,c);
1026 }
1027 
1033  Index b,
1034  const Range& p,
1035  Index r,
1036  const Range& c) const
1037 {
1038  return ConstTensor5View::operator()(s,b,p,r,c);
1039 }
1040 
1046  Index b,
1047  const Range& p,
1048  const Range& r,
1049  Index c ) const
1050 {
1051  return ConstTensor5View::operator()(s,b,p,r,c);
1052 }
1053 
1059  Index b,
1060  Index p,
1061  const Range& r,
1062  const Range& c) const
1063 {
1064  return ConstTensor5View::operator()(s,b,p,r,c);
1065 }
1066 
1072  const Range& b,
1073  Index p,
1074  const Range& r,
1075  const Range& c) const
1076 {
1077  return ConstTensor5View::operator()(s,b,p,r,c);
1078 }
1079 
1085  const Range& b,
1086  const Range& p,
1087  Index r,
1088  const Range& c) const
1089 {
1090  return ConstTensor5View::operator()(s,b,p,r,c);
1091 }
1092 
1098  const Range& b,
1099  const Range& p,
1100  const Range& r,
1101  Index c ) const
1102 {
1103  return ConstTensor5View::operator()(s,b,p,r,c);
1104 }
1105 
1111  Index b,
1112  const Range& p,
1113  const Range& r,
1114  const Range& c) const
1115 {
1116  return ConstTensor5View::operator()(s,b,p,r,c);
1117 }
1118 
1124  const Range& b,
1125  Index p,
1126  Index r,
1127  Index c ) const
1128 {
1129  return ConstTensor5View::operator()(s,b,p,r,c);
1130 }
1131 
1137  Index b,
1138  const Range& p,
1139  Index r,
1140  Index c ) const
1141 {
1142  return ConstTensor5View::operator()(s,b,p,r,c);
1143 }
1144 
1150  Index b,
1151  Index p,
1152  const Range& r,
1153  Index c ) const
1154 {
1155  return ConstTensor5View::operator()(s,b,p,r,c);
1156 }
1157 
1163  Index b,
1164  Index p,
1165  Index r,
1166  const Range& c) const
1167 {
1168  return ConstTensor5View::operator()(s,b,p,r,c);
1169 }
1170 
1176  const Range& b,
1177  Index p,
1178  Index r,
1179  const Range& c) const
1180 {
1181  return ConstTensor5View::operator()(s,b,p,r,c);
1182 }
1183 
1189  const Range& b,
1190  Index p,
1191  const Range& r,
1192  Index c ) const
1193 {
1194  return ConstTensor5View::operator()(s,b,p,r,c);
1195 }
1196 
1202  const Range& b,
1203  const Range& p,
1204  Index r,
1205  Index c ) const
1206 {
1207  return ConstTensor5View::operator()(s,b,p,r,c);
1208 }
1209 
1215  Index b,
1216  const Range& p,
1217  const Range& r,
1218  Index c ) const
1219 {
1220  return ConstTensor5View::operator()(s,b,p,r,c);
1221 }
1222 
1228  Index b,
1229  const Range& p,
1230  Index r,
1231  const Range& c) const
1232 {
1233  return ConstTensor5View::operator()(s,b,p,r,c);
1234 }
1235 
1241  Index b,
1242  Index p,
1243  const Range& r,
1244  const Range& c) const
1245 {
1246  return ConstTensor5View::operator()(s,b,p,r,c);
1247 }
1248 
1254  Index b,
1255  Index p,
1256  Index r,
1257  Index c ) const
1258 {
1259  return ConstTensor5View::operator()(s,b,p,r,c);
1260 }
1261 
1267  const Range& b,
1268  Index p,
1269  Index r,
1270  Index c ) const
1271 {
1272  return ConstTensor5View::operator()(s,b,p,r,c);
1273 }
1274 
1280  Index b,
1281  const Range& p,
1282  Index r,
1283  Index c ) const
1284 {
1285  return ConstTensor5View::operator()(s,b,p,r,c);
1286 }
1287 
1293  Index b,
1294  Index p,
1295  const Range& r,
1296  Index c ) const
1297 {
1298  return ConstTensor5View::operator()(s,b,p,r,c);
1299 }
1300 
1306  Index b,
1307  Index p,
1308  Index r,
1309  const Range& c) const
1310 {
1311  return ConstTensor5View::operator()(s,b,p,r,c);
1312 }
1313 
1318  const Range& b,
1319  const Range& p,
1320  const Range& r,
1321  const Range& c)
1322 {
1323  return Tensor5View(mdata,
1324  msr, mbr, mpr, mrr, mcr,
1325  s, b, p, r, c);
1326 }
1327 
1331  const Range& b,
1332  const Range& p,
1333  const Range& r,
1334  Index c)
1335 {
1336  // Check that c is valid:
1337  assert( 0 <= c );
1338  assert( c < mcr.mextent );
1339 
1340  return Tensor4View(mdata +
1341  mcr.mstart + c * mcr.mstride,
1342  msr, mbr, mpr, mrr,
1343  s, b, p, r);
1344 }
1345 
1349  const Range& b,
1350  const Range& p,
1351  Index r,
1352  const Range& c)
1353 {
1354  // Check that r is valid:
1355  assert( 0 <= r );
1356  assert( r < mrr.mextent );
1357 
1358  return Tensor4View(mdata +
1359  mrr.mstart + r * mrr.mstride,
1360  msr, mbr, mpr, mcr,
1361  s, b, p, c);
1362 }
1363 
1367  const Range& b,
1368  Index p,
1369  const Range& r,
1370  const Range& c)
1371 {
1372  // Check that p is valid:
1373  assert( 0 <= p );
1374  assert( p < mpr.mextent );
1375 
1376  return Tensor4View(mdata +
1377  mpr.mstart + p * mpr.mstride,
1378  msr, mbr, mrr, mcr,
1379  s, b, r, c);
1380 }
1381 
1385  Index b,
1386  const Range& p,
1387  const Range& r,
1388  const Range& c)
1389 {
1390  // Check that b is valid:
1391  assert( 0 <= b );
1392  assert( b < mbr.mextent );
1393 
1394  return Tensor4View(mdata +
1395  mbr.mstart + b * mbr.mstride,
1396  msr, mpr, mrr, mcr,
1397  s, p, r, c);
1398 }
1399 
1403  const Range& b,
1404  const Range& p,
1405  const Range& r,
1406  const Range& c)
1407 {
1408  // Check that s is valid:
1409  assert( 0 <= s );
1410  assert( s < msr.mextent );
1411 
1412  return Tensor4View(mdata +
1413  msr.mstart + s * msr.mstride,
1414  mbr, mpr, mrr, mcr,
1415  b, p, r, c);
1416 }
1417 
1421  const Range& b,
1422  const Range& p,
1423  Index r,
1424  Index c)
1425 {
1426  // Check that r and c is valid:
1427  assert( 0 <= r );
1428  assert( 0 <= c );
1429  assert( r < mrr.mextent );
1430  assert( c < mcr.mextent );
1431 
1432  return Tensor3View(mdata +
1433  mrr.mstart + r * mrr.mstride +
1434  mcr.mstart + c * mcr.mstride,
1435  msr, mbr, mpr,
1436  s, b, p);
1437 }
1438 
1442  const Range& b,
1443  Index p,
1444  const Range& r,
1445  Index c)
1446 {
1447  // Check that p and c are valid:
1448  assert( 0 <= p );
1449  assert( 0 <= c );
1450  assert( p < mpr.mextent );
1451  assert( c < mcr.mextent );
1452 
1453  return Tensor3View(mdata +
1454  mpr.mstart + p * mpr.mstride +
1455  mcr.mstart + c * mcr.mstride,
1456  msr, mbr, mrr,
1457  s, b, r);
1458 }
1459 
1463  const Range& b,
1464  Index p,
1465  Index r,
1466  const Range& c)
1467 {
1468  // Check that p and r are valid:
1469  assert( 0 <= p );
1470  assert( 0 <= r );
1471  assert( p < mpr.mextent );
1472  assert( r < mrr.mextent );
1473 
1474  return Tensor3View(mdata +
1475  mpr.mstart + p * mpr.mstride +
1476  mrr.mstart + r * mrr.mstride,
1477  msr, mbr, mcr,
1478  s, b, c);
1479 }
1480 
1484  Index b,
1485  const Range& p,
1486  Index r,
1487  const Range& c)
1488 {
1489  // Check that b and r are valid:
1490  assert( 0 <= b );
1491  assert( 0 <= r );
1492  assert( b < mbr.mextent );
1493  assert( r < mrr.mextent );
1494 
1495  return Tensor3View(mdata +
1496  mbr.mstart + b * mbr.mstride +
1497  mrr.mstart + r * mrr.mstride,
1498  msr, mpr, mcr,
1499  s, p, c);
1500 }
1501 
1505  Index b,
1506  const Range& p,
1507  const Range& r,
1508  Index c)
1509 {
1510  // Check that b and c are valid:
1511  assert( 0 <= b );
1512  assert( 0 <= c );
1513  assert( b < mbr.mextent );
1514  assert( c < mcr.mextent );
1515 
1516  return Tensor3View(mdata +
1517  mbr.mstart + b * mbr.mstride +
1518  mcr.mstart + c * mcr.mstride,
1519  msr, mpr, mrr,
1520  s, p, r);
1521 }
1522 
1526  Index b,
1527  Index p,
1528  const Range& r,
1529  const Range& c)
1530 {
1531  // Check that b and p are valid:
1532  assert( 0 <= b );
1533  assert( 0 <= p );
1534  assert( b < mbr.mextent );
1535  assert( p < mpr.mextent );
1536 
1537  return Tensor3View(mdata +
1538  mbr.mstart + b * mbr.mstride +
1539  mpr.mstart + p * mpr.mstride,
1540  msr, mrr, mcr,
1541  s, r, c);
1542 }
1543 
1547  const Range& b,
1548  Index p,
1549  const Range& r,
1550  const Range& c)
1551 {
1552  // Check that s and p are valid:
1553  assert( 0 <= s );
1554  assert( 0 <= p );
1555  assert( s < msr.mextent );
1556  assert( p < mpr.mextent );
1557 
1558  return Tensor3View(mdata +
1559  msr.mstart + s * msr.mstride +
1560  mpr.mstart + p * mpr.mstride,
1561  mbr, mrr, mcr,
1562  b, r, c);
1563 }
1564 
1568  const Range& b,
1569  const Range& p,
1570  Index r,
1571  const Range& c)
1572 {
1573  // Check that s and r are valid:
1574  assert( 0 <= s );
1575  assert( 0 <= r );
1576  assert( s < msr.mextent );
1577  assert( r < mrr.mextent );
1578 
1579  return Tensor3View(mdata +
1580  msr.mstart + s * msr.mstride +
1581  mrr.mstart + r * mrr.mstride,
1582  mbr, mpr, mcr,
1583  b, p, c);
1584 }
1585 
1589  const Range& b,
1590  const Range& p,
1591  const Range& r,
1592  Index c)
1593 {
1594  // Check that s and c are valid:
1595  assert( 0 <= s );
1596  assert( 0 <= c );
1597  assert( s < msr.mextent );
1598  assert( c < mcr.mextent );
1599 
1600  return Tensor3View(mdata +
1601  msr.mstart + s * msr.mstride +
1602  mcr.mstart + c * mcr.mstride,
1603  mbr, mpr, mrr,
1604  b, p, r);
1605 }
1606 
1610  Index b,
1611  const Range& p,
1612  const Range& r,
1613  const Range& c)
1614 {
1615  // Check that s and b are valid:
1616  assert( 0 <= s );
1617  assert( 0 <= b );
1618  assert( s < msr.mextent );
1619  assert( b < mbr.mextent );
1620 
1621  return Tensor3View(mdata +
1622  msr.mstart + s * msr.mstride +
1623  mbr.mstart + b * mbr.mstride,
1624  mpr, mrr, mcr,
1625  p, r, c);
1626 }
1627 
1631  const Range& b,
1632  Index p,
1633  Index r,
1634  Index c)
1635 {
1636  // Check that p, r and c are valid:
1637  assert( 0 <= p );
1638  assert( 0 <= r );
1639  assert( 0 <= c );
1640  assert( p < mpr.mextent );
1641  assert( r < mrr.mextent );
1642  assert( c < mcr.mextent );
1643 
1644  return MatrixView(mdata +
1645  mpr.mstart + p * mpr.mstride +
1646  mrr.mstart + r * mrr.mstride +
1647  mcr.mstart + c * mcr.mstride,
1648  msr, mbr,
1649  s, b);
1650 }
1651 
1655  Index b,
1656  const Range& p,
1657  Index r,
1658  Index c)
1659 {
1660  // Check that b, r and c are valid:
1661  assert( 0 <= b );
1662  assert( 0 <= r );
1663  assert( 0 <= c );
1664  assert( b < mbr.mextent );
1665  assert( r < mrr.mextent );
1666  assert( c < mcr.mextent );
1667 
1668  return MatrixView(mdata +
1669  mbr.mstart + b * mbr.mstride +
1670  mrr.mstart + r * mpr.mstride +
1671  mcr.mstart + c * mcr.mstride,
1672  msr, mpr,
1673  s, p);
1674 }
1675 
1679  Index b,
1680  Index p,
1681  const Range& r,
1682  Index c)
1683 {
1684  // Check that b, p and c are valid:
1685  assert( 0 <= b );
1686  assert( 0 <= p );
1687  assert( 0 <= c );
1688  assert( b < mbr.mextent );
1689  assert( p < mpr.mextent );
1690  assert( c < mcr.mextent );
1691 
1692  return MatrixView(mdata +
1693  mbr.mstart + b * mbr.mstride +
1694  mpr.mstart + p * mpr.mstride +
1695  mcr.mstart + c * mcr.mstride,
1696  msr, mrr,
1697  s, r);
1698 }
1699 
1703  Index b,
1704  Index p,
1705  Index r,
1706  const Range& c)
1707 {
1708  // Check that b, p and r are valid:
1709  assert( 0 <= b );
1710  assert( 0 <= p );
1711  assert( 0 <= r );
1712  assert( b < mbr.mextent );
1713  assert( p < mpr.mextent );
1714  assert( r < mrr.mextent );
1715 
1716  return MatrixView(mdata +
1717  mbr.mstart + b * mbr.mstride +
1718  mpr.mstart + p * mpr.mstride +
1719  mrr.mstart + r * mrr.mstride,
1720  msr, mcr,
1721  s, c);
1722 }
1723 
1727  const Range& b,
1728  Index p,
1729  Index r,
1730  const Range& c)
1731 {
1732  // Check that s, p and r are valid:
1733  assert( 0 <= s );
1734  assert( 0 <= p );
1735  assert( 0 <= r );
1736  assert( s < msr.mextent );
1737  assert( p < mpr.mextent );
1738  assert( r < mrr.mextent );
1739 
1740  return MatrixView(mdata +
1741  msr.mstart + s * msr.mstride +
1742  mpr.mstart + p * mpr.mstride +
1743  mrr.mstart + r * mrr.mstride,
1744  mbr, mcr,
1745  b, c);
1746 }
1747 
1751  const Range& b,
1752  Index p,
1753  const Range& r,
1754  Index c )
1755 {
1756  // Check that s, p and c are valid:
1757  assert( 0 <= s );
1758  assert( 0 <= p );
1759  assert( 0 <= c );
1760  assert( s < msr.mextent );
1761  assert( p < mpr.mextent );
1762  assert( c < mcr.mextent );
1763 
1764  return MatrixView(mdata +
1765  msr.mstart + s * msr.mstride +
1766  mpr.mstart + p * mpr.mstride +
1767  mcr.mstart + c * mcr.mstride,
1768  mbr, mrr,
1769  b, r);
1770 }
1771 
1775  const Range& b,
1776  const Range& p,
1777  Index r,
1778  Index c )
1779 {
1780  // Check that s, r and c are valid:
1781  assert( 0 <= s );
1782  assert( 0 <= r );
1783  assert( 0 <= c );
1784  assert( s < msr.mextent );
1785  assert( r < mrr.mextent );
1786  assert( c < mcr.mextent );
1787 
1788  return MatrixView(mdata +
1789  msr.mstart + s * msr.mstride +
1790  mrr.mstart + r * mrr.mstride +
1791  mcr.mstart + c * mcr.mstride,
1792  mbr, mpr,
1793  b, p);
1794 }
1795 
1799  Index b,
1800  const Range& p,
1801  const Range& r,
1802  Index c )
1803 {
1804  // Check that s, b and c are valid:
1805  assert( 0 <= s );
1806  assert( 0 <= b );
1807  assert( 0 <= c );
1808  assert( s < msr.mextent );
1809  assert( b < mbr.mextent );
1810  assert( c < mcr.mextent );
1811 
1812  return MatrixView(mdata +
1813  msr.mstart + s * msr.mstride +
1814  mbr.mstart + b * mbr.mstride +
1815  mcr.mstart + c * mcr.mstride,
1816  mpr, mrr,
1817  p, r);
1818 }
1819 
1823  Index b,
1824  const Range& p,
1825  Index r,
1826  const Range& c)
1827 {
1828  // Check that s, b and r are valid:
1829  assert( 0 <= s );
1830  assert( 0 <= b );
1831  assert( 0 <= r );
1832  assert( s < msr.mextent );
1833  assert( b < mbr.mextent );
1834  assert( r < mrr.mextent );
1835 
1836  return MatrixView(mdata +
1837  msr.mstart + s * msr.mstride +
1838  mbr.mstart + b * mbr.mstride +
1839  mrr.mstart + r * mrr.mstride,
1840  mpr, mcr,
1841  p, c);
1842 }
1843 
1847  Index b,
1848  Index p,
1849  const Range& r,
1850  const Range& c)
1851 {
1852  // Check that s, b and p are valid:
1853  assert( 0 <= s );
1854  assert( 0 <= b );
1855  assert( 0 <= p );
1856  assert( s < msr.mextent );
1857  assert( b < mbr.mextent );
1858  assert( p < mpr.mextent );
1859 
1860  return MatrixView(mdata +
1861  msr.mstart + s * msr.mstride +
1862  mbr.mstart + b * mbr.mstride +
1863  mpr.mstart + p * mpr.mstride,
1864  mrr, mcr,
1865  r, c);
1866 }
1867 
1871  Index b,
1872  Index p,
1873  Index r,
1874  Index c)
1875 {
1876  // Check that b, p, r and c are valid:
1877  assert( 0 <= b );
1878  assert( 0 <= p );
1879  assert( 0 <= r );
1880  assert( 0 <= c );
1881  assert( b < mbr.mextent );
1882  assert( p < mpr.mextent );
1883  assert( r < mrr.mextent );
1884  assert( c < mcr.mextent );
1885 
1886  return VectorView(mdata +
1887  mbr.mstart + b * mbr.mstride +
1888  mpr.mstart + p * mpr.mstride +
1889  mrr.mstart + r * mrr.mstride +
1890  mcr.mstart + c * mcr.mstride,
1891  msr,
1892  s);
1893 }
1894 
1898  const Range& b,
1899  Index p,
1900  Index r,
1901  Index c)
1902 {
1903  // Check that s, p, r and c are valid:
1904  assert( 0 <= s );
1905  assert( 0 <= p );
1906  assert( 0 <= r );
1907  assert( 0 <= c );
1908  assert( s < msr.mextent );
1909  assert( p < mpr.mextent );
1910  assert( r < mrr.mextent );
1911  assert( c < mcr.mextent );
1912 
1913  return VectorView(mdata +
1914  msr.mstart + s * msr.mstride +
1915  mpr.mstart + p * mpr.mstride +
1916  mrr.mstart + r * mrr.mstride +
1917  mcr.mstart + c * mcr.mstride,
1918  mbr,
1919  b);
1920 }
1921 
1925  Index b,
1926  const Range& p,
1927  Index r,
1928  Index c)
1929 {
1930  // Check that s, b, r and c are valid:
1931  assert( 0 <= s );
1932  assert( 0 <= b );
1933  assert( 0 <= r );
1934  assert( 0 <= c );
1935  assert( s < msr.mextent );
1936  assert( b < mbr.mextent );
1937  assert( r < mrr.mextent );
1938  assert( c < mcr.mextent );
1939 
1940  return VectorView(mdata +
1941  msr.mstart + s * msr.mstride +
1942  mbr.mstart + b * mbr.mstride +
1943  mrr.mstart + r * mrr.mstride +
1944  mcr.mstart + c * mcr.mstride,
1945  mpr,
1946  p);
1947 }
1948 
1952  Index b,
1953  Index p,
1954  const Range& r,
1955  Index c)
1956 {
1957  // Check that s, b, p and c are valid:
1958  assert( 0 <= s );
1959  assert( 0 <= b );
1960  assert( 0 <= p );
1961  assert( 0 <= c );
1962  assert( s < msr.mextent );
1963  assert( b < mbr.mextent );
1964  assert( p < mpr.mextent );
1965  assert( c < mcr.mextent );
1966 
1967  return VectorView(mdata +
1968  msr.mstart + s * msr.mstride +
1969  mbr.mstart + b * mbr.mstride +
1970  mpr.mstart + p * mpr.mstride +
1971  mcr.mstart + c * mcr.mstride,
1972  mrr,
1973  r);
1974 }
1975 
1979  Index b,
1980  Index p,
1981  Index r,
1982  const Range& c)
1983 {
1984  // Check that s, b, p and r are valid:
1985  assert( 0 <= s );
1986  assert( 0 <= b );
1987  assert( 0 <= p );
1988  assert( 0 <= r );
1989  assert( s < msr.mextent );
1990  assert( b < mbr.mextent );
1991  assert( p < mpr.mextent );
1992  assert( r < mrr.mextent );
1993 
1994  return VectorView(mdata +
1995  msr.mstart + s * msr.mstride +
1996  mbr.mstart + b * mbr.mstride +
1997  mpr.mstart + p * mpr.mstride +
1998  mrr.mstart + r * mrr.mstride,
1999  mcr,
2000  c);
2001 }
2002 
2003 
2007 {
2008  return ConstTensor5View::begin();
2009 }
2010 
2013 {
2014  return ConstTensor5View::end();
2015 }
2016 
2019 {
2021  mbr, mpr, mrr, mcr),
2022  msr.mstride );
2023 }
2024 
2027 {
2028  return Iterator5D( Tensor4View(mdata + msr.mstart +
2029  (msr.mextent) * msr.mstride,
2030  mbr, mpr, mrr, mcr),
2031  msr.mstride );
2032 }
2033 
2039 {
2040  // Check that sizes are compatible:
2041  assert( msr.mextent == m.msr.mextent );
2042  assert( mbr.mextent == m.mbr.mextent );
2043  assert( mpr.mextent == m.mpr.mextent );
2044  assert( mrr.mextent == m.mrr.mextent );
2045  assert( mcr.mextent == m.mcr.mextent );
2046 
2047  copy( m.begin(), m.end(), begin() );
2048  return *this;
2049 }
2050 
2057 {
2058  // Check that sizes are compatible:
2059  assert( msr.mextent == m.msr.mextent );
2060  assert( mbr.mextent == m.mbr.mextent );
2061  assert( mpr.mextent == m.mpr.mextent );
2062  assert( mrr.mextent == m.mrr.mextent );
2063  assert( mcr.mextent == m.mcr.mextent );
2064 
2065  copy( m.begin(), m.end(), begin() );
2066  return *this;
2067 }
2068 
2073 {
2074  // Check that sizes are compatible:
2075  assert( msr.mextent == m.msr.mextent );
2076  assert( mbr.mextent == m.mbr.mextent );
2077  assert( mpr.mextent == m.mpr.mextent );
2078  assert( mrr.mextent == m.mrr.mextent );
2079  assert( mcr.mextent == m.mcr.mextent );
2080 
2081  copy( m.begin(), m.end(), begin() );
2082  return *this;
2083 }
2084 
2088 {
2089  copy( x, begin(), end() );
2090  return *this;
2091 }
2092 
2093 // Some little helper functions:
2094 //------------------------------
2095 
2098 {
2099  const Iterator5D es = end();
2100  for ( Iterator5D s = begin(); s != es ; ++s )
2101  {
2102  *s *= x;
2103  }
2104  return *this;
2105 }
2106 
2109 {
2110  const Iterator5D es = end();
2111  for ( Iterator5D s = begin(); s != es ; ++s )
2112  {
2113  *s /= x;
2114  }
2115  return *this;
2116 }
2117 
2120 {
2121  const Iterator5D es = end();
2122  for ( Iterator5D s = begin(); s != es ; ++s )
2123  {
2124  *s += x;
2125  }
2126  return *this;
2127 }
2128 
2131 {
2132  const Iterator5D es = end();
2133  for ( Iterator5D s = begin(); s != es ; ++s )
2134  {
2135  *s -= x;
2136  }
2137  return *this;
2138 }
2139 
2142 {
2143  assert( nshelves() == x.nshelves() );
2144  assert( nbooks() == x.nbooks() );
2145  assert( npages() == x.npages() );
2146  assert( nrows() == x.nrows() );
2147  assert( ncols() == x.ncols() );
2148  ConstIterator5D xs = x.begin();
2149  Iterator5D s = begin();
2150  const Iterator5D es = end();
2151  for ( ; s != es ; ++s, ++xs )
2152  {
2153  *s *= *xs;
2154  }
2155  return *this;
2156 }
2157 
2160 {
2161  assert( nshelves() == x.nshelves() );
2162  assert( nbooks() == x.nbooks() );
2163  assert( npages() == x.npages() );
2164  assert( nrows() == x.nrows() );
2165  assert( ncols() == x.ncols() );
2166  ConstIterator5D xs = x.begin();
2167  Iterator5D s = begin();
2168  const Iterator5D es = end();
2169  for ( ; s != es ; ++s, ++xs )
2170  {
2171  *s /= *xs;
2172  }
2173  return *this;
2174 }
2175 
2178 {
2179  assert( nshelves() == x.nshelves() );
2180  assert( nbooks() == x.nbooks() );
2181  assert( npages() == x.npages() );
2182  assert( nrows() == x.nrows() );
2183  assert( ncols() == x.ncols() );
2184  ConstIterator5D xs = x.begin();
2185  Iterator5D s = begin();
2186  const Iterator5D es = end();
2187  for ( ; s != es ; ++s, ++xs )
2188  {
2189  *s += *xs;
2190  }
2191  return *this;
2192 }
2193 
2196 {
2197  assert( nshelves() == x.nshelves() );
2198  assert( nbooks() == x.nbooks() );
2199  assert( npages() == x.npages() );
2200  assert( nrows() == x.nrows() );
2201  assert( ncols() == x.ncols() );
2202  ConstIterator5D xs = x.begin();
2203  Iterator5D s = begin();
2204  const Iterator5D es = end();
2205  for ( ; s != es ; ++s, ++xs )
2206  {
2207  *s -= *xs;
2208  }
2209  return *this;
2210 }
2211 
2215  Range(0,1,
2216  a.mbr.mextent*
2217  a.mpr.mextent*
2218  a.mrr.mextent*
2219  a.mcr.mextent),
2220  a.mbr,
2221  a.mpr,
2222  a.mrr,
2223  a.mcr )
2224 {
2225  // Nothing to do here.
2226 }
2227 
2232 {
2233  // Nothing to do here.
2234 }
2235 
2240  const Range& sr,
2241  const Range& br,
2242  const Range& pr,
2243  const Range& rr,
2244  const Range& cr) :
2245  ConstTensor5View(data, sr, br, pr, rr, cr)
2246 {
2247  // Nothing to do here.
2248 }
2249 
2271  const Range& ps,
2272  const Range& pb,
2273  const Range& pp,
2274  const Range& pr,
2275  const Range& pc,
2276  const Range& ns,
2277  const Range& nb,
2278  const Range& np,
2279  const Range& nr,
2280  const Range& nc) :
2281  ConstTensor5View(data, ps, pb, pp, pr, pc, ns, nb, np, nr, nc)
2282 {
2283  // Nothing to do here.
2284 }
2285 
2290 void copy(ConstIterator5D origin,
2291  const ConstIterator5D& end,
2292  Iterator5D target)
2293 {
2294  for ( ; origin != end ; ++origin, ++target )
2295  {
2296  // We use the copy function for the next smaller rank of tensor
2297  // recursively:
2298  copy( origin->begin(), origin->end(), target->begin() );
2299  }
2300 }
2301 
2303 void copy(Numeric x,
2304  Iterator5D target,
2305  const Iterator5D& end)
2306 {
2307  for ( ; target != end ; ++target )
2308  {
2309  // We use the copy function for the next smaller rank of tensor
2310  // recursively:
2311  copy( x, target->begin(), target->end() );
2312  }
2313 }
2314 
2315 
2316 // Functions for Tensor5:
2317 // ---------------------
2318 
2322 {
2323  // Nothing to do here. However, note that the default constructor
2324  // for Tensor5View has been called in the initializer list. That is
2325  // crucial, otherwise internal range objects will not be properly
2326  // initialized.
2327 }
2328 
2332  Tensor5View( new Numeric[s*b*p*r*c],
2333  Range( 0, s, b*p*r*c ),
2334  Range( 0, b, p*r*c ),
2335  Range( 0, p, r*c ),
2336  Range( 0, r, c ),
2337  Range( 0, c) )
2338 {
2339  // Nothing to do here.
2340 }
2341 
2344  Tensor5View( new Numeric[s*b*p*r*c],
2345  Range( 0, s, b*p*r*c ),
2346  Range( 0, b, p*r*c ),
2347  Range( 0, p, r*c ),
2348  Range( 0, r, c ),
2349  Range( 0, c) )
2350 {
2351  // Here we can access the raw memory directly, for slightly
2352  // increased efficiency:
2353  const Numeric *stop = mdata + s*b*p*r*c;
2354  for ( Numeric *x = mdata; x < stop; ++x )
2355  *x = fill;
2356 }
2357 
2361  Tensor5View( new Numeric[m.nshelves()*m.nbooks()*m.npages()*m.nrows()*m.ncols()],
2362  Range( 0, m.nshelves(), m.nbooks()*m.npages()*m.nrows()*m.ncols() ),
2363  Range( 0, m.nbooks(), m.npages()*m.nrows()*m.ncols() ),
2364  Range( 0, m.npages(), m.nrows()*m.ncols() ),
2365  Range( 0, m.nrows(), m.ncols() ),
2366  Range( 0, m.ncols() ) )
2367 {
2368  copy( m.begin(), m.end(), begin() );
2369 }
2370 
2374  Tensor5View( new Numeric[m.nshelves()*m.nbooks()*m.npages()*m.nrows()*m.ncols()],
2375  Range( 0, m.nshelves(), m.nbooks()*m.npages()*m.nrows()*m.ncols() ),
2376  Range( 0, m.nbooks(), m.npages()*m.nrows()*m.ncols() ),
2377  Range( 0, m.npages(), m.nrows()*m.ncols() ),
2378  Range( 0, m.nrows(), m.ncols() ),
2379  Range( 0, m.ncols() ) )
2380 {
2381  // There is a catch here: If m is an empty tensor, then it will have
2382  // dimensions of size 0. But these are used to initialize the stride
2383  // for higher dimensions! Thus, this method has to be consistent
2384  // with the behaviour of Range::Range. For now, Range::Range allows
2385  // also stride 0.
2386  copy( m.begin(), m.end(), begin() );
2387 }
2388 
2390 
2414 {
2415  swap(*this, x);
2416  return *this;
2417 }
2418 
2422 {
2423  copy( x, begin(), end() );
2424  return *this;
2425 }
2426 
2431 {
2432  assert( 0 <= s );
2433  assert( 0 <= b );
2434  assert( 0 <= p );
2435  assert( 0 <= r );
2436  assert( 0 <= c );
2437 
2438  if ( msr.mextent != s ||
2439  mbr.mextent != b ||
2440  mpr.mextent != p ||
2441  mrr.mextent != r ||
2442  mcr.mextent != c )
2443  {
2444  delete[] mdata;
2445  mdata = new Numeric[s*b*p*r*c];
2446 
2447  msr.mstart = 0;
2448  msr.mextent = s;
2449  msr.mstride = b*p*r*c;
2450 
2451  mbr.mstart = 0;
2452  mbr.mextent = b;
2453  mbr.mstride = p*r*c;
2454 
2455  mpr.mstart = 0;
2456  mpr.mextent = p;
2457  mpr.mstride = r*c;
2458 
2459  mrr.mstart = 0;
2460  mrr.mextent = r;
2461  mrr.mstride = c;
2462 
2463  mcr.mstart = 0;
2464  mcr.mextent = c;
2465  mcr.mstride = 1;
2466  }
2467 }
2468 
2469 
2471 void swap(Tensor5& t1, Tensor5& t2)
2472 {
2473  std::swap(t1.msr, t2.msr);
2474  std::swap(t1.mbr, t2.mbr);
2475  std::swap(t1.mpr, t2.mpr);
2476  std::swap(t1.mrr, t2.mrr);
2477  std::swap(t1.mcr, t2.mcr);
2478  std::swap(t1.mdata, t2.mdata);
2479 }
2480 
2481 
2485 {
2486 // cout << "Destroying a Tensor5:\n"
2487 // << *this << "\n........................................\n";
2488  delete[] mdata;
2489 }
2490 
2491 
2508  double (&my_func)(double),
2509  ConstTensor5View x )
2510 {
2511  // Check dimensions:
2512  assert( y.nshelves() == x.nshelves() );
2513  assert( y.nbooks() == x.nbooks() );
2514  assert( y.npages() == x.npages() );
2515  assert( y.nrows() == x.nrows() );
2516  assert( y.ncols() == x.ncols() );
2517 
2518  const ConstIterator5D xe = x.end();
2519  ConstIterator5D xi = x.begin();
2520  Iterator5D yi = y.begin();
2521  for ( ; xi != xe; ++xi, ++yi )
2522  {
2523  // Use the transform function of lower dimensional tensors
2524  // recursively:
2525  transform( *yi, my_func, *xi );
2526  }
2527 }
2528 
2531 {
2532  const ConstIterator5D xe = x.end();
2533  ConstIterator5D xi = x.begin();
2534 
2535  // Initial value for max:
2536  Numeric themax = max(*xi);
2537  ++xi;
2538 
2539  for ( ; xi != xe ; ++xi )
2540  {
2541  // Use the max function of lower dimensional tensors
2542  // recursively:
2543  Numeric maxi = max(*xi);
2544  if ( maxi > themax )
2545  themax = maxi;
2546  }
2547 
2548  return themax;
2549 }
2550 
2553 {
2554  const ConstIterator5D xe = x.end();
2555  ConstIterator5D xi = x.begin();
2556 
2557  // Initial value for min:
2558  Numeric themin = min(*xi);
2559  ++xi;
2560 
2561  for ( ; xi != xe ; ++xi )
2562  {
2563  // Use the min function of lower dimensional tensors
2564  // recursively:
2565  Numeric mini = min(*xi);
2566  if ( mini < themin )
2567  themin = mini;
2568  }
2569 
2570  return themin;
2571 }
2572 
2574 // Helper function for debugging
2575 #ifndef NDEBUG
2576 
2594  Index r, Index c)
2595 {
2596  return tv(s, b, p, r, c);
2597 }
2598 
2599 #endif
2600 
Range mcr
The column range of mdata that is actually used.
Definition: matpackV.h:262
Index npages() const
Returns the number of pages.
Definition: matpackV.cc:47
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:35
Tensor5View & operator+=(Numeric x)
Addition of scalar.
Definition: matpackV.cc:2119
The VectorView class.
Definition: matpackI.h:372
Index nrows() const
Returns the number of rows.
Definition: matpackV.cc:53
Index mstride
The stride.
Definition: matpackI.h:209
The Tensor4View class.
Definition: matpackIV.h:243
void resize(Index s, Index b, Index p, Index r, Index c)
Resize function.
Definition: matpackV.cc:2430
std::ostream & operator<<(std::ostream &os, const ConstTensor5View &v)
Output operator.
Definition: matpackV.cc:888
Index mstart
The start index.
Definition: matpackI.h:204
Tensor5View & operator-=(Numeric x)
Subtraction of scalar.
Definition: matpackV.cc:2130
The MatrixView class.
Definition: matpackI.h:679
ConstIterator4D begin() const
Return const iterator to first book.
Definition: matpackIV.cc:414
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:2507
virtual ~Tensor5()
Destructor for Tensor5.
Definition: matpackV.cc:2484
The range class.
Definition: matpackI.h:148
void swap(Tensor5 &t1, Tensor5 &t2)
Swaps two objects.
Definition: matpackV.cc:2471
Index nbooks() const
Returns the number of books.
Definition: matpackV.cc:41
Tensor5()
Default constructor.
Definition: matpackV.cc:2320
ConstIterator5D end() const
Return const iterator behind last shelf.
Definition: matpackV.cc:800
void copy(ConstIterator5D origin, const ConstIterator5D &end, Iterator5D target)
Copy data between begin and end to target.
Definition: matpackV.cc:2290
Numeric max(const ConstTensor5View &x)
Max function, tensor version.
Definition: matpackV.cc:2530
A constant view of a Tensor4.
Definition: matpackIV.h:141
friend void swap(Tensor5 &t1, Tensor5 &t2)
Swaps two objects.
Definition: matpackV.cc:2471
Tensor5View & operator/=(Numeric x)
Division by scalar.
Definition: matpackV.cc:2108
Index nshelves() const
Returns the number of shelves.
Definition: matpackV.cc:35
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:915
Range mbr
The book range of mdata that is actually used.
Definition: matpackV.h:256
Range mpr
The page range of mdata that is actually used.
Definition: matpackV.h:258
Numeric * mdata
Pointer to the plain C array that holds the data.
Definition: matpackV.h:264
The Tensor3View class.
Definition: matpackIII.h:232
ConstIterator5D end() const
Return const iterator behind last shelf.
Definition: matpackV.cc:2012
Tensor5View()
Default constructor.
Definition: matpackV.cc:2230
The declarations of all the exception classes.
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:67
A constant view of a Tensor5.
Definition: matpackV.h:152
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:29
ConstIterator5D begin() const
Return const iterator to first shelf.
Definition: matpackV.cc:792
Range msr
The shelf range of mdata that is actually used.
Definition: matpackV.h:254
const Numeric * get_c_array() const
Conversion to plain C-array.
Definition: matpackV.cc:778
Index mextent
The number of elements.
Definition: matpackI.h:207
Const version of Iterator5D.
Definition: matpackV.h:88
Tensor5View & operator=(const ConstTensor5View &v)
Assignment operator.
Definition: matpackV.cc:2038
The Tensor5View class.
Definition: matpackV.h:276
ConstIterator5D begin() const
Return const iterator to first shelf.
Definition: matpackV.cc:2006
ConstIterator4D begin() const
Return const iterator to first book.
Definition: matpackIV.cc:997
Implementation of Tensors of Rank 5.
Definition: matpackV.h:38
ConstIterator4D end() const
Return const iterator behind last book.
Definition: matpackIV.cc:422
ConstIterator4D end() const
Return const iterator behind last book.
Definition: matpackIV.cc:1003
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:2593
#define ns
Definition: continua.cc:21931
Numeric min(const ConstTensor5View &x)
Min function, tensor version.
Definition: matpackV.cc:2552
A constant view of a Tensor3.
Definition: matpackIII.h:139
Range mrr
The row range of mdata that is actually used.
Definition: matpackV.h:260
A constant view of a Vector.
Definition: matpackI.h:292
A constant view of a Matrix.
Definition: matpackI.h:596
Index ncols() const
Returns the number of columns.
Definition: matpackV.cc:59
ConstTensor5View()
Default constructor.
Definition: matpackV.cc:826
Tensor5View & operator*=(Numeric x)
Multiplication by scalar.
Definition: matpackV.cc:2097
friend class Tensor5View
Definition: matpackV.h:234
The Tensor5 class.
Definition: matpackV.h:451
Tensor5 & operator=(Tensor5 x)
Assignment operator from another tensor.
Definition: matpackV.cc:2413