ARTS  2.0.49
matpackV.cc
Go to the documentation of this file.
1 /* Copyright (C) 2002-2008 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 // Functions for ConstTensor5View:
29 // ------------------------------
30 
33 {
34  return msr.mextent;
35 }
36 
39 {
40  return mbr.mextent;
41 }
42 
45 {
46  return mpr.mextent;
47 }
48 
51 {
52  return mrr.mextent;
53 }
54 
57 {
58  return mcr.mextent;
59 }
60 
65  const Range& b,
66  const Range& p,
67  const Range& r,
68  const Range& c) const
69 {
70  return ConstTensor5View(mdata,
71  msr, mbr, mpr, mrr, mcr,
72  s, b, p, r, c);
73 }
74 
78  const Range& b,
79  const Range& p,
80  const Range& r,
81  Index c ) const
82 {
83  // Check that c is valid:
84  assert( 0 <= c );
85  assert( c < mcr.mextent );
86 
87  return ConstTensor4View(mdata +
88  mcr.mstart + c * mcr.mstride,
89  msr, mbr, mpr, mrr,
90  s, b, p, r);
91 }
92 
96  const Range& b,
97  const Range& p,
98  Index r,
99  const Range& c) const
100 {
101  // Check that r is valid:
102  assert( 0 <= r );
103  assert( r < mrr.mextent );
104 
105  return ConstTensor4View(mdata +
106  mrr.mstart + r * mrr.mstride,
107  msr, mbr, mpr, mcr,
108  s, b, p, c);
109 }
110 
114  const Range& b,
115  Index p,
116  const Range& r,
117  const Range& c) const
118 {
119  // Check that p is valid:
120  assert( 0 <= p );
121  assert( p < mpr.mextent );
122 
123  return ConstTensor4View(mdata +
124  mpr.mstart + p * mpr.mstride,
125  msr, mbr, mrr, mcr,
126  s, b, r, c);
127 }
128 
132  Index b,
133  const Range& p,
134  const Range& r,
135  const Range& c) const
136 {
137  // Check that b is valid:
138  assert( 0 <= b );
139  assert( b < mbr.mextent );
140 
141  return ConstTensor4View(mdata +
142  mbr.mstart + b * mbr.mstride,
143  msr, mpr, mrr, mcr,
144  s, p, r, c);
145 }
146 
150  const Range& b,
151  const Range& p,
152  const Range& r,
153  const Range& c) const
154 {
155  // Check that s is valid:
156  assert( 0 <= s );
157  assert( s < msr.mextent );
158 
159  return ConstTensor4View(mdata +
160  msr.mstart + s * msr.mstride,
161  mbr, mpr, mrr, mcr,
162  b, p, r, c);
163 }
164 
168  const Range& b,
169  const Range& p,
170  Index r,
171  Index c ) const
172 {
173  // Check that r and c is valid:
174  assert( 0 <= r );
175  assert( 0 <= c );
176  assert( r < mrr.mextent );
177  assert( c < mcr.mextent );
178 
179  return ConstTensor3View(mdata +
180  mrr.mstart + r * mrr.mstride +
181  mcr.mstart + c * mcr.mstride,
182  msr, mbr, mpr,
183  s, b, p);
184 }
185 
189  const Range& b,
190  Index p,
191  const Range& r,
192  Index c ) const
193 {
194  // Check that p and c are valid:
195  assert( 0 <= p );
196  assert( 0 <= c );
197  assert( p < mpr.mextent );
198  assert( c < mcr.mextent );
199 
200  return ConstTensor3View(mdata +
201  mpr.mstart + p * mpr.mstride +
202  mcr.mstart + c * mcr.mstride,
203  msr, mbr, mrr,
204  s, b, r);
205 }
206 
210  const Range& b,
211  Index p,
212  Index r,
213  const Range& c) const
214 {
215  // Check that p and r are valid:
216  assert( 0 <= p );
217  assert( 0 <= r );
218  assert( p < mpr.mextent );
219  assert( r < mrr.mextent );
220 
221  return ConstTensor3View(mdata +
222  mpr.mstart + p * mpr.mstride +
223  mrr.mstart + r * mrr.mstride,
224  msr, mbr, mcr,
225  s, b, c);
226 }
227 
231  Index b,
232  const Range& p,
233  Index r,
234  const Range& c) const
235 {
236  // Check that b and r are valid:
237  assert( 0 <= b );
238  assert( 0 <= r );
239  assert( b < mbr.mextent );
240  assert( r < mrr.mextent );
241 
242  return ConstTensor3View(mdata +
243  mbr.mstart + b * mbr.mstride +
244  mrr.mstart + r * mrr.mstride,
245  msr, mpr, mcr,
246  s, p, c);
247 }
248 
252  Index b,
253  const Range& p,
254  const Range& r,
255  Index c ) const
256 {
257  // Check that b and c are valid:
258  assert( 0 <= b );
259  assert( 0 <= c );
260  assert( b < mbr.mextent );
261  assert( c < mcr.mextent );
262 
263  return ConstTensor3View(mdata +
264  mbr.mstart + b * mbr.mstride +
265  mcr.mstart + c * mcr.mstride,
266  msr, mpr, mrr,
267  s, p, r);
268 }
269 
273  Index b,
274  Index p,
275  const Range& r,
276  const Range& c) const
277 {
278  // Check that b and p are valid:
279  assert( 0 <= b );
280  assert( 0 <= p );
281  assert( b < mbr.mextent );
282  assert( p < mpr.mextent );
283 
284  return ConstTensor3View(mdata +
285  mbr.mstart + b * mbr.mstride +
286  mpr.mstart + p * mpr.mstride,
287  msr, mrr, mcr,
288  s, r, c);
289 }
290 
294  const Range& b,
295  Index p,
296  const Range& r,
297  const Range& c) const
298 {
299  // Check that s and p are valid:
300  assert( 0 <= s );
301  assert( 0 <= p );
302  assert( s < msr.mextent );
303  assert( p < mpr.mextent );
304 
305  return ConstTensor3View(mdata +
306  msr.mstart + s * msr.mstride +
307  mpr.mstart + p * mpr.mstride,
308  mbr, mrr, mcr,
309  b, r, c);
310 }
311 
315  const Range& b,
316  const Range& p,
317  Index r,
318  const Range& c) const
319 {
320  // Check that s and r are valid:
321  assert( 0 <= s );
322  assert( 0 <= r );
323  assert( s < msr.mextent );
324  assert( r < mrr.mextent );
325 
326  return ConstTensor3View(mdata +
327  msr.mstart + s * msr.mstride +
328  mrr.mstart + r * mrr.mstride,
329  mbr, mpr, mcr,
330  b, p, c);
331 }
332 
336  const Range& b,
337  const Range& p,
338  const Range& r,
339  Index c ) const
340 {
341  // Check that s and c are valid:
342  assert( 0 <= s );
343  assert( 0 <= c );
344  assert( s < msr.mextent );
345  assert( c < mcr.mextent );
346 
347  return ConstTensor3View(mdata +
348  msr.mstart + s * msr.mstride +
349  mcr.mstart + c * mcr.mstride,
350  mbr, mpr, mrr,
351  b, p, r);
352 }
353 
357  Index b,
358  const Range& p,
359  const Range& r,
360  const Range& c) const
361 {
362  // Check that s and b are valid:
363  assert( 0 <= s );
364  assert( 0 <= b );
365  assert( s < msr.mextent );
366  assert( b < mbr.mextent );
367 
368  return ConstTensor3View(mdata +
369  msr.mstart + s * msr.mstride +
370  mbr.mstart + b * mbr.mstride,
371  mpr, mrr, mcr,
372  p, r, c);
373 }
374 
378  const Range& b,
379  Index p,
380  Index r,
381  Index c ) const
382 {
383  // Check that p, r and c are valid:
384  assert( 0 <= p );
385  assert( 0 <= r );
386  assert( 0 <= c );
387  assert( p < mpr.mextent );
388  assert( r < mrr.mextent );
389  assert( c < mcr.mextent );
390 
391  return ConstMatrixView(mdata +
392  mpr.mstart + p * mpr.mstride +
393  mrr.mstart + r * mrr.mstride +
394  mcr.mstart + c * mcr.mstride,
395  msr, mbr,
396  s, b);
397 }
398 
402  Index b,
403  const Range& p,
404  Index r,
405  Index c ) const
406 {
407  // Check that b, r and c are valid:
408  assert( 0 <= b );
409  assert( 0 <= r );
410  assert( 0 <= c );
411  assert( b < mbr.mextent );
412  assert( r < mrr.mextent );
413  assert( c < mcr.mextent );
414 
415  return ConstMatrixView(mdata +
416  mbr.mstart + b * mbr.mstride +
417  mrr.mstart + r * mpr.mstride +
418  mcr.mstart + c * mcr.mstride,
419  msr, mpr,
420  s, p);
421 }
422 
426  Index b,
427  Index p,
428  const Range& r,
429  Index c ) const
430 {
431  // Check that b, p and c are valid:
432  assert( 0 <= b );
433  assert( 0 <= p );
434  assert( 0 <= c );
435  assert( b < mbr.mextent );
436  assert( p < mpr.mextent );
437  assert( c < mcr.mextent );
438 
439  return ConstMatrixView(mdata +
440  mbr.mstart + b * mbr.mstride +
441  mpr.mstart + p * mpr.mstride +
442  mcr.mstart + c * mcr.mstride,
443  msr, mrr,
444  s, r);
445 }
446 
450  Index b,
451  Index p,
452  Index r,
453  const Range& c) const
454 {
455  // Check that b, p and r are valid:
456  assert( 0 <= b );
457  assert( 0 <= p );
458  assert( 0 <= r );
459  assert( b < mbr.mextent );
460  assert( p < mpr.mextent );
461  assert( r < mrr.mextent );
462 
463  return ConstMatrixView(mdata +
464  mbr.mstart + b * mbr.mstride +
465  mpr.mstart + p * mpr.mstride +
466  mrr.mstart + r * mrr.mstride,
467  msr, mcr,
468  s, c);
469 }
470 
474  const Range& b,
475  Index p,
476  Index r,
477  const Range& c) const
478 {
479  // Check that s, p and r are valid:
480  assert( 0 <= s );
481  assert( 0 <= p );
482  assert( 0 <= r );
483  assert( s < msr.mextent );
484  assert( p < mpr.mextent );
485  assert( r < mrr.mextent );
486 
487  return ConstMatrixView(mdata +
488  msr.mstart + s * msr.mstride +
489  mpr.mstart + p * mpr.mstride +
490  mrr.mstart + r * mrr.mstride,
491  mbr, mcr,
492  b, c);
493 }
494 
498  const Range& b,
499  Index p,
500  const Range& r,
501  Index c ) const
502 {
503  // Check that s, p and c are valid:
504  assert( 0 <= s );
505  assert( 0 <= p );
506  assert( 0 <= c );
507  assert( s < msr.mextent );
508  assert( p < mpr.mextent );
509  assert( c < mcr.mextent );
510 
511  return ConstMatrixView(mdata +
512  msr.mstart + s * msr.mstride +
513  mpr.mstart + p * mpr.mstride +
514  mcr.mstart + c * mcr.mstride,
515  mbr, mrr,
516  b, r);
517 }
518 
522  const Range& b,
523  const Range& p,
524  Index r,
525  Index c ) const
526 {
527  // Check that s, r and c are valid:
528  assert( 0 <= s );
529  assert( 0 <= r );
530  assert( 0 <= c );
531  assert( s < msr.mextent );
532  assert( r < mrr.mextent );
533  assert( c < mcr.mextent );
534 
535  return ConstMatrixView(mdata +
536  msr.mstart + s * msr.mstride +
537  mrr.mstart + r * mrr.mstride +
538  mcr.mstart + c * mcr.mstride,
539  mbr, mpr,
540  b, p);
541 }
542 
546  Index b,
547  const Range& p,
548  const Range& r,
549  Index c ) const
550 {
551  // Check that s, b and c are valid:
552  assert( 0 <= s );
553  assert( 0 <= b );
554  assert( 0 <= c );
555  assert( s < msr.mextent );
556  assert( b < mbr.mextent );
557  assert( c < mcr.mextent );
558 
559  return ConstMatrixView(mdata +
560  msr.mstart + s * msr.mstride +
561  mbr.mstart + b * mbr.mstride +
562  mcr.mstart + c * mcr.mstride,
563  mpr, mrr,
564  p, r);
565 }
566 
570  Index b,
571  const Range& p,
572  Index r,
573  const Range& c) const
574 {
575  // Check that s, b and r are valid:
576  assert( 0 <= s );
577  assert( 0 <= b );
578  assert( 0 <= r );
579  assert( s < msr.mextent );
580  assert( b < mbr.mextent );
581  assert( r < mrr.mextent );
582 
583  return ConstMatrixView(mdata +
584  msr.mstart + s * msr.mstride +
585  mbr.mstart + b * mbr.mstride +
586  mrr.mstart + r * mrr.mstride,
587  mpr, mcr,
588  p, c);
589 }
590 
594  Index b,
595  Index p,
596  const Range& r,
597  const Range& c) const
598 {
599  // Check that s, b and p are valid:
600  assert( 0 <= s );
601  assert( 0 <= b );
602  assert( 0 <= p );
603  assert( s < msr.mextent );
604  assert( b < mbr.mextent );
605  assert( p < mpr.mextent );
606 
607  return ConstMatrixView(mdata +
608  msr.mstart + s * msr.mstride +
609  mbr.mstart + b * mbr.mstride +
610  mpr.mstart + p * mpr.mstride,
611  mrr, mcr,
612  r, c);
613 }
614 
618  Index b,
619  Index p,
620  Index r,
621  Index c ) const
622 {
623  // Check that b, p, r and c are valid:
624  assert( 0 <= b );
625  assert( 0 <= p );
626  assert( 0 <= r );
627  assert( 0 <= c );
628  assert( b < mbr.mextent );
629  assert( p < mpr.mextent );
630  assert( r < mrr.mextent );
631  assert( c < mcr.mextent );
632 
633  return ConstVectorView(mdata +
634  mbr.mstart + b * mbr.mstride +
635  mpr.mstart + p * mpr.mstride +
636  mrr.mstart + r * mrr.mstride +
637  mcr.mstart + c * mcr.mstride,
638  msr,
639  s);
640 }
641 
645  const Range& b,
646  Index p,
647  Index r,
648  Index c ) const
649 {
650  // Check that s, p, r and c are valid:
651  assert( 0 <= s );
652  assert( 0 <= p );
653  assert( 0 <= r );
654  assert( 0 <= c );
655  assert( s < msr.mextent );
656  assert( p < mpr.mextent );
657  assert( r < mrr.mextent );
658  assert( c < mcr.mextent );
659 
660  return ConstVectorView(mdata +
661  msr.mstart + s * msr.mstride +
662  mpr.mstart + p * mpr.mstride +
663  mrr.mstart + r * mrr.mstride +
664  mcr.mstart + c * mcr.mstride,
665  mbr,
666  b);
667 }
668 
672  Index b,
673  const Range& p,
674  Index r,
675  Index c ) const
676 {
677  // Check that s, b, r and c are valid:
678  assert( 0 <= s );
679  assert( 0 <= b );
680  assert( 0 <= r );
681  assert( 0 <= c );
682  assert( s < msr.mextent );
683  assert( b < mbr.mextent );
684  assert( r < mrr.mextent );
685  assert( c < mcr.mextent );
686 
687  return ConstVectorView(mdata +
688  msr.mstart + s * msr.mstride +
689  mbr.mstart + b * mbr.mstride +
690  mrr.mstart + r * mrr.mstride +
691  mcr.mstart + c * mcr.mstride,
692  mpr,
693  p);
694 }
695 
699  Index b,
700  Index p,
701  const Range& r,
702  Index c ) const
703 {
704  // Check that s, b, p and c are valid:
705  assert( 0 <= s );
706  assert( 0 <= b );
707  assert( 0 <= p );
708  assert( 0 <= c );
709  assert( s < msr.mextent );
710  assert( b < mbr.mextent );
711  assert( p < mpr.mextent );
712  assert( c < mcr.mextent );
713 
714  return ConstVectorView(mdata +
715  msr.mstart + s * msr.mstride +
716  mbr.mstart + b * mbr.mstride +
717  mpr.mstart + p * mpr.mstride +
718  mcr.mstart + c * mcr.mstride,
719  mrr,
720  r);
721 }
722 
726  Index b,
727  Index p,
728  Index r,
729  const Range& c) const
730 {
731  // Check that s, b, p and r are valid:
732  assert( 0 <= s );
733  assert( 0 <= b );
734  assert( 0 <= p );
735  assert( 0 <= r );
736  assert( s < msr.mextent );
737  assert( b < mbr.mextent );
738  assert( p < mpr.mextent );
739  assert( r < mrr.mextent );
740 
741  return ConstVectorView(mdata +
742  msr.mstart + s * msr.mstride +
743  mbr.mstart + b * mbr.mstride +
744  mpr.mstart + p * mpr.mstride +
745  mrr.mstart + r * mrr.mstride,
746  mcr,
747  c);
748 }
749 
750 
758 {
760  || mbr.mstart != 0 || mbr.mstride != mpr.mextent * mrr.mextent * mcr.mextent
761  || mpr.mstart != 0 || mpr.mstride != mrr.mextent * mcr.mextent
762  || mrr.mstart != 0 || mrr.mstride != mcr.mextent
763  || mcr.mstart != 0 || mcr.mstride != 1)
764  throw runtime_error("A Tensor5View can only be converted to a plain C-array if mbr.mstart == 0 and mbr.mstride == mrp.extent*mrr.extent*mcr.extent and mpr.mstart == 0 and mpr.mstride == mrr.extent*mcr.extent and mrr.mstart == 0 and mrr.mstride == mcr.extent and mcr.mstart == 0 and mcr.mstride == 1");
765 
766  return mdata;
767 }
768 
776 {
778  || mbr.mstart != 0 || mbr.mstride != mpr.mextent * mrr.mextent * mcr.mextent
779  || mpr.mstart != 0 || mpr.mstride != mrr.mextent * mcr.mextent
780  || mrr.mstart != 0 || mrr.mstride != mcr.mextent
781  || mcr.mstart != 0 || mcr.mstride != 1)
782  throw runtime_error("A Tensor5View can only be converted to a plain C-array if mbr.mstart == 0 and mbr.mstride == mrp.extent*mrr.extent*mcr.extent and mpr.mstart == 0 and mpr.mstride == mrr.extent*mcr.extent and mrr.mstart == 0 and mrr.mstride == mcr.extent and mcr.mstart == 0 and mcr.mstride == 1");
783 
784  return mdata;
785 }
786 
787 
790 {
792  mbr, mpr, mrr, mcr),
793  msr.mstride );
794 }
795 
798 {
800  (msr.mextent) * msr.mstride,
801  mbr, mpr, mrr, mcr),
802  msr.mstride );
803 }
804 
807  msr(0,1,
808  a.mbr.mextent*
809  a.mpr.mextent*
810  a.mrr.mextent*
811  a.mcr.mextent),
812  mbr(a.mbr),
813  mpr(a.mpr),
814  mrr(a.mrr),
815  mcr(a.mcr),
816  mdata(a.mdata)
817 {
818  // Nothing to do here.
819 }
820 
824  msr(0,0,1),
825  mbr(0,0,1),
826  mpr(0,0,1),
827  mrr(0,0,1),
828  mcr(0,0,1),
829  mdata(NULL)
830 {
831  // Nothing to do here.
832 }
833 
839  const Range& sr,
840  const Range& br,
841  const Range& pr,
842  const Range& rr,
843  const Range& cr) :
844  msr(sr),
845  mbr(br),
846  mpr(pr),
847  mrr(rr),
848  mcr(cr),
849  mdata(data)
850 {
851  // Nothing to do here.
852 }
853 
862  const Range& ps,
863  const Range& pb,
864  const Range& pp,
865  const Range& pr,
866  const Range& pc,
867  const Range& ns,
868  const Range& nb,
869  const Range& np,
870  const Range& nr,
871  const Range& nc) :
872  msr(ps,ns),
873  mbr(pb,nb),
874  mpr(pp,np),
875  mrr(pr,nr),
876  mcr(pc,nc),
877  mdata(data)
878 {
879  // Nothing to do here.
880 }
881 
885 ostream& operator<<(ostream& os, const ConstTensor5View& v)
886 {
887  // Page iterators:
888  ConstIterator5D is = v.begin();
889  const ConstIterator5D end_shelf = v.end();
890 
891  if ( is != end_shelf ) {
892  os << *is;
893  ++is;
894  }
895 
896  for ( ; is != end_shelf; ++is ) {
897  os << "\n\n";
898  os << *is;
899  }
900 
901  return os;
902 }
903 
904 
905 // Functions for Tensor5View:
906 // -------------------------
907 
913  const Range& b,
914  const Range& p,
915  const Range& r,
916  const Range& c) const
917 {
918  return ConstTensor5View::operator()(s,b,p,r,c);
919 }
920 
926  const Range& b,
927  const Range& p,
928  const Range& r,
929  Index c ) const
930 {
931  return ConstTensor5View::operator()(s,b,p,r,c);
932 }
933 
939  const Range& b,
940  const Range& p,
941  Index r,
942  const Range& c) const
943 {
944  return ConstTensor5View::operator()(s,b,p,r,c);
945 }
946 
952  const Range& b,
953  Index p,
954  const Range& r,
955  const Range& c) const
956 {
957  return ConstTensor5View::operator()(s,b,p,r,c);
958 }
959 
965  Index b,
966  const Range& p,
967  const Range& r,
968  const Range& c) const
969 {
970  return ConstTensor5View::operator()(s,b,p,r,c);
971 }
972 
978  const Range& b,
979  const Range& p,
980  const Range& r,
981  const Range& c) const
982 {
983  return ConstTensor5View::operator()(s,b,p,r,c);
984 }
985 
991  const Range& b,
992  const Range& p,
993  Index r,
994  Index c ) const
995 {
996  return ConstTensor5View::operator()(s,b,p,r,c);
997 }
998 
1004  const Range& b,
1005  Index p,
1006  const Range& r,
1007  Index c ) const
1008 {
1009  return ConstTensor5View::operator()(s,b,p,r,c);
1010 }
1011 
1017  const Range& b,
1018  Index p,
1019  Index r,
1020  const Range& c) const
1021 {
1022  return ConstTensor5View::operator()(s,b,p,r,c);
1023 }
1024 
1030  Index b,
1031  const Range& p,
1032  Index r,
1033  const Range& c) const
1034 {
1035  return ConstTensor5View::operator()(s,b,p,r,c);
1036 }
1037 
1043  Index b,
1044  const Range& p,
1045  const Range& r,
1046  Index c ) const
1047 {
1048  return ConstTensor5View::operator()(s,b,p,r,c);
1049 }
1050 
1056  Index b,
1057  Index p,
1058  const Range& r,
1059  const Range& c) const
1060 {
1061  return ConstTensor5View::operator()(s,b,p,r,c);
1062 }
1063 
1069  const Range& b,
1070  Index p,
1071  const Range& r,
1072  const Range& c) const
1073 {
1074  return ConstTensor5View::operator()(s,b,p,r,c);
1075 }
1076 
1082  const Range& b,
1083  const Range& p,
1084  Index r,
1085  const Range& c) const
1086 {
1087  return ConstTensor5View::operator()(s,b,p,r,c);
1088 }
1089 
1095  const Range& b,
1096  const Range& p,
1097  const Range& r,
1098  Index c ) const
1099 {
1100  return ConstTensor5View::operator()(s,b,p,r,c);
1101 }
1102 
1108  Index b,
1109  const Range& p,
1110  const Range& r,
1111  const Range& c) const
1112 {
1113  return ConstTensor5View::operator()(s,b,p,r,c);
1114 }
1115 
1121  const Range& b,
1122  Index p,
1123  Index r,
1124  Index c ) const
1125 {
1126  return ConstTensor5View::operator()(s,b,p,r,c);
1127 }
1128 
1134  Index b,
1135  const Range& p,
1136  Index r,
1137  Index c ) const
1138 {
1139  return ConstTensor5View::operator()(s,b,p,r,c);
1140 }
1141 
1147  Index b,
1148  Index p,
1149  const Range& r,
1150  Index c ) const
1151 {
1152  return ConstTensor5View::operator()(s,b,p,r,c);
1153 }
1154 
1160  Index b,
1161  Index p,
1162  Index r,
1163  const Range& c) const
1164 {
1165  return ConstTensor5View::operator()(s,b,p,r,c);
1166 }
1167 
1173  const Range& b,
1174  Index p,
1175  Index r,
1176  const Range& c) const
1177 {
1178  return ConstTensor5View::operator()(s,b,p,r,c);
1179 }
1180 
1186  const Range& b,
1187  Index p,
1188  const Range& r,
1189  Index c ) const
1190 {
1191  return ConstTensor5View::operator()(s,b,p,r,c);
1192 }
1193 
1199  const Range& b,
1200  const Range& p,
1201  Index r,
1202  Index c ) const
1203 {
1204  return ConstTensor5View::operator()(s,b,p,r,c);
1205 }
1206 
1212  Index b,
1213  const Range& p,
1214  const Range& r,
1215  Index c ) const
1216 {
1217  return ConstTensor5View::operator()(s,b,p,r,c);
1218 }
1219 
1225  Index b,
1226  const Range& p,
1227  Index r,
1228  const Range& c) const
1229 {
1230  return ConstTensor5View::operator()(s,b,p,r,c);
1231 }
1232 
1238  Index b,
1239  Index p,
1240  const Range& r,
1241  const Range& c) const
1242 {
1243  return ConstTensor5View::operator()(s,b,p,r,c);
1244 }
1245 
1251  Index b,
1252  Index p,
1253  Index r,
1254  Index c ) const
1255 {
1256  return ConstTensor5View::operator()(s,b,p,r,c);
1257 }
1258 
1264  const Range& b,
1265  Index p,
1266  Index r,
1267  Index c ) const
1268 {
1269  return ConstTensor5View::operator()(s,b,p,r,c);
1270 }
1271 
1277  Index b,
1278  const Range& p,
1279  Index r,
1280  Index c ) const
1281 {
1282  return ConstTensor5View::operator()(s,b,p,r,c);
1283 }
1284 
1290  Index b,
1291  Index p,
1292  const Range& r,
1293  Index c ) const
1294 {
1295  return ConstTensor5View::operator()(s,b,p,r,c);
1296 }
1297 
1303  Index b,
1304  Index p,
1305  Index r,
1306  const Range& c) const
1307 {
1308  return ConstTensor5View::operator()(s,b,p,r,c);
1309 }
1310 
1315  const Range& b,
1316  const Range& p,
1317  const Range& r,
1318  const Range& c)
1319 {
1320  return Tensor5View(mdata,
1321  msr, mbr, mpr, mrr, mcr,
1322  s, b, p, r, c);
1323 }
1324 
1328  const Range& b,
1329  const Range& p,
1330  const Range& r,
1331  Index c)
1332 {
1333  // Check that c is valid:
1334  assert( 0 <= c );
1335  assert( c < mcr.mextent );
1336 
1337  return Tensor4View(mdata +
1338  mcr.mstart + c * mcr.mstride,
1339  msr, mbr, mpr, mrr,
1340  s, b, p, r);
1341 }
1342 
1346  const Range& b,
1347  const Range& p,
1348  Index r,
1349  const Range& c)
1350 {
1351  // Check that r is valid:
1352  assert( 0 <= r );
1353  assert( r < mrr.mextent );
1354 
1355  return Tensor4View(mdata +
1356  mrr.mstart + r * mrr.mstride,
1357  msr, mbr, mpr, mcr,
1358  s, b, p, c);
1359 }
1360 
1364  const Range& b,
1365  Index p,
1366  const Range& r,
1367  const Range& c)
1368 {
1369  // Check that p is valid:
1370  assert( 0 <= p );
1371  assert( p < mpr.mextent );
1372 
1373  return Tensor4View(mdata +
1374  mpr.mstart + p * mpr.mstride,
1375  msr, mbr, mrr, mcr,
1376  s, b, r, c);
1377 }
1378 
1382  Index b,
1383  const Range& p,
1384  const Range& r,
1385  const Range& c)
1386 {
1387  // Check that b is valid:
1388  assert( 0 <= b );
1389  assert( b < mbr.mextent );
1390 
1391  return Tensor4View(mdata +
1392  mbr.mstart + b * mbr.mstride,
1393  msr, mpr, mrr, mcr,
1394  s, p, r, c);
1395 }
1396 
1400  const Range& b,
1401  const Range& p,
1402  const Range& r,
1403  const Range& c)
1404 {
1405  // Check that s is valid:
1406  assert( 0 <= s );
1407  assert( s < msr.mextent );
1408 
1409  return Tensor4View(mdata +
1410  msr.mstart + s * msr.mstride,
1411  mbr, mpr, mrr, mcr,
1412  b, p, r, c);
1413 }
1414 
1418  const Range& b,
1419  const Range& p,
1420  Index r,
1421  Index c)
1422 {
1423  // Check that r and c is valid:
1424  assert( 0 <= r );
1425  assert( 0 <= c );
1426  assert( r < mrr.mextent );
1427  assert( c < mcr.mextent );
1428 
1429  return Tensor3View(mdata +
1430  mrr.mstart + r * mrr.mstride +
1431  mcr.mstart + c * mcr.mstride,
1432  msr, mbr, mpr,
1433  s, b, p);
1434 }
1435 
1439  const Range& b,
1440  Index p,
1441  const Range& r,
1442  Index c)
1443 {
1444  // Check that p and c are valid:
1445  assert( 0 <= p );
1446  assert( 0 <= c );
1447  assert( p < mpr.mextent );
1448  assert( c < mcr.mextent );
1449 
1450  return Tensor3View(mdata +
1451  mpr.mstart + p * mpr.mstride +
1452  mcr.mstart + c * mcr.mstride,
1453  msr, mbr, mrr,
1454  s, b, r);
1455 }
1456 
1460  const Range& b,
1461  Index p,
1462  Index r,
1463  const Range& c)
1464 {
1465  // Check that p and r are valid:
1466  assert( 0 <= p );
1467  assert( 0 <= r );
1468  assert( p < mpr.mextent );
1469  assert( r < mrr.mextent );
1470 
1471  return Tensor3View(mdata +
1472  mpr.mstart + p * mpr.mstride +
1473  mrr.mstart + r * mrr.mstride,
1474  msr, mbr, mcr,
1475  s, b, c);
1476 }
1477 
1481  Index b,
1482  const Range& p,
1483  Index r,
1484  const Range& c)
1485 {
1486  // Check that b and r are valid:
1487  assert( 0 <= b );
1488  assert( 0 <= r );
1489  assert( b < mbr.mextent );
1490  assert( r < mrr.mextent );
1491 
1492  return Tensor3View(mdata +
1493  mbr.mstart + b * mbr.mstride +
1494  mrr.mstart + r * mrr.mstride,
1495  msr, mpr, mcr,
1496  s, p, c);
1497 }
1498 
1502  Index b,
1503  const Range& p,
1504  const Range& r,
1505  Index c)
1506 {
1507  // Check that b and c are valid:
1508  assert( 0 <= b );
1509  assert( 0 <= c );
1510  assert( b < mbr.mextent );
1511  assert( c < mcr.mextent );
1512 
1513  return Tensor3View(mdata +
1514  mbr.mstart + b * mbr.mstride +
1515  mcr.mstart + c * mcr.mstride,
1516  msr, mpr, mrr,
1517  s, p, r);
1518 }
1519 
1523  Index b,
1524  Index p,
1525  const Range& r,
1526  const Range& c)
1527 {
1528  // Check that b and p are valid:
1529  assert( 0 <= b );
1530  assert( 0 <= p );
1531  assert( b < mbr.mextent );
1532  assert( p < mpr.mextent );
1533 
1534  return Tensor3View(mdata +
1535  mbr.mstart + b * mbr.mstride +
1536  mpr.mstart + p * mpr.mstride,
1537  msr, mrr, mcr,
1538  s, r, c);
1539 }
1540 
1544  const Range& b,
1545  Index p,
1546  const Range& r,
1547  const Range& c)
1548 {
1549  // Check that s and p are valid:
1550  assert( 0 <= s );
1551  assert( 0 <= p );
1552  assert( s < msr.mextent );
1553  assert( p < mpr.mextent );
1554 
1555  return Tensor3View(mdata +
1556  msr.mstart + s * msr.mstride +
1557  mpr.mstart + p * mpr.mstride,
1558  mbr, mrr, mcr,
1559  b, r, c);
1560 }
1561 
1565  const Range& b,
1566  const Range& p,
1567  Index r,
1568  const Range& c)
1569 {
1570  // Check that s and r are valid:
1571  assert( 0 <= s );
1572  assert( 0 <= r );
1573  assert( s < msr.mextent );
1574  assert( r < mrr.mextent );
1575 
1576  return Tensor3View(mdata +
1577  msr.mstart + s * msr.mstride +
1578  mrr.mstart + r * mrr.mstride,
1579  mbr, mpr, mcr,
1580  b, p, c);
1581 }
1582 
1586  const Range& b,
1587  const Range& p,
1588  const Range& r,
1589  Index c)
1590 {
1591  // Check that s and c are valid:
1592  assert( 0 <= s );
1593  assert( 0 <= c );
1594  assert( s < msr.mextent );
1595  assert( c < mcr.mextent );
1596 
1597  return Tensor3View(mdata +
1598  msr.mstart + s * msr.mstride +
1599  mcr.mstart + c * mcr.mstride,
1600  mbr, mpr, mrr,
1601  b, p, r);
1602 }
1603 
1607  Index b,
1608  const Range& p,
1609  const Range& r,
1610  const Range& c)
1611 {
1612  // Check that s and b are valid:
1613  assert( 0 <= s );
1614  assert( 0 <= b );
1615  assert( s < msr.mextent );
1616  assert( b < mbr.mextent );
1617 
1618  return Tensor3View(mdata +
1619  msr.mstart + s * msr.mstride +
1620  mbr.mstart + b * mbr.mstride,
1621  mpr, mrr, mcr,
1622  p, r, c);
1623 }
1624 
1628  const Range& b,
1629  Index p,
1630  Index r,
1631  Index c)
1632 {
1633  // Check that p, r and c are valid:
1634  assert( 0 <= p );
1635  assert( 0 <= r );
1636  assert( 0 <= c );
1637  assert( p < mpr.mextent );
1638  assert( r < mrr.mextent );
1639  assert( c < mcr.mextent );
1640 
1641  return MatrixView(mdata +
1642  mpr.mstart + p * mpr.mstride +
1643  mrr.mstart + r * mrr.mstride +
1644  mcr.mstart + c * mcr.mstride,
1645  msr, mbr,
1646  s, b);
1647 }
1648 
1652  Index b,
1653  const Range& p,
1654  Index r,
1655  Index c)
1656 {
1657  // Check that b, r and c are valid:
1658  assert( 0 <= b );
1659  assert( 0 <= r );
1660  assert( 0 <= c );
1661  assert( b < mbr.mextent );
1662  assert( r < mrr.mextent );
1663  assert( c < mcr.mextent );
1664 
1665  return MatrixView(mdata +
1666  mbr.mstart + b * mbr.mstride +
1667  mrr.mstart + r * mpr.mstride +
1668  mcr.mstart + c * mcr.mstride,
1669  msr, mpr,
1670  s, p);
1671 }
1672 
1676  Index b,
1677  Index p,
1678  const Range& r,
1679  Index c)
1680 {
1681  // Check that b, p and c are valid:
1682  assert( 0 <= b );
1683  assert( 0 <= p );
1684  assert( 0 <= c );
1685  assert( b < mbr.mextent );
1686  assert( p < mpr.mextent );
1687  assert( c < mcr.mextent );
1688 
1689  return MatrixView(mdata +
1690  mbr.mstart + b * mbr.mstride +
1691  mpr.mstart + p * mpr.mstride +
1692  mcr.mstart + c * mcr.mstride,
1693  msr, mrr,
1694  s, r);
1695 }
1696 
1700  Index b,
1701  Index p,
1702  Index r,
1703  const Range& c)
1704 {
1705  // Check that b, p and r are valid:
1706  assert( 0 <= b );
1707  assert( 0 <= p );
1708  assert( 0 <= r );
1709  assert( b < mbr.mextent );
1710  assert( p < mpr.mextent );
1711  assert( r < mrr.mextent );
1712 
1713  return MatrixView(mdata +
1714  mbr.mstart + b * mbr.mstride +
1715  mpr.mstart + p * mpr.mstride +
1716  mrr.mstart + r * mrr.mstride,
1717  msr, mcr,
1718  s, c);
1719 }
1720 
1724  const Range& b,
1725  Index p,
1726  Index r,
1727  const Range& c)
1728 {
1729  // Check that s, p and r are valid:
1730  assert( 0 <= s );
1731  assert( 0 <= p );
1732  assert( 0 <= r );
1733  assert( s < msr.mextent );
1734  assert( p < mpr.mextent );
1735  assert( r < mrr.mextent );
1736 
1737  return MatrixView(mdata +
1738  msr.mstart + s * msr.mstride +
1739  mpr.mstart + p * mpr.mstride +
1740  mrr.mstart + r * mrr.mstride,
1741  mbr, mcr,
1742  b, c);
1743 }
1744 
1748  const Range& b,
1749  Index p,
1750  const Range& r,
1751  Index c )
1752 {
1753  // Check that s, p and c are valid:
1754  assert( 0 <= s );
1755  assert( 0 <= p );
1756  assert( 0 <= c );
1757  assert( s < msr.mextent );
1758  assert( p < mpr.mextent );
1759  assert( c < mcr.mextent );
1760 
1761  return MatrixView(mdata +
1762  msr.mstart + s * msr.mstride +
1763  mpr.mstart + p * mpr.mstride +
1764  mcr.mstart + c * mcr.mstride,
1765  mbr, mrr,
1766  b, r);
1767 }
1768 
1772  const Range& b,
1773  const Range& p,
1774  Index r,
1775  Index c )
1776 {
1777  // Check that s, r and c are valid:
1778  assert( 0 <= s );
1779  assert( 0 <= r );
1780  assert( 0 <= c );
1781  assert( s < msr.mextent );
1782  assert( r < mrr.mextent );
1783  assert( c < mcr.mextent );
1784 
1785  return MatrixView(mdata +
1786  msr.mstart + s * msr.mstride +
1787  mrr.mstart + r * mrr.mstride +
1788  mcr.mstart + c * mcr.mstride,
1789  mbr, mpr,
1790  b, p);
1791 }
1792 
1796  Index b,
1797  const Range& p,
1798  const Range& r,
1799  Index c )
1800 {
1801  // Check that s, b and c are valid:
1802  assert( 0 <= s );
1803  assert( 0 <= b );
1804  assert( 0 <= c );
1805  assert( s < msr.mextent );
1806  assert( b < mbr.mextent );
1807  assert( c < mcr.mextent );
1808 
1809  return MatrixView(mdata +
1810  msr.mstart + s * msr.mstride +
1811  mbr.mstart + b * mbr.mstride +
1812  mcr.mstart + c * mcr.mstride,
1813  mpr, mrr,
1814  p, r);
1815 }
1816 
1820  Index b,
1821  const Range& p,
1822  Index r,
1823  const Range& c)
1824 {
1825  // Check that s, b and r are valid:
1826  assert( 0 <= s );
1827  assert( 0 <= b );
1828  assert( 0 <= r );
1829  assert( s < msr.mextent );
1830  assert( b < mbr.mextent );
1831  assert( r < mrr.mextent );
1832 
1833  return MatrixView(mdata +
1834  msr.mstart + s * msr.mstride +
1835  mbr.mstart + b * mbr.mstride +
1836  mrr.mstart + r * mrr.mstride,
1837  mpr, mcr,
1838  p, c);
1839 }
1840 
1844  Index b,
1845  Index p,
1846  const Range& r,
1847  const Range& c)
1848 {
1849  // Check that s, b and p are valid:
1850  assert( 0 <= s );
1851  assert( 0 <= b );
1852  assert( 0 <= p );
1853  assert( s < msr.mextent );
1854  assert( b < mbr.mextent );
1855  assert( p < mpr.mextent );
1856 
1857  return MatrixView(mdata +
1858  msr.mstart + s * msr.mstride +
1859  mbr.mstart + b * mbr.mstride +
1860  mpr.mstart + p * mpr.mstride,
1861  mrr, mcr,
1862  r, c);
1863 }
1864 
1868  Index b,
1869  Index p,
1870  Index r,
1871  Index c)
1872 {
1873  // Check that b, p, r and c are valid:
1874  assert( 0 <= b );
1875  assert( 0 <= p );
1876  assert( 0 <= r );
1877  assert( 0 <= c );
1878  assert( b < mbr.mextent );
1879  assert( p < mpr.mextent );
1880  assert( r < mrr.mextent );
1881  assert( c < mcr.mextent );
1882 
1883  return VectorView(mdata +
1884  mbr.mstart + b * mbr.mstride +
1885  mpr.mstart + p * mpr.mstride +
1886  mrr.mstart + r * mrr.mstride +
1887  mcr.mstart + c * mcr.mstride,
1888  msr,
1889  s);
1890 }
1891 
1895  const Range& b,
1896  Index p,
1897  Index r,
1898  Index c)
1899 {
1900  // Check that s, p, r and c are valid:
1901  assert( 0 <= s );
1902  assert( 0 <= p );
1903  assert( 0 <= r );
1904  assert( 0 <= c );
1905  assert( s < msr.mextent );
1906  assert( p < mpr.mextent );
1907  assert( r < mrr.mextent );
1908  assert( c < mcr.mextent );
1909 
1910  return VectorView(mdata +
1911  msr.mstart + s * msr.mstride +
1912  mpr.mstart + p * mpr.mstride +
1913  mrr.mstart + r * mrr.mstride +
1914  mcr.mstart + c * mcr.mstride,
1915  mbr,
1916  b);
1917 }
1918 
1922  Index b,
1923  const Range& p,
1924  Index r,
1925  Index c)
1926 {
1927  // Check that s, b, r and c are valid:
1928  assert( 0 <= s );
1929  assert( 0 <= b );
1930  assert( 0 <= r );
1931  assert( 0 <= c );
1932  assert( s < msr.mextent );
1933  assert( b < mbr.mextent );
1934  assert( r < mrr.mextent );
1935  assert( c < mcr.mextent );
1936 
1937  return VectorView(mdata +
1938  msr.mstart + s * msr.mstride +
1939  mbr.mstart + b * mbr.mstride +
1940  mrr.mstart + r * mrr.mstride +
1941  mcr.mstart + c * mcr.mstride,
1942  mpr,
1943  p);
1944 }
1945 
1949  Index b,
1950  Index p,
1951  const Range& r,
1952  Index c)
1953 {
1954  // Check that s, b, p and c are valid:
1955  assert( 0 <= s );
1956  assert( 0 <= b );
1957  assert( 0 <= p );
1958  assert( 0 <= c );
1959  assert( s < msr.mextent );
1960  assert( b < mbr.mextent );
1961  assert( p < mpr.mextent );
1962  assert( c < mcr.mextent );
1963 
1964  return VectorView(mdata +
1965  msr.mstart + s * msr.mstride +
1966  mbr.mstart + b * mbr.mstride +
1967  mpr.mstart + p * mpr.mstride +
1968  mcr.mstart + c * mcr.mstride,
1969  mrr,
1970  r);
1971 }
1972 
1976  Index b,
1977  Index p,
1978  Index r,
1979  const Range& c)
1980 {
1981  // Check that s, b, p and r are valid:
1982  assert( 0 <= s );
1983  assert( 0 <= b );
1984  assert( 0 <= p );
1985  assert( 0 <= r );
1986  assert( s < msr.mextent );
1987  assert( b < mbr.mextent );
1988  assert( p < mpr.mextent );
1989  assert( r < mrr.mextent );
1990 
1991  return VectorView(mdata +
1992  msr.mstart + s * msr.mstride +
1993  mbr.mstart + b * mbr.mstride +
1994  mpr.mstart + p * mpr.mstride +
1995  mrr.mstart + r * mrr.mstride,
1996  mcr,
1997  c);
1998 }
1999 
2000 
2004 {
2005  return ConstTensor5View::begin();
2006 }
2007 
2010 {
2011  return ConstTensor5View::end();
2012 }
2013 
2016 {
2018  mbr, mpr, mrr, mcr),
2019  msr.mstride );
2020 }
2021 
2024 {
2025  return Iterator5D( Tensor4View(mdata + msr.mstart +
2026  (msr.mextent) * msr.mstride,
2027  mbr, mpr, mrr, mcr),
2028  msr.mstride );
2029 }
2030 
2036 {
2037  // Check that sizes are compatible:
2038  assert( msr.mextent == m.msr.mextent );
2039  assert( mbr.mextent == m.mbr.mextent );
2040  assert( mpr.mextent == m.mpr.mextent );
2041  assert( mrr.mextent == m.mrr.mextent );
2042  assert( mcr.mextent == m.mcr.mextent );
2043 
2044  copy( m.begin(), m.end(), begin() );
2045  return *this;
2046 }
2047 
2054 {
2055  // Check that sizes are compatible:
2056  assert( msr.mextent == m.msr.mextent );
2057  assert( mbr.mextent == m.mbr.mextent );
2058  assert( mpr.mextent == m.mpr.mextent );
2059  assert( mrr.mextent == m.mrr.mextent );
2060  assert( mcr.mextent == m.mcr.mextent );
2061 
2062  copy( m.begin(), m.end(), begin() );
2063  return *this;
2064 }
2065 
2070 {
2071  // Check that sizes are compatible:
2072  assert( msr.mextent == m.msr.mextent );
2073  assert( mbr.mextent == m.mbr.mextent );
2074  assert( mpr.mextent == m.mpr.mextent );
2075  assert( mrr.mextent == m.mrr.mextent );
2076  assert( mcr.mextent == m.mcr.mextent );
2077 
2078  copy( m.begin(), m.end(), begin() );
2079  return *this;
2080 }
2081 
2085 {
2086  copy( x, begin(), end() );
2087  return *this;
2088 }
2089 
2090 // Some little helper functions:
2091 //------------------------------
2092 
2095 {
2096  const Iterator5D es = end();
2097  for ( Iterator5D s = begin(); s != es ; ++s )
2098  {
2099  *s *= x;
2100  }
2101  return *this;
2102 }
2103 
2106 {
2107  const Iterator5D es = end();
2108  for ( Iterator5D s = begin(); s != es ; ++s )
2109  {
2110  *s /= x;
2111  }
2112  return *this;
2113 }
2114 
2117 {
2118  const Iterator5D es = end();
2119  for ( Iterator5D s = begin(); s != es ; ++s )
2120  {
2121  *s += x;
2122  }
2123  return *this;
2124 }
2125 
2128 {
2129  const Iterator5D es = end();
2130  for ( Iterator5D s = begin(); s != es ; ++s )
2131  {
2132  *s -= x;
2133  }
2134  return *this;
2135 }
2136 
2139 {
2140  assert( nshelves() == x.nshelves() );
2141  assert( nbooks() == x.nbooks() );
2142  assert( npages() == x.npages() );
2143  assert( nrows() == x.nrows() );
2144  assert( ncols() == x.ncols() );
2145  ConstIterator5D xs = x.begin();
2146  Iterator5D s = begin();
2147  const Iterator5D es = end();
2148  for ( ; s != es ; ++s, ++xs )
2149  {
2150  *s *= *xs;
2151  }
2152  return *this;
2153 }
2154 
2157 {
2158  assert( nshelves() == x.nshelves() );
2159  assert( nbooks() == x.nbooks() );
2160  assert( npages() == x.npages() );
2161  assert( nrows() == x.nrows() );
2162  assert( ncols() == x.ncols() );
2163  ConstIterator5D xs = x.begin();
2164  Iterator5D s = begin();
2165  const Iterator5D es = end();
2166  for ( ; s != es ; ++s, ++xs )
2167  {
2168  *s /= *xs;
2169  }
2170  return *this;
2171 }
2172 
2175 {
2176  assert( nshelves() == x.nshelves() );
2177  assert( nbooks() == x.nbooks() );
2178  assert( npages() == x.npages() );
2179  assert( nrows() == x.nrows() );
2180  assert( ncols() == x.ncols() );
2181  ConstIterator5D xs = x.begin();
2182  Iterator5D s = begin();
2183  const Iterator5D es = end();
2184  for ( ; s != es ; ++s, ++xs )
2185  {
2186  *s += *xs;
2187  }
2188  return *this;
2189 }
2190 
2193 {
2194  assert( nshelves() == x.nshelves() );
2195  assert( nbooks() == x.nbooks() );
2196  assert( npages() == x.npages() );
2197  assert( nrows() == x.nrows() );
2198  assert( ncols() == x.ncols() );
2199  ConstIterator5D xs = x.begin();
2200  Iterator5D s = begin();
2201  const Iterator5D es = end();
2202  for ( ; s != es ; ++s, ++xs )
2203  {
2204  *s -= *xs;
2205  }
2206  return *this;
2207 }
2208 
2211  ConstTensor5View( a.mdata,
2212  Range(0,1,
2213  a.mbr.mextent*
2214  a.mpr.mextent*
2215  a.mrr.mextent*
2216  a.mcr.mextent),
2217  a.mbr,
2218  a.mpr,
2219  a.mrr,
2220  a.mcr )
2221 {
2222  // Nothing to do here.
2223 }
2224 
2229 {
2230  // Nothing to do here.
2231 }
2232 
2237  const Range& sr,
2238  const Range& br,
2239  const Range& pr,
2240  const Range& rr,
2241  const Range& cr) :
2242  ConstTensor5View(data, sr, br, pr, rr, cr)
2243 {
2244  // Nothing to do here.
2245 }
2246 
2268  const Range& ps,
2269  const Range& pb,
2270  const Range& pp,
2271  const Range& pr,
2272  const Range& pc,
2273  const Range& ns,
2274  const Range& nb,
2275  const Range& np,
2276  const Range& nr,
2277  const Range& nc) :
2278  ConstTensor5View(data, ps, pb, pp, pr, pc, ns, nb, np, nr, nc)
2279 {
2280  // Nothing to do here.
2281 }
2282 
2287 void copy(ConstIterator5D origin,
2288  const ConstIterator5D& end,
2289  Iterator5D target)
2290 {
2291  for ( ; origin != end ; ++origin, ++target )
2292  {
2293  // We use the copy function for the next smaller rank of tensor
2294  // recursively:
2295  copy( origin->begin(), origin->end(), target->begin() );
2296  }
2297 }
2298 
2300 void copy(Numeric x,
2301  Iterator5D target,
2302  const Iterator5D& end)
2303 {
2304  for ( ; target != end ; ++target )
2305  {
2306  // We use the copy function for the next smaller rank of tensor
2307  // recursively:
2308  copy( x, target->begin(), target->end() );
2309  }
2310 }
2311 
2312 
2313 // Functions for Tensor5:
2314 // ---------------------
2315 
2319 {
2320  // Nothing to do here. However, note that the default constructor
2321  // for Tensor5View has been called in the initializer list. That is
2322  // crucial, otherwise internal range objects will not be properly
2323  // initialized.
2324 }
2325 
2329  Tensor5View( new Numeric[s*b*p*r*c],
2330  Range( 0, s, b*p*r*c ),
2331  Range( 0, b, p*r*c ),
2332  Range( 0, p, r*c ),
2333  Range( 0, r, c ),
2334  Range( 0, c) )
2335 {
2336  // Nothing to do here.
2337 }
2338 
2341  Tensor5View( new Numeric[s*b*p*r*c],
2342  Range( 0, s, b*p*r*c ),
2343  Range( 0, b, p*r*c ),
2344  Range( 0, p, r*c ),
2345  Range( 0, r, c ),
2346  Range( 0, c) )
2347 {
2348  // Here we can access the raw memory directly, for slightly
2349  // increased efficiency:
2350  const Numeric *stop = mdata + s*b*p*r*c;
2351  for ( Numeric *x = mdata; x < stop; ++x )
2352  *x = fill;
2353 }
2354 
2358  Tensor5View( new Numeric[m.nshelves()*m.nbooks()*m.npages()*m.nrows()*m.ncols()],
2359  Range( 0, m.nshelves(), m.nbooks()*m.npages()*m.nrows()*m.ncols() ),
2360  Range( 0, m.nbooks(), m.npages()*m.nrows()*m.ncols() ),
2361  Range( 0, m.npages(), m.nrows()*m.ncols() ),
2362  Range( 0, m.nrows(), m.ncols() ),
2363  Range( 0, m.ncols() ) )
2364 {
2365  copy( m.begin(), m.end(), begin() );
2366 }
2367 
2371  Tensor5View( new Numeric[m.nshelves()*m.nbooks()*m.npages()*m.nrows()*m.ncols()],
2372  Range( 0, m.nshelves(), m.nbooks()*m.npages()*m.nrows()*m.ncols() ),
2373  Range( 0, m.nbooks(), m.npages()*m.nrows()*m.ncols() ),
2374  Range( 0, m.npages(), m.nrows()*m.ncols() ),
2375  Range( 0, m.nrows(), m.ncols() ),
2376  Range( 0, m.ncols() ) )
2377 {
2378  // There is a catch here: If m is an empty tensor, then it will have
2379  // dimensions of size 0. But these are used to initialize the stride
2380  // for higher dimensions! Thus, this method has to be consistent
2381  // with the behaviour of Range::Range. For now, Range::Range allows
2382  // also stride 0.
2383  copy( m.begin(), m.end(), begin() );
2384 }
2385 
2387 
2411 {
2412  // cout << "Tensor5 copy: m = " << m.nrows() << " " << m.ncols() << "\n";
2413  // cout << " n = " << nrows() << " " << ncols() << "\n";
2414 
2415  resize( m.msr.mextent,
2416  m.mbr.mextent,
2417  m.mpr.mextent,
2418  m.mrr.mextent,
2419  m.mcr.mextent );
2420  copy( m.begin(), m.end(), begin() );
2421  return *this;
2422 }
2423 
2427 {
2428  copy( x, begin(), end() );
2429  return *this;
2430 }
2431 
2436 {
2437  assert( 0 <= s );
2438  assert( 0 <= b );
2439  assert( 0 <= p );
2440  assert( 0 <= r );
2441  assert( 0 <= c );
2442 
2443  if ( msr.mextent != s ||
2444  mbr.mextent != b ||
2445  mpr.mextent != p ||
2446  mrr.mextent != r ||
2447  mcr.mextent != c )
2448  {
2449  delete[] mdata;
2450  mdata = new Numeric[s*b*p*r*c];
2451 
2452  msr.mstart = 0;
2453  msr.mextent = s;
2454  msr.mstride = b*p*r*c;
2455 
2456  mbr.mstart = 0;
2457  mbr.mextent = b;
2458  mbr.mstride = p*r*c;
2459 
2460  mpr.mstart = 0;
2461  mpr.mextent = p;
2462  mpr.mstride = r*c;
2463 
2464  mrr.mstart = 0;
2465  mrr.mextent = r;
2466  mrr.mstride = c;
2467 
2468  mcr.mstart = 0;
2469  mcr.mextent = c;
2470  mcr.mstride = 1;
2471  }
2472 }
2473 
2477 {
2478 // cout << "Destroying a Tensor5:\n"
2479 // << *this << "\n........................................\n";
2480  delete[] mdata;
2481 }
2482 
2483 
2500  double (&my_func)(double),
2501  ConstTensor5View x )
2502 {
2503  // Check dimensions:
2504  assert( y.nshelves() == x.nshelves() );
2505  assert( y.nbooks() == x.nbooks() );
2506  assert( y.npages() == x.npages() );
2507  assert( y.nrows() == x.nrows() );
2508  assert( y.ncols() == x.ncols() );
2509 
2510  const ConstIterator5D xe = x.end();
2511  ConstIterator5D xi = x.begin();
2512  Iterator5D yi = y.begin();
2513  for ( ; xi != xe; ++xi, ++yi )
2514  {
2515  // Use the transform function of lower dimensional tensors
2516  // recursively:
2517  transform( *yi, my_func, *xi );
2518  }
2519 }
2520 
2523 {
2524  const ConstIterator5D xe = x.end();
2525  ConstIterator5D xi = x.begin();
2526 
2527  // Initial value for max:
2528  Numeric themax = max(*xi);
2529  ++xi;
2530 
2531  for ( ; xi != xe ; ++xi )
2532  {
2533  // Use the max function of lower dimensional tensors
2534  // recursively:
2535  Numeric maxi = max(*xi);
2536  if ( maxi > themax )
2537  themax = maxi;
2538  }
2539 
2540  return themax;
2541 }
2542 
2545 {
2546  const ConstIterator5D xe = x.end();
2547  ConstIterator5D xi = x.begin();
2548 
2549  // Initial value for min:
2550  Numeric themin = min(*xi);
2551  ++xi;
2552 
2553  for ( ; xi != xe ; ++xi )
2554  {
2555  // Use the min function of lower dimensional tensors
2556  // recursively:
2557  Numeric mini = min(*xi);
2558  if ( mini < themin )
2559  themin = mini;
2560  }
2561 
2562  return themin;
2563 }
2564 
2566 // Helper function for debugging
2567 #ifndef NDEBUG
2568 
2586  Index r, Index c)
2587 {
2588  return tv(s, b, p, r, c);
2589 }
2590 
2591 #endif
2592 
ConstTensor5View::nbooks
Index nbooks() const
Returns the number of books.
Definition: matpackV.cc:38
MatrixView
The MatrixView class.
Definition: matpackI.h:668
exceptions.h
The declarations of all the exception classes.
ConstTensor4View::end
ConstIterator4D end() const
Return const iterator behind last book.
Definition: matpackIV.cc:419
Tensor5View::operator+=
Tensor5View & operator+=(Numeric x)
Addition of scalar.
Definition: matpackV.cc:2116
Tensor5::Tensor5
Tensor5()
Default constructor.
Definition: matpackV.cc:2317
Tensor5View::operator-=
Tensor5View & operator-=(Numeric x)
Subtraction of scalar.
Definition: matpackV.cc:2127
ConstTensor5View::ncols
Index ncols() const
Returns the number of columns.
Definition: matpackV.cc:56
ConstTensor5View::mbr
Range mbr
The book range of mdata that is actually used.
Definition: matpackV.h:258
ConstTensor5View::operator()
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:64
Tensor5::operator=
Tensor5 & operator=(const Tensor5 &x)
Assignment operator from another tensor.
Definition: matpackV.cc:2410
Range::mstart
Index mstart
The start index.
Definition: matpackI.h:204
ConstTensor5View::msr
Range msr
The shelf range of mdata that is actually used.
Definition: matpackV.h:256
Iterator5D
Implementation of Tensors of Rank 5.
Definition: matpackV.h:38
ConstTensor5View::npages
Index npages() const
Returns the number of pages.
Definition: matpackV.cc:44
ConstTensor5View::begin
ConstIterator5D begin() const
Return const iterator to first shelf.
Definition: matpackV.cc:789
ConstTensor4View
A constant view of a Tensor4.
Definition: matpackIV.h:149
Tensor3View
The Tensor3View class.
Definition: matpackIII.h:234
Tensor5View::operator()
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:912
Tensor5View::operator/=
Tensor5View & operator/=(Numeric x)
Division by scalar.
Definition: matpackV.cc:2105
Tensor5::resize
void resize(Index s, Index b, Index p, Index r, Index c)
Resize function.
Definition: matpackV.cc:2435
transform
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:2499
Tensor5View::get_c_array
const Numeric * get_c_array() const
Conversion to plain C-array.
Definition: matpackV.cc:775
Tensor5::~Tensor5
virtual ~Tensor5()
Destructor for Tensor5.
Definition: matpackV.cc:2476
ConstTensor5View::mrr
Range mrr
The row range of mdata that is actually used.
Definition: matpackV.h:262
VectorView
The VectorView class.
Definition: matpackI.h:373
Tensor5View::begin
ConstIterator5D begin() const
Return const iterator to first shelf.
Definition: matpackV.cc:2003
ConstTensor4View::begin
ConstIterator4D begin() const
Return const iterator to first book.
Definition: matpackIV.cc:411
ns
#define ns
Definition: continua.cc:14564
Numeric
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:33
Tensor5View
The Tensor5View class.
Definition: matpackV.h:278
Tensor5View::end
ConstIterator5D end() const
Return const iterator behind last shelf.
Definition: matpackV.cc:2009
Tensor4View::end
ConstIterator4D end() const
Return const iterator behind last book.
Definition: matpackIV.cc:1000
ConstTensor5View::ConstTensor5View
ConstTensor5View()
Default constructor.
Definition: matpackV.cc:823
copy
void copy(ConstIterator5D origin, const ConstIterator5D &end, Iterator5D target)
Copy data between begin and end to target.
Definition: matpackV.cc:2287
ConstTensor5View::mcr
Range mcr
The column range of mdata that is actually used.
Definition: matpackV.h:264
max
Numeric max(const ConstTensor5View &x)
Max function, tensor version.
Definition: matpackV.cc:2522
ConstMatrixView
A constant view of a Matrix.
Definition: matpackI.h:591
Tensor4View::begin
ConstIterator4D begin() const
Return const iterator to first book.
Definition: matpackIV.cc:994
Tensor5
The Tensor5 class.
Definition: matpackV.h:443
Tensor5View::Tensor5View
Tensor5View()
Default constructor.
Definition: matpackV.cc:2227
debug_tensor5view_get_elem
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:2585
Range
The range class.
Definition: matpackI.h:148
Range::mextent
Index mextent
The number of elements.
Definition: matpackI.h:207
ConstTensor5View::nrows
Index nrows() const
Returns the number of rows.
Definition: matpackV.cc:50
Tensor5View::operator=
Tensor5View & operator=(const ConstTensor5View &v)
Assignment operator.
Definition: matpackV.cc:2035
matpackV.h
ConstTensor5View::mpr
Range mpr
The page range of mdata that is actually used.
Definition: matpackV.h:260
ConstTensor5View::nshelves
Index nshelves() const
Returns the number of shelves.
Definition: matpackV.cc:32
ConstTensor3View
A constant view of a Tensor3.
Definition: matpackIII.h:147
Tensor4View
The Tensor4View class.
Definition: matpackIV.h:245
ConstTensor5View::mdata
Numeric * mdata
Pointer to the plain C array that holds the data.
Definition: matpackV.h:266
operator<<
ostream & operator<<(ostream &os, const ConstTensor5View &v)
Output operator.
Definition: matpackV.cc:885
min
Numeric min(const ConstTensor5View &x)
Min function, tensor version.
Definition: matpackV.cc:2544
Index
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
ConstIterator5D
Const version of Iterator5D.
Definition: matpackV.h:92
Range::mstride
Index mstride
The stride.
Definition: matpackI.h:209
ConstVectorView
A constant view of a Vector.
Definition: matpackI.h:300
ConstTensor5View::end
ConstIterator5D end() const
Return const iterator behind last shelf.
Definition: matpackV.cc:797
Tensor5View::operator*=
Tensor5View & operator*=(Numeric x)
Multiplication by scalar.
Definition: matpackV.cc:2094
ConstTensor5View
A constant view of a Tensor5.
Definition: matpackV.h:160