ARTS  1.0.222
matpackIII.h
Go to the documentation of this file.
1 /* Copyright (C) 2001 Stefan Buehler <sbuehler@uni-bremen.de>
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 
27 #ifndef matpackIII_h
28 #define matpackIII_h
29 
30 #include <iomanip>
31 #include "matpackI.h"
32 
35 class Iterator3D {
36 public:
37  // Constructors:
38  Iterator3D();
39  Iterator3D(const Iterator3D& o);
40  Iterator3D(const MatrixView& x, Index stride);
41 
42  // Operators:
44  bool operator!=(const Iterator3D& other) const;
47 
48 private:
53 };
54 
57 public:
58  // Constructors:
61  ConstIterator3D(const ConstMatrixView& x, Index stride);
62 
63  // Operators:
65  bool operator!=(const ConstIterator3D& other) const;
66  const ConstMatrixView* operator->() const;
67  const ConstMatrixView& operator*() const;
68 
69 private:
74 };
75 
76 
77 // Declare class Tensor3:
78 class Tensor3;
79 
80 
94 public:
95  // Member functions:
96  Index npages() const;
97  Index nrows() const;
98  Index ncols() const;
99 
100  // Const index operators:
101  ConstTensor3View operator()( const Range& p, const Range& r, const Range& c ) const;
102 
103  ConstMatrixView operator()( const Range& p, const Range& r, Index c ) const;
104  ConstMatrixView operator()( const Range& p, Index r, const Range& c ) const;
105  ConstMatrixView operator()( Index p, const Range& r, const Range& c ) const;
106 
107  ConstVectorView operator()( Index p, Index r, const Range& c ) const;
108  ConstVectorView operator()( Index p, const Range& r, Index c ) const;
109  ConstVectorView operator()( const Range& p, Index r, Index c ) const;
110 
111  Numeric operator()( Index p, Index r, Index c ) const;
112 
113  // Functions returning iterators:
114  ConstIterator3D begin() const;
115  ConstIterator3D end() const;
116 
117  // Friends:
118  friend class Tensor3View;
119 
120 
121 protected:
122  // Constructors:
125  const Range& p, const Range& r, const Range& c);
127  const Range& pp, const Range& pr, const Range& pc,
128  const Range& np, const Range& nr, const Range& nc);
129 
130  // Data members:
131  // -------------
140 };
141 
152 public:
153 
154  // Const index operators:
155  ConstTensor3View operator()( const Range& p, const Range& r, const Range& c ) const;
156 
157  ConstMatrixView operator()( const Range& p, const Range& r, Index c ) const;
158  ConstMatrixView operator()( const Range& p, Index r, const Range& c ) const;
159  ConstMatrixView operator()( Index p, const Range& r, const Range& c ) const;
160 
161  ConstVectorView operator()( Index p, Index r, const Range& c ) const;
162  ConstVectorView operator()( Index p, const Range& r, Index c ) const;
163  ConstVectorView operator()( const Range& p, Index r, Index c ) const;
164 
165  Numeric operator()( Index p, Index r, Index c ) const;
166 
167  // Non-const index operators:
168 
169  Tensor3View operator()( const Range& p, const Range& r, const Range& c );
170 
171  MatrixView operator()( const Range& p, const Range& r, Index c );
172  MatrixView operator()( const Range& p, Index r, const Range& c );
173  MatrixView operator()( Index p, const Range& r, const Range& c );
174 
175  VectorView operator()( Index p, Index r, const Range& c );
176  VectorView operator()( Index p, const Range& r, Index c );
177  VectorView operator()( const Range& p, Index r, Index c );
178 
179  Numeric& operator()( Index p, Index r, Index c );
180 
181  // Functions returning const iterators:
182  ConstIterator3D begin() const;
183  ConstIterator3D end() const;
184  // Functions returning iterators:
185  Iterator3D begin();
186  Iterator3D end();
187 
188  // Assignment operators:
190  Tensor3View& operator=(const Tensor3View& v);
191  Tensor3View& operator=(const Tensor3& v);
193 
194  // Other operators:
199 
204 
205  // Friends:
206 // friend class VectorView;
207 // friend ConstTensor3View transpose(ConstTensor3View m);
208 // friend Tensor3View transpose(Tensor3View m);
209 
210 protected:
211  // Constructors:
212  Tensor3View();
213  Tensor3View(Numeric *data, const Range& p, const Range& r, const Range& c);
214  Tensor3View(Numeric *data,
215  const Range& pp, const Range& pr, const Range& pc,
216  const Range& np, const Range& nr, const Range& nc);
217 };
218 
227 class Tensor3 : public Tensor3View {
228 public:
229  // Constructors:
230  Tensor3();
231  Tensor3(Index p, Index r, Index c);
232  Tensor3(Index p, Index r, Index c, Numeric fill);
233  Tensor3(const ConstTensor3View& v);
234  Tensor3(const Tensor3& v);
235 
236  // Assignment operators:
237  Tensor3& operator=(const Tensor3& x);
239 
240  // Resize function:
241  void resize(Index p, Index r, Index c);
242 
243  // Destructor:
244  ~Tensor3();
245 };
246 
247 
248 // Function declarations:
249 // ----------------------
250 
251 inline void copy(ConstIterator3D origin,
252  const ConstIterator3D& end,
253  Iterator3D target);
254 
255 inline void copy(Numeric x,
256  Iterator3D target,
257  const Iterator3D& end);
258 
259 
260 
261 // Declare the existance of class Array:
262 template<class base>
263 class Array;
264 
267 
268 
269 
270 // Functions for Iterator3D
271 // ------------------------
272 
275 {
276  // Nothing to do here.
277 }
278 
281  msv(o.msv), mstride(o.mstride)
282 {
283  // Nothing to do here.
284 }
285 
287 inline Iterator3D::Iterator3D(const MatrixView& x, Index stride) :
288  msv(x), mstride(stride)
289 {
290  // Nothing to do here.
291 }
292 
295 {
296  msv.mdata += mstride;
297  return *this;
298 }
299 
301 inline bool Iterator3D::operator!=(const Iterator3D& other) const
302 {
303  if ( msv.mdata +
304  msv.mrr.mstart +
305  msv.mcr.mstart
306  !=
307  other.msv.mdata +
308  other.msv.mrr.mstart +
309  other.msv.mcr.mstart )
310  return true;
311  else
312  return false;
313 }
314 
318 {
319  return &msv;
320 }
321 
324 {
325  return msv;
326 }
327 
328 // Functions for ConstIterator3D
329 // -----------------------------
330 
333 {
334  // Nothing to do here.
335 }
336 
339  msv(o.msv), mstride(o.mstride)
340 {
341  // Nothing to do here.
342 }
343 
346  msv(x), mstride(stride)
347 {
348  // Nothing to do here.
349 }
350 
353 {
354  msv.mdata += mstride;
355  return *this;
356 }
357 
359 inline bool ConstIterator3D::operator!=(const ConstIterator3D& other) const
360 {
361  if ( msv.mdata +
362  msv.mrr.mstart +
363  msv.mcr.mstart
364  !=
365  other.msv.mdata +
366  other.msv.mrr.mstart +
367  other.msv.mcr.mstart )
368  return true;
369  else
370  return false;
371 }
372 
376 {
377  return &msv;
378 }
379 
382 {
383  return msv;
384 }
385 
386 
387 
388 // Functions for ConstTensor3View:
389 // ------------------------------
390 
393 {
394  return mpr.mextent;
395 }
396 
399 {
400  return mrr.mextent;
401 }
402 
405 {
406  return mcr.mextent;
407 }
408 
413  const Range& r,
414  const Range& c) const
415 {
416  return ConstTensor3View(mdata, mpr, mrr, mcr, p, r, c);
417 }
418 
422  const Range& r,
423  Index c) const
424 {
425  // Check that c is valid:
426  assert( 0 <= c );
427  assert( c < mcr.mextent );
428 
429  return ConstMatrixView(mdata + mcr.mstart + c*mcr.mstride,
430  mpr, mrr,
431  p, r);
432 }
433 
437  Index r,
438  const Range& c) const
439 {
440  // Check that r is valid:
441  assert( 0 <= r );
442  assert( r < mrr.mextent );
443 
444  return ConstMatrixView(mdata + mrr.mstart + r*mrr.mstride,
445  mpr, mcr,
446  p, c);
447 }
448 
452  const Range& r,
453  const Range& c) const
454 {
455  // Check that p is valid:
456  assert( 0 <= p );
457  assert( p < mpr.mextent );
458 
459  return ConstMatrixView(mdata + mpr.mstart + p*mpr.mstride,
460  mrr, mcr,
461  r, c);
462 }
463 
467  Index r,
468  const Range& c) const
469 {
470  // Check that p and r are valid:
471  assert( 0 <= p );
472  assert( 0 <= r );
473  assert( p < mpr.mextent );
474  assert( r < mrr.mextent );
475 
476  return ConstVectorView(mdata +
477  mpr.mstart + p*mpr.mstride +
478  mrr.mstart + r*mrr.mstride,
479  mcr, c);
480 }
481 
485  const Range& r,
486  Index c) const
487 {
488  // Check that p and c are valid:
489  assert( 0 <= p );
490  assert( 0 <= c );
491  assert( p < mpr.mextent );
492  assert( c < mcr.mextent );
493 
494  return ConstVectorView(mdata +
495  mpr.mstart + p*mpr.mstride +
496  mcr.mstart + c*mcr.mstride,
497  mrr, r);
498 }
499 
503  Index r,
504  Index c) const
505 {
506  // Check that r and c are valid:
507  assert( 0 <= r );
508  assert( 0 <= c );
509  assert( r < mrr.mextent );
510  assert( c < mcr.mextent );
511 
512  return ConstVectorView(mdata +
513  mrr.mstart + r*mrr.mstride +
514  mcr.mstart + c*mcr.mstride,
515  mpr, p);
516 }
517 
520 {
521  // Check if indices are valid:
522  assert( 0<=p );
523  assert( 0<=r );
524  assert( 0<=c );
525  assert( p<mpr.mextent );
526  assert( r<mrr.mextent );
527  assert( c<mcr.mextent );
528 
529  return *( mdata +
530  mpr.mstart + p*mpr.mstride +
531  mrr.mstart + r*mrr.mstride +
532  mcr.mstart + c*mcr.mstride );
533 }
534 
537 {
539  mrr,
540  mcr),
541  mpr.mstride);
542 }
543 
546 {
549  mrr,
550  mcr),
551  mpr.mstride );
552 }
553 
557  mpr(0,0,1), mrr(0,0,1), mcr(0,0,1), mdata(NULL)
558 {
559  // Nothing to do here.
560 }
561 
567  const Range& pr,
568  const Range& rr,
569  const Range& cr) :
570  mpr(pr),
571  mrr(rr),
572  mcr(cr),
573  mdata(data)
574 {
575  // Nothing to do here.
576 }
577 
586  const Range& pp,
587  const Range& pr,
588  const Range& pc,
589  const Range& np,
590  const Range& nr,
591  const Range& nc) :
592  mpr(pp,np),
593  mrr(pr,nr),
594  mcr(pc,nc),
595  mdata(data)
596 {
597  // Nothing to do here.
598 }
599 
603 inline std::ostream& operator<<(std::ostream& os, const ConstTensor3View& v)
604 {
605  // Page iterators:
606  ConstIterator3D ip=v.begin();
607  const ConstIterator3D end_page=v.end();
608 
609  if ( ip!=end_page )
610  {
611  os << *ip;
612  ++ip;
613  }
614 
615  for ( ; ip!=end_page; ++ip )
616  {
617  os << "\n\n";
618  os << *ip;
619  }
620 
621  return os;
622 }
623 
624 
625 // Functions for Tensor3View:
626 // -------------------------
627 
633  const Range& r,
634  const Range& c) const
635 {
636  return ConstTensor3View::operator()(p,r,c);
637 }
638 
644  const Range& r,
645  Index c) const
646 {
647  return ConstTensor3View::operator()(p,r,c);
648 }
649 
655  Index r,
656  const Range& c) const
657 {
658  return ConstTensor3View::operator()(p,r,c);
659 }
660 
666  const Range& r,
667  const Range& c) const
668 {
669  return ConstTensor3View::operator()(p,r,c);
670 }
671 
677  Index r,
678  const Range& c) const
679 {
680  return ConstTensor3View::operator()(p,r,c);
681 }
682 
688  const Range& r,
689  Index c) const
690 {
691  return ConstTensor3View::operator()(p,r,c);
692 }
693 
699  Index r,
700  Index c) const
701 {
702  return ConstTensor3View::operator()(p,r,c);
703 }
704 
708 {
709  return ConstTensor3View::operator()(p,r,c);
710 }
711 
716  const Range& r,
717  const Range& c)
718 {
719  return Tensor3View(mdata, mpr, mrr, mcr, p, r, c);
720 }
721 
725  const Range& r,
726  Index c)
727 {
728  // Check that c is valid:
729  assert( 0 <= c );
730  assert( c < mcr.mextent );
731 
732  return MatrixView(mdata + mcr.mstart + c*mcr.mstride,
733  mpr, mrr,
734  p, r);
735 }
736 
740  Index r,
741  const Range& c)
742 {
743  // Check that r is valid:
744  assert( 0 <= r );
745  assert( r < mrr.mextent );
746 
747  return MatrixView(mdata + mrr.mstart + r*mrr.mstride,
748  mpr, mcr,
749  p, c);
750 }
751 
755  const Range& r,
756  const Range& c)
757 {
758  // Check that p is valid:
759  assert( 0 <= p );
760  assert( p < mpr.mextent );
761 
762  return MatrixView(mdata + mpr.mstart + p*mpr.mstride,
763  mrr, mcr,
764  r, c);
765 }
766 
770  Index r,
771  const Range& c)
772 {
773  // Check that p and r are valid:
774  assert( 0 <= p );
775  assert( 0 <= r );
776  assert( p < mpr.mextent );
777  assert( r < mrr.mextent );
778 
779  return VectorView(mdata +
780  mpr.mstart + p*mpr.mstride +
781  mrr.mstart + r*mrr.mstride,
782  mcr, c);
783 }
784 
788  const Range& r,
789  Index c)
790 {
791  // Check that p and c are valid:
792  assert( 0 <= p );
793  assert( 0 <= c );
794  assert( p < mpr.mextent );
795  assert( c < mcr.mextent );
796 
797  return VectorView(mdata +
798  mpr.mstart + p*mpr.mstride +
799  mcr.mstart + c*mcr.mstride,
800  mrr, r);
801 }
802 
806  Index r,
807  Index c)
808 {
809  // Check that r and r are valid:
810  assert( 0 <= r );
811  assert( 0 <= c );
812  assert( r < mrr.mextent );
813  assert( c < mcr.mextent );
814 
815  return VectorView(mdata +
816  mrr.mstart + r*mrr.mstride +
817  mcr.mstart + c*mcr.mstride,
818  mpr, p);
819 }
820 
823 {
824  // Check if indices are valid:
825  assert( 0<=p );
826  assert( 0<=r );
827  assert( 0<=c );
828  assert( p<mpr.mextent );
829  assert( r<mrr.mextent );
830  assert( c<mcr.mextent );
831 
832  return *( mdata +
833  mpr.mstart + p*mpr.mstride +
834  mrr.mstart + r*mrr.mstride +
835  mcr.mstart + c*mcr.mstride );
836 }
837 
841 {
842  return ConstTensor3View::begin();
843 }
844 
847 {
848  return ConstTensor3View::end();
849 }
850 
853 {
855  mrr,
856  mcr),
857  mpr.mstride);
858 }
859 
862 {
863  return Iterator3D( MatrixView(mdata + mpr.mstart +
865  mrr,
866  mcr),
867  mpr.mstride );
868 }
869 
875 {
876  // Check that sizes are compatible:
877  assert(mpr.mextent==m.mpr.mextent);
878  assert(mrr.mextent==m.mrr.mextent);
879  assert(mcr.mextent==m.mcr.mextent);
880 
881  copy( m.begin(), m.end(), begin() );
882  return *this;
883 }
884 
891 {
892  // Check that sizes are compatible:
893  assert(mpr.mextent==m.mpr.mextent);
894  assert(mrr.mextent==m.mrr.mextent);
895  assert(mcr.mextent==m.mcr.mextent);
896 
897  copy( m.begin(), m.end(), begin() );
898  return *this;
899 }
900 
905 {
906  // Check that sizes are compatible:
907  assert(mpr.mextent==m.mpr.mextent);
908  assert(mrr.mextent==m.mrr.mextent);
909  assert(mcr.mextent==m.mcr.mextent);
910 
911  copy( m.begin(), m.end(), begin() );
912  return *this;
913 }
914 
918 {
919  copy( x, begin(), end() );
920  return *this;
921 }
922 
923 // Some little helper functions:
924 //------------------------------
925 
927 {
928  return x+y;
929 }
930 
933 {
934  const Iterator3D ep=end();
935  for ( Iterator3D p=begin(); p!=ep ; ++p )
936  {
937  *p *= x;
938  }
939  return *this;
940 }
941 
944 {
945  const Iterator3D ep=end();
946  for ( Iterator3D p=begin(); p!=ep ; ++p )
947  {
948  *p /= x;
949  }
950  return *this;
951 }
952 
955 {
956  const Iterator3D ep=end();
957  for ( Iterator3D p=begin(); p!=ep ; ++p )
958  {
959  *p += x;
960  }
961  return *this;
962 }
963 
966 {
967  const Iterator3D ep=end();
968  for ( Iterator3D p=begin(); p!=ep ; ++p )
969  {
970  *p -= x;
971  }
972  return *this;
973 }
974 
977 {
978  assert( npages() == x.npages() );
979  assert( nrows() == x.nrows() );
980  assert( ncols() == x.ncols() );
981  ConstIterator3D xp = x.begin();
982  Iterator3D p = begin();
983  const Iterator3D ep = end();
984  for ( ; p!=ep ; ++p,++xp )
985  {
986  *p *= *xp;
987  }
988  return *this;
989 }
990 
993 {
994  assert( npages() == x.npages() );
995  assert( nrows() == x.nrows() );
996  assert( ncols() == x.ncols() );
997  ConstIterator3D xp = x.begin();
998  Iterator3D p = begin();
999  const Iterator3D ep = end();
1000  for ( ; p!=ep ; ++p,++xp )
1001  {
1002  *p /= *xp;
1003  }
1004  return *this;
1005 }
1006 
1009 {
1010  assert( npages() == x.npages() );
1011  assert( nrows() == x.nrows() );
1012  assert( ncols() == x.ncols() );
1013  ConstIterator3D xp = x.begin();
1014  Iterator3D p = begin();
1015  const Iterator3D ep = end();
1016  for ( ; p!=ep ; ++p,++xp )
1017  {
1018  *p += *xp;
1019  }
1020  return *this;
1021 }
1022 
1025 {
1026  assert( npages() == x.npages() );
1027  assert( nrows() == x.nrows() );
1028  assert( ncols() == x.ncols() );
1029  ConstIterator3D xp = x.begin();
1030  Iterator3D p = begin();
1031  const Iterator3D ep = end();
1032  for ( ; p!=ep ; ++p,++xp )
1033  {
1034  *p -= *xp;
1035  }
1036  return *this;
1037 }
1038 
1043 {
1044  // Nothing to do here.
1045 }
1046 
1051  const Range& pr,
1052  const Range& rr,
1053  const Range& cr) :
1054  ConstTensor3View(data, pr, rr, cr)
1055 {
1056  // Nothing to do here.
1057 }
1058 
1071  const Range& pp,
1072  const Range& pr,
1073  const Range& pc,
1074  const Range& np,
1075  const Range& nr,
1076  const Range& nc) :
1077  ConstTensor3View(data,pp,pr,pc,np,nr,nc)
1078 {
1079  // Nothing to do here.
1080 }
1081 
1086 inline void copy(ConstIterator3D origin,
1087  const ConstIterator3D& end,
1088  Iterator3D target)
1089 {
1090  for ( ; origin!=end ; ++origin,++target )
1091  {
1092  // We use the copy function for the next smaller rank of tensor
1093  // recursively:
1094  copy(origin->begin(),
1095  origin->end(),
1096  target->begin());
1097  }
1098 }
1099 
1101 inline void copy(Numeric x,
1102  Iterator3D target,
1103  const Iterator3D& end)
1104 {
1105  for ( ; target!=end ; ++target )
1106  {
1107  // We use the copy function for the next smaller rank of tensor
1108  // recursively:
1109  copy(x,target->begin(),target->end());
1110  }
1111 }
1112 
1113 
1114 // Functions for Tensor3:
1115 // ---------------------
1116 
1120 {
1121  // Nothing to do here. However, note that the default constructor
1122  // for Tensor3View has been called in the initializer list. That is
1123  // crucial, otherwise internal range objects will not be properly
1124  // initialized.
1125 }
1126 
1130  Tensor3View( new Numeric[p*r*c],
1131  Range(0,p,r*c),
1132  Range(0,r,c),
1133  Range(0,c))
1134 {
1135  // Nothing to do here.
1136 }
1137 
1139 inline Tensor3::Tensor3(Index p, Index r, Index c, Numeric fill) :
1140  Tensor3View( new Numeric[p*r*c],
1141  Range(0,p,r*c),
1142  Range(0,r,c),
1143  Range(0,c))
1144 {
1145  // Here we can access the raw memory directly, for slightly
1146  // increased efficiency:
1147  for ( Numeric *x=mdata; x<mdata+p*r*c; ++x )
1148  *x = fill;
1149 }
1150 
1154  Tensor3View( new Numeric[m.npages()*m.nrows()*m.ncols()],
1155  Range( 0, m.npages(), m.nrows()*m.ncols() ),
1156  Range( 0, m.nrows(), m.ncols() ),
1157  Range( 0, m.ncols() ) )
1158 {
1159  copy(m.begin(),m.end(),begin());
1160 }
1161 
1164 inline Tensor3::Tensor3(const Tensor3& m) :
1165  Tensor3View( new Numeric[m.npages()*m.nrows()*m.ncols()],
1166  Range( 0, m.npages(), m.nrows()*m.ncols() ),
1167  Range( 0, m.nrows(), m.ncols() ),
1168  Range( 0, m.ncols() ) )
1169 {
1170  // There is a catch here: If m is an empty tensor, then it will have
1171  // dimensions of size 0. But these are used to initialize the stride
1172  // for higher dimensions! Thus, this method has to be consistent
1173  // with the behaviour of Range::Range. For now, Range::Range allows
1174  // also stride 0.
1175  copy(m.begin(),m.end(),begin());
1176 }
1177 
1189 {
1190  // cout << "Tensor3 copy: m = " << m.nrows() << " " << m.ncols() << "\n";
1191  // cout << " n = " << nrows() << " " << ncols() << "\n";
1192 
1193  // None of the extents can be zero for a valid tensor, so we just
1194  // have to check one.
1195  if ( 0 == mcr.mextent )
1196  {
1197  // Adjust if previously empty.
1198  resize( m.mpr.mextent, m.mrr.mextent, m.mcr.mextent );
1199  }
1200  else
1201  {
1202  // Check that sizes are compatible:
1203  assert( mpr.mextent==m.mpr.mextent );
1204  assert( mrr.mextent==m.mrr.mextent );
1205  assert( mcr.mextent==m.mcr.mextent );
1206  }
1207 
1208  copy( m.begin(), m.end(), begin() );
1209  return *this;
1210 }
1211 
1215 {
1216  copy( x, begin(), end() );
1217  return *this;
1218 }
1219 
1223 inline void Tensor3::resize(Index p, Index r, Index c)
1224 {
1225  assert( 0<=p );
1226  assert( 0<=r );
1227  assert( 0<=c );
1228 
1229  if ( mpr.mextent!=p ||
1230  mrr.mextent!=r ||
1231  mcr.mextent!=c )
1232  {
1233  delete mdata;
1234  mdata = new Numeric[p*r*c];
1235 
1236  mpr.mstart = 0;
1237  mpr.mextent = p;
1238  mpr.mstride = r*c;
1239 
1240  mrr.mstart = 0;
1241  mrr.mextent = r;
1242  mrr.mstride = c;
1243 
1244  mcr.mstart = 0;
1245  mcr.mextent = c;
1246  mcr.mstride = 1;
1247  }
1248 }
1249 
1253 {
1254 // cout << "Destroying a Tensor3:\n"
1255 // << *this << "\n........................................\n";
1256  delete [] mdata;
1257 }
1258 
1259 
1275 inline void transform( Tensor3View y,
1276  double (&my_func)(double),
1277  ConstTensor3View x )
1278 {
1279  // Check dimensions:
1280  assert( y.npages() == x.npages() );
1281  assert( y.nrows() == x.nrows() );
1282  assert( y.ncols() == x.ncols() );
1283 
1284  const ConstIterator3D xe = x.end();
1285  ConstIterator3D xi = x.begin();
1286  Iterator3D yi = y.begin();
1287  for ( ; xi!=xe; ++xi, ++yi )
1288  {
1289  // Use the transform function of lower dimensional tensors
1290  // recursively:
1291  transform(*yi,my_func,*xi);
1292  }
1293 }
1294 
1296 inline Numeric max(const ConstTensor3View& x)
1297 {
1298  const ConstIterator3D xe = x.end();
1299  ConstIterator3D xi = x.begin();
1300 
1301  // Initial value for max:
1302  Numeric themax = max(*xi);
1303  ++xi;
1304 
1305  for ( ; xi!=xe ; ++xi )
1306  {
1307  // Use the max function of lower dimensional tensors
1308  // recursively:
1309  Numeric maxi = max(*xi);
1310  if ( maxi > themax )
1311  themax = maxi;
1312  }
1313 
1314  return themax;
1315 }
1316 
1318 inline Numeric min(const ConstTensor3View& x)
1319 {
1320  const ConstIterator3D xe = x.end();
1321  ConstIterator3D xi = x.begin();
1322 
1323  // Initial value for min:
1324  Numeric themin = min(*xi);
1325  ++xi;
1326 
1327  for ( ; xi!=xe ; ++xi )
1328  {
1329  // Use the min function of lower dimensional tensors
1330  // recursively:
1331  Numeric mini = min(*xi);
1332  if ( mini < themin )
1333  themin = mini;
1334  }
1335 
1336  return themin;
1337 }
1338 
1339 
1340 
1341 #endif // matpackIII_h
Iterator3D::operator!=
bool operator!=(const Iterator3D &other) const
Not equal operator, needed for algorithms like copy.
Definition: matpackIII.h:301
copy
void copy(ConstIterator3D origin, const ConstIterator3D &end, Iterator3D target)
Copy data between begin and end to target.
Definition: matpackIII.h:1086
Tensor3View::Tensor3View
Tensor3View()
Default constructor.
Definition: matpackIII.h:1041
Tensor3View::end
ConstIterator3D end() const
Return const iterator behind last row.
Definition: matpackIII.h:846
MatrixView
The MatrixView class.
Definition: matpackI.h:476
transform
void transform(Tensor3View y, double(&my_func)(double), ConstTensor3View x)
A generic transform function for tensors, which can be used to implement mathematical functions opera...
Definition: matpackIII.h:1275
ConstTensor3View::operator()
ConstTensor3View operator()(const Range &p, const Range &r, const Range &c) const
Const index operator for subrange.
Definition: matpackIII.h:412
ConstIterator3D::operator*
const ConstMatrixView & operator*() const
Dereferencing.
Definition: matpackIII.h:381
ConstIterator3D::mstride
Index mstride
Stride.
Definition: matpackIII.h:73
Tensor3
The Tensor3 class.
Definition: matpackIII.h:227
Iterator3D::Iterator3D
Iterator3D()
Default constructor.
Definition: matpackIII.h:274
ConstIterator3D
Const version of Iterator3D.
Definition: matpackIII.h:56
ConstMatrixView::mdata
Numeric * mdata
Pointer to the plain C array that holds the data.
Definition: matpackI.h:464
ConstTensor3View::ConstTensor3View
ConstTensor3View()
Default constructor.
Definition: matpackIII.h:556
Tensor3View::operator()
ConstTensor3View operator()(const Range &p, const Range &r, const Range &c) const
Const index operator for subrange.
Definition: matpackIII.h:632
Tensor3::~Tensor3
~Tensor3()
Destructor for Tensor3.
Definition: matpackIII.h:1252
Range::mstart
Index mstart
The start index.
Definition: matpackI.h:168
ConstMatrixView::mcr
Range mcr
The column range of mdata that is actually used.
Definition: matpackI.h:462
ConstIterator3D::operator++
ConstIterator3D & operator++()
Prefix increment operator.
Definition: matpackIII.h:352
Tensor3::resize
void resize(Index p, Index r, Index c)
Resize function.
Definition: matpackIII.h:1223
Tensor3View::operator-=
Tensor3View & operator-=(Numeric x)
Subtraction of scalar.
Definition: matpackIII.h:965
ConstTensor3View::npages
Index npages() const
Returns the number of pages.
Definition: matpackIII.h:392
ConstMatrixView::mrr
Range mrr
The row range of mdata that is actually used.
Definition: matpackI.h:460
min
Numeric min(const ConstTensor3View &x)
Min function, tensor version.
Definition: matpackIII.h:1318
ArrayOfTensor3
Array< Tensor3 > ArrayOfTensor3
An array of Tensor3.
Definition: matpackIII.h:263
matpackI.h
Iterator3D::operator*
MatrixView & operator*()
Dereferencing.
Definition: matpackIII.h:323
Tensor3View
The Tensor3View class.
Definition: matpackIII.h:151
Array
This can be used to make arrays out of anything.
Definition: array.h:48
Iterator3D
Implementation of Tensors of Rank 3.
Definition: matpackIII.h:35
MatrixView::begin
ConstIterator2D begin() const
Return const iterator to first row.
Definition: matpackI.h:1760
ConstMatrixView::end
ConstIterator2D end() const
Return const iterator behind last row.
Definition: matpackI.h:1566
ConstTensor3View::begin
ConstIterator3D begin() const
Return const iterator to first page.
Definition: matpackIII.h:536
ConstTensor3View::mrr
Range mrr
The row range of mdata that is actually used.
Definition: matpackIII.h:135
Numeric
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: arts.h:147
ConstTensor3View::mcr
Range mcr
The column range of mdata that is actually used.
Definition: matpackIII.h:137
VectorView
The VectorView class.
Definition: matpackI.h:281
ConstTensor3View::mpr
Range mpr
The page range of mdata that is actually used.
Definition: matpackIII.h:133
ConstTensor3View::mdata
Numeric * mdata
Pointer to the plain C array that holds the data.
Definition: matpackIII.h:139
Tensor3View::operator/=
Tensor3View & operator/=(Numeric x)
Division by scalar.
Definition: matpackIII.h:943
Iterator3D::msv
MatrixView msv
Current position.
Definition: matpackIII.h:50
ConstIterator3D::operator->
const ConstMatrixView * operator->() const
The -> operator is needed, so that we can write i->begin() to get the 1D iterators.
Definition: matpackIII.h:375
ConstTensor3View::nrows
Index nrows() const
Returns the number of rows.
Definition: matpackIII.h:398
ConstMatrixView
A constant view of a Matrix.
Definition: matpackI.h:426
Tensor3View::operator*=
Tensor3View & operator*=(Numeric x)
Multiplication by scalar.
Definition: matpackIII.h:932
Iterator3D::mstride
Index mstride
Stride.
Definition: matpackIII.h:52
ConstTensor3View::end
ConstIterator3D end() const
Return const iterator behind last page.
Definition: matpackIII.h:545
max
Numeric max(const ConstTensor3View &x)
Max function, tensor version.
Definition: matpackIII.h:1296
Range
The range class.
Definition: matpackI.h:139
Range::mextent
Index mextent
The number of elements.
Definition: matpackI.h:171
MatrixView::end
ConstIterator2D end() const
Return const iterator behind last row.
Definition: matpackI.h:1766
ConstIterator3D::msv
ConstMatrixView msv
Current position.
Definition: matpackIII.h:71
Index
INDEX Index
The type to use for all integer numbers and indices.
Definition: arts.h:153
ConstTensor3View::ncols
Index ncols() const
Returns the number of columns.
Definition: matpackIII.h:404
Tensor3View::begin
ConstIterator3D begin() const
Return const iterator to first row.
Definition: matpackIII.h:840
ConstTensor3View
A constant view of a Tensor3.
Definition: matpackIII.h:93
operator<<
std::ostream & operator<<(std::ostream &os, const ConstTensor3View &v)
Output operator.
Definition: matpackIII.h:603
Tensor3::operator=
Tensor3 & operator=(const Tensor3 &x)
Assignment operator from another tensor.
Definition: matpackIII.h:1188
ConstIterator3D::ConstIterator3D
ConstIterator3D()
Default constructor.
Definition: matpackIII.h:332
ConstMatrixView::begin
ConstIterator2D begin() const
Return const iterator to first row.
Definition: matpackI.h:1558
Tensor3View::operator+=
Tensor3View & operator+=(Numeric x)
Addition of scalar.
Definition: matpackIII.h:954
Iterator3D::operator->
MatrixView * operator->()
The -> operator is needed, so that we can write i->begin() to get the 1D iterators.
Definition: matpackIII.h:317
add
Numeric add(Numeric x, Numeric y)
Definition: matpackIII.h:926
ConstIterator3D::operator!=
bool operator!=(const ConstIterator3D &other) const
Not equal operator, needed for algorithms like copy.
Definition: matpackIII.h:359
Tensor3View::operator=
Tensor3View & operator=(const ConstTensor3View &v)
Assignment operator.
Definition: matpackIII.h:874
Iterator3D::operator++
Iterator3D & operator++()
Prefix increment operator.
Definition: matpackIII.h:294
Range::mstride
Index mstride
The stride.
Definition: matpackI.h:173
ConstVectorView
A constant view of a Vector.
Definition: matpackI.h:232
Tensor3::Tensor3
Tensor3()
Default constructor.
Definition: matpackIII.h:1118