ARTS  1.0.222
matpackI.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 
94 #ifndef matpackI_h
95 #define matpackI_h
96 
97 #include <iostream>
98 #include <iomanip>
99 #include "arts.h"
100 
111 class Joker {
112  // Nothing here.
113 };
114 
115 // Declare existence of the global joker object:
116 extern Joker joker;
117 
118 // Declare the existence of class VectorView:
119 class VectorView;
120 
121 // Declare the existence of class SparseMatrixView:
122 class SparseMatrixView;
123 
139 class Range{
140 public:
141  // Constructors:
142  Range(Index start, Index extent, Index stride=1);
143  Range(Index start, Joker joker, Index stride=1);
144  Range(Joker joker, Index stride=1);
145  Range(Index max_size, const Range& r);
146  Range(const Range& p, const Range& n);
147 
148  // Friends:
149  friend class ConstVectorView;
150  friend class VectorView;
151  friend class Vector;
152  friend class ConstMatrixView;
153  friend class MatrixView;
154  friend class Matrix;
155  friend class Iterator2D;
156  friend class Iterator3D;
157  friend class ConstIterator2D;
158  friend class ConstIterator3D;
159  friend class SparseMatrixView;
160  friend class ConstTensor3View;
161  friend class Tensor3View;
162  friend class Tensor3;
163  friend std::ostream& operator<<(std::ostream& os, const SparseMatrixView& v);
164 
165 
166 private:
174 };
175 
178 class Iterator1D {
179 public:
180  // Constructors:
181  Iterator1D();
182  Iterator1D(const Iterator1D& o);
183  Iterator1D(Numeric *x, Index stride);
184 
185  // Operators:
187  Numeric& operator*() const;
188  bool operator!=(const Iterator1D& other) const;
189 
190 private:
195 };
196 
200 public:
201  // Constructors:
202  ConstIterator1D();
204  ConstIterator1D(Numeric *x, Index stride);
205 
206  // Operators:
208  const Numeric& operator*() const;
209  bool operator!=(const ConstIterator1D& other) const;
210 
211 private:
213  const Numeric *mx;
216 };
217 
218 // Declare the vector class:
219 class Vector;
220 
221 // Declare the MatrixView class
222 class MatrixView;
223 
224 // Declare the ConstMatrixView class
225 class ConstMatrixView;
226 
233 public:
234 
235  // Member functions:
236  Index nelem() const;
237  Numeric sum() const;
238 
239  // Const index operators:
240  Numeric operator[](Index n) const;
241  ConstVectorView operator[](const Range& r) const;
242 
243  // Functions returning iterators:
244  ConstIterator1D begin() const;
245  ConstIterator1D end() const;
246 
247  // Conversion to 1 column matrix:
248  operator ConstMatrixView() const;
249 
250  // Friends:
251  friend class VectorView;
252  friend class ConstIterator2D;
253  friend class ConstMatrixView;
254  friend class ConstTensor3View;
255 
256 protected:
257  // Constructors:
258  ConstVectorView();
259  ConstVectorView(Numeric *data, const Range& range);
260  ConstVectorView(Numeric *data, const Range& p, const Range& n);
261 
262  // Data members:
263  // -------------
268 };
269 
281 class VectorView : public ConstVectorView {
282 public:
283 
284  // Const index operators:
285  Numeric operator[](Index n) const;
286  ConstVectorView operator[](const Range& r) const;
287  // Index Operators:
289  VectorView operator[](const Range& r);
290 
291  // Constant iterators:
292  ConstIterator1D begin() const;
293  ConstIterator1D end() const;
294  // Iterators:
295  Iterator1D begin();
296  Iterator1D end();
297 
298  // Assignment operators:
300  VectorView operator=(const VectorView& v);
301  VectorView operator=(const Vector& v);
304 
305  // Other operators:
310 
315 
316  // Conversion to 1 column matrix:
317  operator MatrixView();
318 
319  // Friends:
320  friend class ConstIterator2D;
321  friend class Iterator2D;
322  friend class MatrixView;
323  friend class Tensor3View;
324 
325 protected:
326  // Constructors:
327  VectorView();
328  VectorView(Numeric *data, const Range& range);
329  VectorView(Numeric *data, const Range& p, const Range& n);
330 };
331 
335 class Iterator2D {
336 public:
337  // Constructors:
338  Iterator2D();
339  Iterator2D(const Iterator2D& o);
340  Iterator2D(const VectorView& x, Index stride);
341 
342  // Operators:
344  bool operator!=(const Iterator2D& other) const;
347 
348 private:
353 };
354 
359 public:
360  // Constructors:
361  ConstIterator2D();
363  ConstIterator2D(const ConstVectorView& x, Index stride);
364 
365  // Operators:
367  bool operator!=(const ConstIterator2D& other) const;
368  const ConstVectorView* operator->() const;
369  const ConstVectorView& operator*() const;
370 
371 private:
376 };
377 
389 class Vector : public VectorView {
390 public:
391  // Constructors:
392  Vector();
393  explicit Vector(Index n);
394  Vector(Index n, Numeric fill);
395  Vector(Numeric start, Index extent, Numeric stride);
396  Vector(const ConstVectorView& v);
397  Vector(const Vector& v);
398 
399  // Assignment operators:
400  // Vector& operator=(VectorView x);
401  Vector& operator=(const Vector& v);
402  Vector& operator=(const Array<Numeric>& v);
404 
405  // Resize function:
406  void resize(Index n);
407 
408  // Destructor:
409  ~Vector();
410 };
411 
412 // Declare class Matrix:
413 class Matrix;
414 
415 
427 public:
428  // Member functions:
429  Index nrows() const;
430  Index ncols() const;
431 
432  // Const index operators:
433  Numeric operator()(Index r, Index c) const;
434  ConstMatrixView operator()(const Range& r, const Range& c) const;
435  ConstVectorView operator()(const Range& r, Index c) const;
436  ConstVectorView operator()(Index r, const Range& c) const;
437 
438  // Functions returning iterators:
439  ConstIterator2D begin() const;
440  ConstIterator2D end() const;
441 
442  // Friends:
443  friend class ConstVectorView;
444  friend class MatrixView;
445  friend class ConstIterator3D;
446  friend class ConstTensor3View;
448 
449 protected:
450  // Constructors:
451  ConstMatrixView();
452  ConstMatrixView(Numeric *data, const Range& r, const Range& c);
453  ConstMatrixView(Numeric *data,
454  const Range& pr, const Range& pc,
455  const Range& nr, const Range& nc);
456 
457  // Data members:
458  // -------------
465 };
466 
476 class MatrixView : public ConstMatrixView {
477 public:
478 
479  // Const index operators:
480  Numeric operator()(Index r, Index c) const;
481  ConstMatrixView operator()(const Range& r, const Range& c) const;
482  ConstVectorView operator()(const Range& r, Index c) const;
483  ConstVectorView operator()(Index r, const Range& c) const;
484  // Index Operators:
485  Numeric& operator()(Index r, Index c);
486  MatrixView operator()(const Range& r, const Range& c);
487  VectorView operator()(const Range& r, Index c);
488  VectorView operator()(Index r, const Range& c);
489 
490  // Functions returning const iterators:
491  ConstIterator2D begin() const;
492  ConstIterator2D end() const;
493  // Functions returning iterators:
494  Iterator2D begin();
495  Iterator2D end();
496 
497  // Assignment operators:
499  MatrixView& operator=(const MatrixView& v);
500  MatrixView& operator=(const Matrix& v);
503 
504  // Other operators:
509 
514 
519 
520  // Friends:
521  friend class VectorView;
522  friend class Iterator3D;
523  friend class Tensor3View;
525  friend MatrixView transpose(MatrixView m);
526 
527 protected:
528  // Constructors:
529  MatrixView();
530  MatrixView(Numeric *data, const Range& r, const Range& c);
531  MatrixView(Numeric *data,
532  const Range& pr, const Range& pc,
533  const Range& nr, const Range& nc);
534 };
535 
544 class Matrix : public MatrixView {
545 public:
546  // Constructors:
547  Matrix();
548  Matrix(Index r, Index c);
549  Matrix(Index r, Index c, Numeric fill);
550  Matrix(const ConstMatrixView& v);
551  Matrix(const Matrix& v);
552 
553  // Assignment operators:
554  Matrix& operator=(const Matrix& x);
556  Matrix& operator=(const ConstVectorView& v);
557 
558  // Resize function:
559  void resize(Index r, Index c);
560 
561  // Destructor:
562  ~Matrix();
563 };
564 
565 
566 // Function declarations:
567 // ----------------------
568 
569 inline void copy(ConstIterator1D origin,
570  const ConstIterator1D& end,
571  Iterator1D target);
572 
573 inline void copy(Numeric x,
574  Iterator1D target,
575  const Iterator1D& end);
576 
577 inline void copy(ConstIterator2D origin,
578  const ConstIterator2D& end,
579  Iterator2D target);
580 
581 inline void copy(Numeric x,
582  Iterator2D target,
583  const Iterator2D& end);
584 
585 
586 
587 // Declare the existance of class Array:
588 template<class base>
589 class Array;
590 
593 
596 
597 
598 // Functions for Range:
599 // --------------------
600 
601 /* Explicit constructor.
602 
603  \param Start must be >= 0.
604 
605  \param Extent also. Although internally negative extent means "to the end",
606  this can not be created this way, only with the joker. Zero
607  extent is allowed, though, which corresponds to an empty range.
608 
609  \param Stride can be anything. It can be omitted, in which case the
610  default value is 1. */
611 inline Range::Range(Index start, Index extent, Index stride) :
612  mstart(start), mextent(extent), mstride(stride)
613 {
614  // Start must be >= 0:
615  assert( 0<=mstart );
616  // Extent also. Although internally negative extent means "to the end",
617  // this can not be created this way, only with the joker. Zero
618  // extent is allowed, though, which corresponds to an empty range.
619  assert( 0<=mextent );
620  // Stride can be anything except 0.
621  // SAB 2001-09-21: Allow 0 stride.
622  // assert( 0!=mstride);
623 }
624 
627 inline Range::Range(Index start, Joker /* joker */, Index stride) :
628  mstart(start), mextent(-1), mstride(stride)
629 {
630  // Start must be >= 0:
631  assert( 0<=mstart );
632 }
633 
637 inline Range::Range(Joker /* joker */, Index stride) :
638  mstart(0), mextent(-1), mstride(stride)
639 {
640  // Nothing to do here.
641 }
642 
648 inline Range::Range(Index max_size, const Range& r) :
649  mstart(r.mstart),
650  mextent(r.mextent),
651  mstride(r.mstride)
652 {
653  // Start must be >= 0:
654  assert( 0<=mstart );
655  // ... and < max_size:
656  assert( mstart<max_size );
657 
658  // Stride must be != 0:
659  assert( 0!=mstride);
660 
661  // Convert negative extent (joker) to explicit extent
662  if ( mextent<0 )
663  {
664  if ( 0<mstride )
665  mextent = 1 + (max_size-1-mstart)/mstride;
666  else
667  mextent = 1 + (0-mstart)/mstride;
668  }
669  else
670  {
671 #ifndef NDEBUG
672  // Check that extent is ok:
673  Index fin = mstart+(mextent-1)*mstride;
674  assert( 0 <= fin );
675  assert( fin < max_size );
676 #endif
677  }
678 }
679 
685 inline Range::Range(const Range& p, const Range& n) :
686  mstart(p.mstart + n.mstart*p.mstride),
687  mextent(n.mextent),
688  mstride(p.mstride*n.mstride)
689 {
690  // We have to juggle here a bit with previous, new, and resulting
691  // quantities. I.e.;
692  // p.mstride: Previous stride
693  // n.mstride: New stride (as specified)
694  // mstride: Resulting stride (old*new)
695 
696  // Get the previous final element:
697  Index prev_fin = p.mstart+(p.mextent-1)*p.mstride;
698 
699  // Resulting start must be >= previous start:
700  assert( p.mstart<=mstart );
701  // and <= prev_fin:
702  assert( mstart<=prev_fin );
703 
704  // Resulting stride must be != 0:
705  assert( 0!=mstride);
706 
707  // Convert negative extent (joker) to explicit extent
708  if ( mextent<0 )
709  {
710  if ( 0<mstride )
711  mextent = 1 + (prev_fin-mstart)/mstride;
712  else
713  mextent = 1 + (p.mstart-mstart)/mstride;
714  }
715  else
716  {
717 #ifndef NDEBUG
718  // Check that extent is ok:
719  Index fin = mstart+(mextent-1)*mstride;
720  assert( p.mstart <= fin );
721  assert( fin <= prev_fin );
722 #endif
723  }
724 
725 }
726 
727 
728 // Functions for Iterator1D
729 // ------------------------
730 
733 {
734  // Nothing to do here.
735 }
736 
739  mx(o.mx), mstride(o.mstride)
740 {
741  // Nothing to do here.
742 }
743 
746  mx(x), mstride(stride)
747 {
748  // Nothing to do here.
749 }
750 
753 {
754  mx += mstride;
755  return *this;
756 }
757 
759 inline bool Iterator1D::operator!=(const Iterator1D& other) const
760 {
761  if (mx!=other.mx)
762  return true;
763  else
764  return false;
765 }
766 
769 {
770  return *mx;
771 }
772 
773 // Functions for ConstIterator1D
774 // -----------------------------
775 
778 {
779  // Nothing to do here.
780 }
781 
784  mx(o.mx), mstride(o.mstride)
785 {
786  // Nothing to do here.
787 }
788 
791  mx(x), mstride(stride)
792 {
793  // Nothing to do here.
794 }
795 
798 {
799  mx += mstride;
800  return *this;
801 }
802 
804 inline bool ConstIterator1D::operator!=(const ConstIterator1D& other) const
805 {
806  if (mx!=other.mx)
807  return true;
808  else
809  return false;
810 }
811 
813 inline const Numeric& ConstIterator1D::operator*() const
814 {
815  return *mx;
816 }
817 
818 // Functions for Iterator2D
819 // ------------------------
820 
823 {
824  // Nothing to do here.
825 }
826 
829  msv(o.msv), mstride(o.mstride)
830 {
831  // Nothing to do here.
832 }
833 
835 inline Iterator2D::Iterator2D(const VectorView& x, Index stride) :
836  msv(x), mstride(stride)
837 {
838  // Nothing to do here.
839 }
840 
843 {
844  msv.mdata += mstride;
845  return *this;
846 }
847 
849 inline bool Iterator2D::operator!=(const Iterator2D& other) const
850 {
851  if ( msv.mdata + msv.mrange.mstart !=
852  other.msv.mdata + other.msv.mrange.mstart )
853  return true;
854  else
855  return false;
856 }
857 
861 {
862  return &msv;
863 }
864 
867 {
868  return msv;
869 }
870 
871 // Functions for ConstIterator2D
872 // -----------------------------
873 
876 {
877  // Nothing to do here.
878 }
879 
882  msv(o.msv), mstride(o.mstride)
883 {
884  // Nothing to do here.
885 }
886 
889  msv(x), mstride(stride)
890 {
891  // Nothing to do here.
892 }
893 
896 {
897  msv.mdata += mstride;
898  return *this;
899 }
900 
902 inline bool ConstIterator2D::operator!=(const ConstIterator2D& other) const
903 {
904  if ( msv.mdata + msv.mrange.mstart !=
905  other.msv.mdata + other.msv.mrange.mstart )
906  return true;
907  else
908  return false;
909 }
910 
914 {
915  return &msv;
916 }
917 
920 {
921  return msv;
922 }
923 
924 
925 // Functions for ConstVectorView:
926 // ------------------------------
927 
938 {
939  return mrange.mextent;
940 }
941 
944 {
945  Numeric s=0;
946  ConstIterator1D i = begin();
947  const ConstIterator1D e = end();
948 
949  for ( ; i!=e; ++i )
950  s += *i;
951 
952  return s;
953 }
954 
957 {
958  // Check if index is valid:
959  assert( 0<=n );
960  assert( n<mrange.mextent );
961  return *( mdata +
962  mrange.mstart +
963  n*mrange.mstride );
964 }
965 
970 {
971  return ConstVectorView(mdata, mrange, r);
972 }
973 
976 {
978 }
979 
982 {
983  return ConstIterator1D( mdata +
984  mrange.mstart +
986  mrange.mstride );
987 }
988 
990 inline ConstVectorView::operator ConstMatrixView() const
991 {
992  return ConstMatrixView(mdata,mrange,Range(mrange.mstart,1));
993 }
994 
998  mrange(0,0), mdata(NULL)
999 {
1000  // Nothing to do here.
1001 }
1002 
1006  const Range& range) :
1007  mrange(range),
1008  mdata(data)
1009 {
1010  // Nothing to do here.
1011 }
1012 
1024  const Range& p,
1025  const Range& n) :
1026  mrange(p,n),
1027  mdata(data)
1028 {
1029  // Nothing to do here.
1030 }
1031 
1035 inline std::ostream& operator<<(std::ostream& os, const ConstVectorView& v)
1036 {
1037  ConstIterator1D i=v.begin();
1038  const ConstIterator1D end=v.end();
1039 
1040  if ( i!=end )
1041  {
1042  os << setw(3) << *i;
1043  ++i;
1044  }
1045  for ( ; i!=end ; ++i )
1046  {
1047  os << "\n" << setw(3) << *i;
1048  }
1049 
1050  return os;
1051 }
1052 
1053 
1054 // Functions for VectorView:
1055 // ------------------------
1056 
1060 {
1061  return ConstVectorView::operator[](n);
1062 }
1063 
1069 {
1070  return ConstVectorView::operator[](r);
1071 }
1072 
1075 {
1076  // Check if index is valid:
1077  assert( 0<=n );
1078  assert( n<mrange.mextent );
1079  return *( mdata +
1080  mrange.mstart +
1081  n*mrange.mstride );
1082 }
1083 
1088 {
1089  return VectorView(mdata, mrange, r);
1090 }
1091 
1096 {
1097  return ConstVectorView::begin();
1098 }
1099 
1104 {
1105  return ConstVectorView::end();
1106 }
1107 
1110 {
1112 }
1113 
1116 {
1117  return Iterator1D( mdata +
1118  mrange.mstart +
1120  mrange.mstride );
1121 }
1122 
1128 {
1129  // cout << "Assigning VectorView from ConstVectorView.\n";
1130 
1131  // Check that sizes are compatible:
1132  assert(mrange.mextent==v.mrange.mextent);
1133 
1134  copy( v.begin(), v.end(), begin() );
1135 
1136  return *this;
1137 }
1138 
1145 {
1146  // cout << "Assigning VectorView from VectorView.\n";
1147 
1148  // Check that sizes are compatible:
1149  assert(mrange.mextent==v.mrange.mextent);
1150 
1151  copy( v.begin(), v.end(), begin() );
1152 
1153  return *this;
1154 }
1155 
1159 {
1160  // cout << "Assigning VectorView from Vector.\n";
1161 
1162  // Check that sizes are compatible:
1163  assert(mrange.mextent==v.mrange.mextent);
1164 
1165  copy( v.begin(), v.end(), begin() );
1166 
1167  return *this;
1168 }
1169 
1173 {
1174  copy( x, begin(), end() );
1175  return *this;
1176 }
1177 
1180 {
1181  const Iterator1D e=end();
1182  for ( Iterator1D i=begin(); i!=e ; ++i )
1183  *i *= x;
1184  return *this;
1185 }
1186 
1189 {
1190  const Iterator1D e=end();
1191  for ( Iterator1D i=begin(); i!=e ; ++i )
1192  *i /= x;
1193  return *this;
1194 }
1195 
1198 {
1199  const Iterator1D e=end();
1200  for ( Iterator1D i=begin(); i!=e ; ++i )
1201  *i += x;
1202  return *this;
1203 }
1204 
1207 {
1208  const Iterator1D e=end();
1209  for ( Iterator1D i=begin(); i!=e ; ++i )
1210  *i -= x;
1211  return *this;
1212 }
1213 
1216 {
1217  assert( nelem()==x.nelem() );
1218 
1219  ConstIterator1D s=x.begin();
1220 
1221  Iterator1D i=begin();
1222  const Iterator1D e=end();
1223 
1224  for ( ; i!=e ; ++i,++s )
1225  *i *= *s;
1226  return *this;
1227 }
1228 
1231 {
1232  assert( nelem()==x.nelem() );
1233 
1234  ConstIterator1D s=x.begin();
1235 
1236  Iterator1D i=begin();
1237  const Iterator1D e=end();
1238 
1239  for ( ; i!=e ; ++i,++s )
1240  *i /= *s;
1241  return *this;
1242 }
1243 
1246 {
1247  assert( nelem()==x.nelem() );
1248 
1249  ConstIterator1D s=x.begin();
1250 
1251  Iterator1D i=begin();
1252  const Iterator1D e=end();
1253 
1254  for ( ; i!=e ; ++i,++s )
1255  *i += *s;
1256  return *this;
1257 }
1258 
1261 {
1262  assert( nelem()==x.nelem() );
1263 
1264  ConstIterator1D s=x.begin();
1265 
1266  Iterator1D i=begin();
1267  const Iterator1D e=end();
1268 
1269  for ( ; i!=e ; ++i,++s )
1270  *i -= *s;
1271  return *this;
1272 }
1273 
1275 inline VectorView::operator MatrixView()
1276 {
1277  return MatrixView(mdata,mrange,Range(mrange.mstart,1));
1278 }
1279 
1283  ConstVectorView()
1284 {
1285  // Nothing to do here.
1286 }
1287 
1291  const Range& range) :
1292  ConstVectorView(data,range)
1293 {
1294  // Nothing to do here.
1295 }
1296 
1308  const Range& p,
1309  const Range& n) :
1310  ConstVectorView(data,p,n)
1311 {
1312  // Nothing to do here.
1313 }
1314 
1319 inline void copy(ConstIterator1D origin,
1320  const ConstIterator1D& end,
1321  Iterator1D target)
1322 {
1323  for ( ; origin!=end ; ++origin,++target )
1324  *target = *origin;
1325 }
1326 
1328 inline void copy(Numeric x,
1329  Iterator1D target,
1330  const Iterator1D& end)
1331 {
1332  for ( ; target!=end ; ++target )
1333  *target = x;
1334 }
1335 
1336 
1337 // Functions for Vector:
1338 // ---------------------
1339 
1342 {
1343  // Nothing to do here
1344 }
1345 
1348  VectorView( new Numeric[n],
1349  Range(0,n))
1350 {
1351  // Nothing to do here.
1352 }
1353 
1355 inline Vector::Vector(Index n, Numeric fill) :
1356  VectorView( new Numeric[n],
1357  Range(0,n))
1358 {
1359  // Here we can access the raw memory directly, for slightly
1360  // increased efficiency:
1361  for ( Numeric *x=mdata; x<mdata+n; ++x )
1362  *x = fill;
1363 }
1364 
1373 inline Vector::Vector(Numeric start, Index extent, Numeric stride) :
1374  VectorView( new Numeric[extent],
1375  Range(0,extent))
1376 {
1377  // Fill with values:
1378  Numeric x = start;
1379  Iterator1D i=begin();
1380  const Iterator1D e=end();
1381  for ( ; i!=e; ++i )
1382  {
1383  *i = x;
1384  x += stride;
1385  }
1386 }
1387 
1394  VectorView( new Numeric[v.nelem()],
1395  Range(0,v.nelem()))
1396 {
1397  copy(v.begin(),v.end(),begin());
1398 }
1399 
1402 inline Vector::Vector(const Vector& v) :
1403  VectorView( new Numeric[v.nelem()],
1404  Range(0,v.nelem()))
1405 {
1406  copy(v.begin(),v.end(),begin());
1407 }
1408 
1414 {
1415  // cout << "Assigning VectorView from Vector View.\n";
1416 
1417  // Check that sizes are compatible:
1418  assert(mrange.mextent==v.mrange.mextent);
1419  copy( v.begin(), v.end(), begin() );
1420  return *this;
1421 }
1422 
1440 {
1442  return *this;
1443 }
1444 
1448 {
1450  return *this;
1451 }
1452 
1453 // /** Assignment operator from VectorView. Assignment operators are not
1454 // inherited. */
1455 // inline Vector& Vector::operator=(const VectorView v)
1456 // {
1457 // cout << "Assigning Vector from Vector View.\n";
1458 // // Check that sizes are compatible:
1459 // assert(mrange.mextent==v.mrange.mextent);
1460 // VectorView::operator=(v);
1461 // return *this;
1462 // }
1463 
1467 inline void Vector::resize(Index n)
1468 {
1469  if ( mrange.mextent != n )
1470  {
1471  delete mdata;
1472  mdata = new Numeric[n];
1473  mrange.mstart = 0;
1474  mrange.mextent = n;
1475  mrange.mstride = 1;
1476  }
1477 }
1478 
1482 {
1483  delete [] mdata;
1484 }
1485 
1486 
1487 // Functions for ConstMatrixView:
1488 // ------------------------------
1489 
1492 {
1493  return mrr.mextent;
1494 }
1495 
1498 {
1499  return mcr.mextent;
1500 }
1501 
1504 {
1505  // Check if indices are valid:
1506  assert( 0<=r );
1507  assert( 0<=c );
1508  assert( r<mrr.mextent );
1509  assert( c<mcr.mextent );
1510 
1511  return *( mdata +
1512  mrr.mstart +
1513  r*mrr.mstride +
1514  mcr.mstart +
1515  c*mcr.mstride );
1516 }
1517 
1522  const Range& c) const
1523 {
1524  return ConstMatrixView(mdata, mrr, mcr, r, c);
1525 }
1526 
1533 {
1534  // Check that c is valid:
1535  assert( 0 <= c );
1536  assert( c < mcr.mextent );
1537 
1538  return ConstVectorView(mdata + mcr.mstart + c*mcr.mstride,
1539  mrr, r);
1540 }
1541 
1548 {
1549  // Check that r is valid:
1550  assert( 0 <= r );
1551  assert( r < mrr.mextent );
1552 
1553  return ConstVectorView(mdata + mrr.mstart + r*mrr.mstride,
1554  mcr, c);
1555 }
1556 
1559 {
1561  mcr),
1562  mrr.mstride);
1563 }
1564 
1567 {
1569  mcr),
1570  mrr.mstride );
1571 }
1572 
1576  mrr(0,0,1), mcr(0,0,1), mdata(NULL)
1577 {
1578  // Nothing to do here.
1579 }
1580 
1585  const Range& rr,
1586  const Range& cr) :
1587  mrr(rr),
1588  mcr(cr),
1589  mdata(data)
1590 {
1591  // Nothing to do here.
1592 }
1593 
1606  const Range& pr, const Range& pc,
1607  const Range& nr, const Range& nc) :
1608  mrr(pr,nr),
1609  mcr(pc,nc),
1610  mdata(data)
1611 {
1612  // Nothing to do here.
1613 }
1614 
1622 inline std::ostream& operator<<(std::ostream& os, const ConstMatrixView& v)
1623 {
1624  // Row iterators:
1625  ConstIterator2D ir=v.begin();
1626  const ConstIterator2D end_row=v.end();
1627 
1628  if ( ir!=end_row )
1629  {
1630  ConstIterator1D ic = ir->begin();
1631  const ConstIterator1D end_col = ir->end();
1632 
1633  if ( ic!=end_col )
1634  {
1635  os << setw(3) << *ic;
1636  ++ic;
1637  }
1638  for ( ; ic!=end_col ; ++ic )
1639  {
1640  os << " " << setw(3) << *ic;
1641  }
1642  ++ir;
1643  }
1644  for ( ; ir!=end_row ; ++ir )
1645  {
1646  ConstIterator1D ic = ir->begin();
1647  const ConstIterator1D end_col = ir->end();
1648 
1649  os << "\n";
1650  if ( ic!=end_col )
1651  {
1652  os << setw(3) << *ic;
1653  ++ic;
1654  }
1655  for ( ; ic!=end_col ; ++ic )
1656  {
1657  os << " " << setw(3) << *ic;
1658  }
1659  }
1660 
1661  return os;
1662 }
1663 
1664 
1665 // Functions for MatrixView:
1666 // -------------------------
1667 
1671 {
1672  return ConstMatrixView::operator()(r,c);
1673 }
1674 
1679 inline ConstMatrixView MatrixView::operator()(const Range& r, const Range& c) const
1680 {
1681  return ConstMatrixView::operator()(r,c);
1682 }
1683 
1691 {
1692  return ConstMatrixView::operator()(r,c);
1693 }
1694 
1702 {
1703  return ConstMatrixView::operator()(r,c);
1704 }
1705 
1708 {
1709  // Check if indices are valid:
1710  assert( 0<=r );
1711  assert( 0<=c );
1712  assert( r<mrr.mextent );
1713  assert( c<mcr.mextent );
1714 
1715  return *( mdata +
1716  mrr.mstart +
1717  r*mrr.mstride +
1718  mcr.mstart +
1719  c*mcr.mstride );
1720 }
1721 
1725 inline MatrixView MatrixView::operator()(const Range& r, const Range& c)
1726 {
1727  return MatrixView(mdata, mrr, mcr, r, c);
1728 }
1729 
1735 {
1736  // Check that c is valid:
1737  assert( 0 <= c );
1738  assert( c < mcr.mextent );
1739 
1740  return VectorView(mdata + mcr.mstart + c*mcr.mstride,
1741  mrr, r);
1742 }
1743 
1749 {
1750  // Check that r is valid:
1751  assert( 0 <= r );
1752  assert( r < mrr.mextent );
1753 
1754  return VectorView(mdata + mrr.mstart + r*mrr.mstride,
1755  mcr, c);
1756 }
1757 
1761 {
1762  return ConstMatrixView::begin();
1763 }
1764 
1767 {
1768  return ConstMatrixView::end();
1769 }
1770 
1773 {
1775  mrr.mstride);
1776 }
1777 
1780 {
1782  mcr),
1783  mrr.mstride );
1784 }
1785 
1791 {
1792  // Check that sizes are compatible:
1793  assert(mrr.mextent==m.mrr.mextent);
1794  assert(mcr.mextent==m.mcr.mextent);
1795 
1796  copy( m.begin(), m.end(), begin() );
1797  return *this;
1798 }
1799 
1806 {
1807  // Check that sizes are compatible:
1808  assert(mrr.mextent==m.mrr.mextent);
1809  assert(mcr.mextent==m.mcr.mextent);
1810 
1811  copy( m.begin(), m.end(), begin() );
1812  return *this;
1813 }
1814 
1819 {
1820  // Check that sizes are compatible:
1821  assert(mrr.mextent==m.mrr.mextent);
1822  assert(mcr.mextent==m.mcr.mextent);
1823 
1824  copy( m.begin(), m.end(), begin() );
1825  return *this;
1826 }
1827 
1833 {
1834  // Check that sizes are compatible:
1835  assert( mrr.mextent==v.nelem() );
1836  assert( mcr.mextent==1 );
1837  // dummy = ConstMatrixView(v.mdata,v.mrange,Range(v.mrange.mstart,1));;
1838  ConstMatrixView dummy(v);
1839  copy( dummy.begin(), dummy.end(), begin() );
1840  return *this;
1841 }
1842 
1846 {
1847  copy( x, begin(), end() );
1848  return *this;
1849 }
1850 
1853 {
1854  const Iterator2D er=end();
1855  for ( Iterator2D r=begin(); r!=er ; ++r )
1856  {
1857  const Iterator1D ec = r->end();
1858  for ( Iterator1D c = r->begin(); c!=ec ; ++c )
1859  *c *= x;
1860  }
1861  return *this;
1862 }
1863 
1866 {
1867  const Iterator2D er=end();
1868  for ( Iterator2D r=begin(); r!=er ; ++r )
1869  {
1870  const Iterator1D ec = r->end();
1871  for ( Iterator1D c = r->begin(); c!=ec ; ++c )
1872  *c /= x;
1873  }
1874  return *this;
1875 }
1876 
1879 {
1880  const Iterator2D er=end();
1881  for ( Iterator2D r=begin(); r!=er ; ++r )
1882  {
1883  const Iterator1D ec = r->end();
1884  for ( Iterator1D c = r->begin(); c!=ec ; ++c )
1885  *c += x;
1886  }
1887  return *this;
1888 }
1889 
1892 {
1893  const Iterator2D er=end();
1894  for ( Iterator2D r=begin(); r!=er ; ++r )
1895  {
1896  const Iterator1D ec = r->end();
1897  for ( Iterator1D c = r->begin(); c!=ec ; ++c )
1898  *c -= x;
1899  }
1900  return *this;
1901 }
1902 
1905 {
1906  assert(nrows()==x.nrows());
1907  assert(ncols()==x.ncols());
1908  ConstIterator2D sr = x.begin();
1909  Iterator2D r = begin();
1910  const Iterator2D er = end();
1911  for ( ; r!=er ; ++r,++sr )
1912  {
1913  ConstIterator1D sc = sr->begin();
1914  Iterator1D c = r->begin();
1915  const Iterator1D ec = r->end();
1916  for ( ; c!=ec ; ++c,++sc )
1917  *c *= *sc;
1918  }
1919  return *this;
1920 }
1921 
1924 {
1925  assert(nrows()==x.nrows());
1926  assert(ncols()==x.ncols());
1927  ConstIterator2D sr = x.begin();
1928  Iterator2D r = begin();
1929  const Iterator2D er = end();
1930  for ( ; r!=er ; ++r,++sr )
1931  {
1932  ConstIterator1D sc = sr->begin();
1933  Iterator1D c = r->begin();
1934  const Iterator1D ec = r->end();
1935  for ( ; c!=ec ; ++c,++sc )
1936  *c /= *sc;
1937  }
1938  return *this;
1939 }
1940 
1943 {
1944  assert(nrows()==x.nrows());
1945  assert(ncols()==x.ncols());
1946  ConstIterator2D sr = x.begin();
1947  Iterator2D r = begin();
1948  const Iterator2D er = end();
1949  for ( ; r!=er ; ++r,++sr )
1950  {
1951  ConstIterator1D sc = sr->begin();
1952  Iterator1D c = r->begin();
1953  const Iterator1D ec = r->end();
1954  for ( ; c!=ec ; ++c,++sc )
1955  *c += *sc;
1956  }
1957  return *this;
1958 }
1959 
1962 {
1963  assert(nrows()==x.nrows());
1964  assert(ncols()==x.ncols());
1965  ConstIterator2D sr = x.begin();
1966  Iterator2D r = begin();
1967  const Iterator2D er = end();
1968  for ( ; r!=er ; ++r,++sr )
1969  {
1970  ConstIterator1D sc = sr->begin();
1971  Iterator1D c = r->begin();
1972  const Iterator1D ec = r->end();
1973  for ( ; c!=ec ; ++c,++sc )
1974  *c -= *sc;
1975  }
1976  return *this;
1977 }
1978 
1981 {
1982  assert(nrows()==x.nelem());
1983  assert(ncols()==1);
1984  ConstIterator1D sc = x.begin();
1985  Iterator2D r = begin();
1986  const Iterator2D er = end();
1987  for ( ; r!=er ; ++r,++sc )
1988  {
1989  Iterator1D c = r->begin();
1990  *c *= *sc;
1991  }
1992  return *this;
1993 }
1994 
1997 {
1998  assert(nrows()==x.nelem());
1999  assert(ncols()==1);
2000  ConstIterator1D sc = x.begin();
2001  Iterator2D r = begin();
2002  const Iterator2D er = end();
2003  for ( ; r!=er ; ++r,++sc )
2004  {
2005  Iterator1D c = r->begin();
2006  *c /= *sc;
2007  }
2008  return *this;
2009 }
2010 
2013 {
2014  assert(nrows()==x.nelem());
2015  assert(ncols()==1);
2016  ConstIterator1D sc = x.begin();
2017  Iterator2D r = begin();
2018  const Iterator2D er = end();
2019  for ( ; r!=er ; ++r,++sc )
2020  {
2021  Iterator1D c = r->begin();
2022  *c += *sc;
2023  }
2024  return *this;
2025 }
2026 
2029 {
2030  assert(nrows()==x.nelem());
2031  assert(ncols()==1);
2032  ConstIterator1D sc = x.begin();
2033  Iterator2D r = begin();
2034  const Iterator2D er = end();
2035  for ( ; r!=er ; ++r,++sc )
2036  {
2037  Iterator1D c = r->begin();
2038  *c -= *sc;
2039  }
2040  return *this;
2041 }
2042 
2046  ConstMatrixView()
2047 {
2048  // Nothing to do here.
2049 }
2050 
2055  const Range& rr,
2056  const Range& cr) :
2057  ConstMatrixView(data, rr, cr)
2058 {
2059  // Nothing to do here.
2060 }
2061 
2074  const Range& pr, const Range& pc,
2075  const Range& nr, const Range& nc) :
2076  ConstMatrixView(data,pr,pc,nr,nc)
2077 {
2078  // Nothing to do here.
2079 }
2080 
2090 inline void copy(ConstIterator2D origin,
2091  const ConstIterator2D& end,
2092  Iterator2D target)
2093 {
2094  for ( ; origin!=end ; ++origin,++target )
2095  {
2096  ConstIterator1D o = origin->begin();
2097  const ConstIterator1D e = origin->end();
2098  Iterator1D t = target->begin();
2099  for ( ; o!=e ; ++o,++t )
2100  *t = *o;
2101  }
2102 }
2103 
2105 inline void copy(Numeric x,
2106  Iterator2D target,
2107  const Iterator2D& end)
2108 {
2109  for ( ; target!=end ; ++target )
2110  {
2111  Iterator1D t = target->begin();
2112  const Iterator1D e = target->end();
2113  for ( ; t!=e ; ++t )
2114  *t = x;
2115  }
2116 }
2117 
2118 
2119 // Functions for Matrix:
2120 // ---------------------
2121 
2123 inline Matrix::Matrix() :
2125 {
2126  // Nothing to do here. However, note that the default constructor
2127  // for MatrixView has been called in the initializer list. That is
2128  // crucial, otherwise internal range objects will not be properly
2129  // initialized.
2130 }
2131 
2135  MatrixView( new Numeric[r*c],
2136  Range(0,r,c),
2137  Range(0,c))
2138 {
2139  // Nothing to do here.
2140 }
2141 
2143 inline Matrix::Matrix(Index r, Index c, Numeric fill) :
2144  MatrixView( new Numeric[r*c],
2145  Range(0,r,c),
2146  Range(0,c))
2147 {
2148  // Here we can access the raw memory directly, for slightly
2149  // increased efficiency:
2150  for ( Numeric *x=mdata; x<mdata+r*c; ++x )
2151  *x = fill;
2152 }
2153 
2157  MatrixView( new Numeric[m.nrows()*m.ncols()],
2158  Range( 0, m.nrows(), m.ncols() ),
2159  Range( 0, m.ncols() ) )
2160 {
2161  copy(m.begin(),m.end(),begin());
2162 }
2163 
2166 inline Matrix::Matrix(const Matrix& m) :
2167  MatrixView( new Numeric[m.nrows()*m.ncols()],
2168  Range( 0, m.nrows(), m.ncols() ),
2169  Range( 0, m.ncols() ) )
2170 {
2171  // There is a catch here: If m is an empty matrix, then it will have
2172  // 0 colunns. But this is used to initialize the stride of the row
2173  // Range! Thus, this method has to be consistent with the behaviour
2174  // of Range::Range. For now, Range::Range allows also stride 0.
2175  copy(m.begin(),m.end(),begin());
2176 }
2177 
2189 {
2190  // cout << "Matrix copy: m = " << m.nrows() << " " << m.ncols() << "\n";
2191  // cout << " n = " << nrows() << " " << ncols() << "\n";
2192 
2193  // None of the extents can be zero for a valid matrix, so we just
2194  // have to check one.
2195  if ( 0 == mrr.mextent )
2196  {
2197  // Adjust if previously empty.
2198  resize( m.mrr.mextent, m.mcr.mextent );
2199  }
2200  else
2201  {
2202  // Check that sizes are compatible:
2203  assert( mrr.mextent==m.mrr.mextent );
2204  assert( mcr.mextent==m.mcr.mextent );
2205  }
2206 
2207  copy( m.begin(), m.end(), begin() );
2208  return *this;
2209 }
2210 
2214 {
2215  copy( x, begin(), end() );
2216  return *this;
2217 }
2218 
2224 {
2225  // Check that sizes are compatible:
2226  assert( mrr.mextent==v.nelem() );
2227  assert( mcr.mextent==1 );
2228  // dummy = ConstMatrixView(v.mdata,v.mrange,Range(v.mrange.mstart,1));;
2229  ConstMatrixView dummy(v);
2230  copy( dummy.begin(), dummy.end(), begin() );
2231  return *this;
2232 }
2233 
2237 inline void Matrix::resize(Index r, Index c)
2238 {
2239  assert( 0<=r );
2240  assert( 0<=c );
2241 
2242  if ( mrr.mextent!=r || mcr.mextent!=c )
2243  {
2244  delete mdata;
2245  mdata = new Numeric[r*c];
2246 
2247  mrr.mstart = 0;
2248  mrr.mextent = r;
2249  mrr.mstride = c;
2250 
2251  mcr.mstart = 0;
2252  mcr.mextent = c;
2253  mcr.mstride = 1;
2254  }
2255 }
2256 
2260 {
2261 // cout << "Destroying a Matrix:\n"
2262 // << *this << "\n........................................\n";
2263  delete [] mdata;
2264 }
2265 
2266 
2267 // Some general Matrix Vector functions:
2268 
2271 {
2272  // Check dimensions:
2273  assert( a.nelem() == b.nelem() );
2274 
2275  const ConstIterator1D ae = a.end();
2276  ConstIterator1D ai = a.begin();
2277  ConstIterator1D bi = b.begin();
2278 
2279  Numeric res = 0;
2280  for ( ; ai!=ae ; ++ai, ++bi )
2281  res += (*ai) * (*bi);
2282 
2283  return res;
2284 }
2285 
2291 inline void mult( VectorView y,
2292  const ConstMatrixView& M,
2293  const ConstVectorView& x )
2294 {
2295  // Check dimensions:
2296  assert( y.nelem() == M.nrows() );
2297  assert( M.ncols() == x.nelem() );
2298 
2299  // Let's get a 1D iterator for y:
2300  const Iterator1D ye = y.end();
2301  Iterator1D yi = y.begin();
2302 
2303  // ... a 2D iterator for M:
2304  ConstIterator2D mi = M.begin();
2305 
2306  // ... and 1D iterators pointing to the start and end of x:
2307  const ConstIterator1D xs = x.begin();
2308  const ConstIterator1D xe = x.end();
2309 
2310  // This walks through the rows of y and M:
2311  for ( ; yi!=ye ; ++yi, ++mi )
2312  {
2313  // Compute the scalar product between this row of M and x:
2314  Numeric dummy = 0;
2315 
2316  // Iterators for row of M:
2317  ConstIterator1D ri = mi->begin();
2318 
2319  // ... and for x (always initialized to the start of x):
2320  ConstIterator1D xi = xs;
2321 
2322  for ( ; xi!=xe ; ++xi, ++ri )
2323  {
2324  dummy += (*ri) * (*xi);
2325  }
2326 
2327  *yi = dummy;
2328  }
2329 }
2330 
2336 inline void mult( MatrixView A,
2337  const ConstMatrixView& B,
2338  const ConstMatrixView& C )
2339 {
2340  // Check dimensions:
2341  assert( A.nrows() == B.nrows() );
2342  assert( A.ncols() == C.ncols() );
2343  assert( B.ncols() == C.nrows() );
2344 
2345  // Let's get the transpose of C, so that we can use 2D iterators to
2346  // access the columns (= rows of the transpose).
2347  ConstMatrixView CT = transpose(C);
2348 
2349  const Iterator2D ae = A.end();
2350  Iterator2D ai = A.begin();
2351  ConstIterator2D bi = B.begin();
2352 
2353  // This walks through the rows of A and B:
2354  for ( ; ai!=ae ; ++ai, ++bi )
2355  {
2356  const Iterator1D ace = ai->end();
2357  Iterator1D aci = ai->begin();
2358  ConstIterator2D cti = CT.begin();
2359 
2360  // This walks through the columns of A with a 1D iterator, and
2361  // at the same time through the rows of CT, which are the columns of
2362  // C, with a 2D iterator:
2363  for ( ; aci!=ace ; ++aci, ++cti )
2364  {
2365  // The operator * is used to compute the scalar product
2366  // between rows of B and rows of C.transpose().
2367  *aci = (*bi) * (*cti);
2368  }
2369  }
2370 }
2371 
2374 {
2375  return ConstMatrixView(m.mdata, m.mcr, m.mrr);
2376 }
2377 
2381 {
2382  return MatrixView(m.mdata, m.mcr, m.mrr);
2383 }
2384 
2405 inline void transform( VectorView y,
2406  double (&my_func)(double),
2407  ConstVectorView x )
2408 {
2409  // Check dimensions:
2410  assert( y.nelem()==x.nelem() );
2411 
2412  const ConstIterator1D xe = x.end();
2413  ConstIterator1D xi = x.begin();
2414  Iterator1D yi = y.begin();
2415  for ( ; xi!=xe; ++xi, ++yi )
2416  *yi = my_func(*xi);
2417 }
2418 
2437 inline void transform( MatrixView y,
2438  double (&my_func)(double),
2439  ConstMatrixView x )
2440 {
2441  // Check dimensions:
2442  assert( y.nrows()==x.nrows() );
2443  assert( y.ncols()==x.ncols() );
2444 
2445  const ConstIterator2D rxe = x.end();
2446  ConstIterator2D rx = x.begin();
2447  Iterator2D ry = y.begin();
2448  for ( ; rx!=rxe; ++rx, ++ry )
2449  {
2450  const ConstIterator1D cxe = rx->end();
2451  ConstIterator1D cx = rx->begin();
2452  Iterator1D cy = ry->begin();
2453  for ( ; cx!=cxe; ++cx, ++cy )
2454  *cy = my_func(*cx);
2455  }
2456 }
2457 
2459 inline Numeric max(const ConstVectorView& x)
2460 {
2461  // Initial value for max:
2462  Numeric max = x[0];
2463 
2464  const ConstIterator1D xe = x.end();
2465  ConstIterator1D xi = x.begin();
2466 
2467  for ( ; xi!=xe ; ++xi )
2468  {
2469  if ( *xi > max )
2470  max = *xi;
2471  }
2472 
2473  return max;
2474 }
2475 
2477 inline Numeric max(const ConstMatrixView& x)
2478 {
2479  // Initial value for max:
2480  Numeric max = x(0,0);
2481 
2482  const ConstIterator2D rxe = x.end();
2483  ConstIterator2D rx = x.begin();
2484 
2485  for ( ; rx!=rxe ; ++rx )
2486  {
2487  const ConstIterator1D cxe = rx->end();
2488  ConstIterator1D cx = rx->begin();
2489 
2490  for ( ; cx!=cxe ; ++cx )
2491  if ( *cx > max )
2492  max = *cx;
2493  }
2494 
2495  return max;
2496 }
2497 
2499 inline Numeric min(const ConstVectorView& x)
2500 {
2501  // Initial value for min:
2502  Numeric min = x[0];
2503 
2504  const ConstIterator1D xe = x.end();
2505  ConstIterator1D xi = x.begin();
2506 
2507  for ( ; xi!=xe ; ++xi )
2508  {
2509  if ( *xi < min )
2510  min = *xi;
2511  }
2512 
2513  return min;
2514 }
2515 
2517 inline Numeric min(const ConstMatrixView& x)
2518 {
2519  // Initial value for min:
2520  Numeric min = x(0,0);
2521 
2522  const ConstIterator2D rxe = x.end();
2523  ConstIterator2D rx = x.begin();
2524 
2525  for ( ; rx!=rxe ; ++rx )
2526  {
2527  const ConstIterator1D cxe = rx->end();
2528  ConstIterator1D cx = rx->begin();
2529 
2530  for ( ; cx!=cxe ; ++cx )
2531  if ( *cx < min )
2532  min = *cx;
2533  }
2534 
2535  return min;
2536 }
2537 
2538 
2539 #endif // matpackI_h
Matrix
The Matrix class.
Definition: matpackI.h:544
MatrixView::operator()
Numeric operator()(Index r, Index c) const
Plain const index operator.
Definition: matpackI.h:1670
Iterator1D::mx
Numeric * mx
Current position.
Definition: matpackI.h:192
transform
void transform(VectorView y, double(&my_func)(double), ConstVectorView x)
A generic transform function for vectors, which can be used to implement mathematical functions opera...
Definition: matpackI.h:2405
MatrixView
The MatrixView class.
Definition: matpackI.h:476
VectorView::VectorView
VectorView()
Default constructor.
Definition: matpackI.h:1282
ArrayOfMatrix
Array< Matrix > ArrayOfMatrix
An array of matrices.
Definition: matpackI.h:595
Iterator2D::operator!=
bool operator!=(const Iterator2D &other) const
Not equal operator, needed for algorithms like copy.
Definition: matpackI.h:849
ConstIterator2D::msv
ConstVectorView msv
Current position.
Definition: matpackI.h:373
MatrixView::operator=
MatrixView & operator=(const ConstMatrixView &v)
Assignment operator.
Definition: matpackI.h:1790
Vector::Vector
Vector()
Default constructor.
Definition: matpackI.h:1341
Tensor3
The Tensor3 class.
Definition: matpackIII.h:227
ConstIterator1D
The constant iterator class for sub vectors.
Definition: matpackI.h:199
ArrayOfVector
Array< Vector > ArrayOfVector
An array of vectors.
Definition: matpackI.h:589
transpose
ConstMatrixView transpose(ConstMatrixView m)
Const version of transpose.
Definition: matpackI.h:2373
MatrixView::MatrixView
MatrixView()
Default constructor.
Definition: matpackI.h:2045
ConstIterator2D::operator*
const ConstVectorView & operator*() const
Dereferencing.
Definition: matpackI.h:919
Iterator2D::mstride
Index mstride
Row stride.
Definition: matpackI.h:352
MatrixView::transpose
friend ConstMatrixView transpose(ConstMatrixView m)
Const version of transpose.
Definition: matpackI.h:2373
ConstIterator1D::mstride
Index mstride
Stride.
Definition: matpackI.h:215
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
ConstIterator1D::ConstIterator1D
ConstIterator1D()
Default constructor.
Definition: matpackI.h:777
Vector::resize
void resize(Index n)
Resize function.
Definition: matpackI.h:1467
ConstVectorView::ConstVectorView
ConstVectorView()
Default constructor.
Definition: matpackI.h:997
MatrixView::operator+=
MatrixView & operator+=(Numeric x)
Addition of scalar.
Definition: matpackI.h:1878
ConstMatrixView::nrows
Index nrows() const
Returns the number of rows.
Definition: matpackI.h:1491
copy
void copy(ConstIterator1D origin, const ConstIterator1D &end, Iterator1D target)
Copy data between begin and end to target.
Definition: matpackI.h:1319
Range::operator<<
friend std::ostream & operator<<(std::ostream &os, const SparseMatrixView &v)
ConstIterator2D::ConstIterator2D
ConstIterator2D()
Default constructor.
Definition: matpackI.h:875
ConstVectorView::mrange
Range mrange
The range of mdata that is actually used.
Definition: matpackI.h:265
Range::mstart
Index mstart
The start index.
Definition: matpackI.h:168
MatrixView::operator-=
MatrixView & operator-=(Numeric x)
Subtraction of scalar.
Definition: matpackI.h:1891
MatrixView::operator/=
MatrixView & operator/=(Numeric x)
Division by scalar.
Definition: matpackI.h:1865
ConstMatrixView::transpose
friend ConstMatrixView transpose(ConstMatrixView m)
Const version of transpose.
Definition: matpackI.h:2373
mult
void mult(VectorView y, const ConstMatrixView &M, const ConstVectorView &x)
Matrix Vector multiplication.
Definition: matpackI.h:2291
ConstMatrixView::mcr
Range mcr
The column range of mdata that is actually used.
Definition: matpackI.h:462
VectorView::operator/=
VectorView operator/=(Numeric x)
Division by scalar.
Definition: matpackI.h:1188
ConstMatrixView::mrr
Range mrr
The row range of mdata that is actually used.
Definition: matpackI.h:460
ConstIterator2D::operator++
ConstIterator2D & operator++()
Prefix increment operator.
Definition: matpackI.h:895
Tensor3View
The Tensor3View class.
Definition: matpackIII.h:151
Iterator1D::operator++
Iterator1D & operator++()
Prefix increment operator.
Definition: matpackI.h:752
Array< Numeric >
Iterator3D
Implementation of Tensors of Rank 3.
Definition: matpackIII.h:35
ConstVectorView::end
ConstIterator1D end() const
Return const iterator behind last element.
Definition: matpackI.h:981
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
ConstIterator2D::operator->
const ConstVectorView * operator->() const
The -> operator is needed, so that we can write i->begin() to get the 1D iterators.
Definition: matpackI.h:913
Matrix::~Matrix
~Matrix()
Destructor for Matrix.
Definition: matpackI.h:2259
operator<<
std::ostream & operator<<(std::ostream &os, const ConstVectorView &v)
Output operator.
Definition: matpackI.h:1035
Vector::operator=
Vector & operator=(const Vector &v)
Assignment from another Vector.
Definition: matpackI.h:1413
ConstMatrixView::ncols
Index ncols() const
Returns the number of columns.
Definition: matpackI.h:1497
ConstIterator1D::operator++
ConstIterator1D & operator++()
Prefix increment operator.
Definition: matpackI.h:797
max
Numeric max(const ConstVectorView &x)
Max function, vector version.
Definition: matpackI.h:2459
Iterator1D
The iterator class for sub vectors.
Definition: matpackI.h:178
ConstIterator2D::operator!=
bool operator!=(const ConstIterator2D &other) const
Not equal operator, needed for algorithms like copy.
Definition: matpackI.h:902
Numeric
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: arts.h:147
ConstVectorView::nelem
Index nelem() const
Returns the number of elements.
Definition: matpackI.h:937
Vector::~Vector
~Vector()
Destructor for Vector.
Definition: matpackI.h:1481
VectorView
The VectorView class.
Definition: matpackI.h:281
ConstVectorView::begin
ConstIterator1D begin() const
Return const iterator to first element.
Definition: matpackI.h:975
Range::Range
Range(Index start, Index extent, Index stride=1)
Definition: matpackI.h:611
ConstVectorView::sum
Numeric sum() const
The sum of all elements of a Vector.
Definition: matpackI.h:943
MatrixView::VectorView
friend class VectorView
Definition: matpackI.h:521
ConstIterator2D::mstride
Index mstride
Row stride.
Definition: matpackI.h:375
ConstVectorView::mdata
Numeric * mdata
Pointer to the plain C array that holds the data.
Definition: matpackI.h:267
ConstVectorView::operator[]
Numeric operator[](Index n) const
Plain const index operator.
Definition: matpackI.h:956
min
Numeric min(const ConstVectorView &x)
Min function, vector version.
Definition: matpackI.h:2499
ConstMatrixView::operator()
Numeric operator()(Index r, Index c) const
Plain const index operator.
Definition: matpackI.h:1503
Matrix::resize
void resize(Index r, Index c)
Resize function.
Definition: matpackI.h:2237
ConstIterator1D::operator!=
bool operator!=(const ConstIterator1D &other) const
Not equal operator, needed for algorithms like copy.
Definition: matpackI.h:804
VectorView::begin
ConstIterator1D begin() const
Return const iterator to first element.
Definition: matpackI.h:1095
Iterator2D::Iterator2D
Iterator2D()
Default constructor.
Definition: matpackI.h:822
ConstIterator2D
The const row iterator class for sub matrices.
Definition: matpackI.h:358
ConstMatrixView
A constant view of a Matrix.
Definition: matpackI.h:426
Iterator2D::operator->
VectorView * operator->()
The -> operator is needed, so that we can write i->begin() to get the 1D iterators.
Definition: matpackI.h:860
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
Iterator2D::msv
VectorView msv
Current position.
Definition: matpackI.h:350
Index
INDEX Index
The type to use for all integer numbers and indices.
Definition: arts.h:153
Matrix::Matrix
Matrix()
Default constructor.
Definition: matpackI.h:2123
VectorView::operator*=
VectorView operator*=(Numeric x)
Multiplication by scalar.
Definition: matpackI.h:1179
VectorView::operator-=
VectorView operator-=(Numeric x)
Subtraction of scalar.
Definition: matpackI.h:1206
Joker
Implementation of Matrix, Vector, and such stuff.
Definition: matpackI.h:111
Iterator1D::mstride
Index mstride
Stride.
Definition: matpackI.h:194
ConstMatrixView::ConstMatrixView
ConstMatrixView()
Default constructor.
Definition: matpackI.h:1575
Iterator1D::operator*
Numeric & operator*() const
Dereferencing.
Definition: matpackI.h:768
joker
Joker joker
Define the global joker objekt.
Definition: constants.cc:233
VectorView::operator=
VectorView operator=(const ConstVectorView &v)
Assignment operator.
Definition: matpackI.h:1127
ConstTensor3View
A constant view of a Tensor3.
Definition: matpackIII.h:93
ConstMatrixView::begin
ConstIterator2D begin() const
Return const iterator to first row.
Definition: matpackI.h:1558
VectorView::MatrixView
friend class MatrixView
Definition: matpackI.h:322
Matrix::operator=
Matrix & operator=(const Matrix &x)
Assignment operator from another matrix.
Definition: matpackI.h:2188
Range::SparseMatrixView
friend class SparseMatrixView
Definition: matpackI.h:159
VectorView::end
ConstIterator1D end() const
Return const iterator behind last element.
Definition: matpackI.h:1103
Iterator2D
The row iterator class for sub matrices.
Definition: matpackI.h:335
MatrixView::operator*=
MatrixView & operator*=(Numeric x)
Multiplication by scalar.
Definition: matpackI.h:1852
operator*
Numeric operator*(const ConstVectorView &a, const ConstVectorView &b)
Scalar product.
Definition: matpackI.h:2270
Iterator1D::operator!=
bool operator!=(const Iterator1D &other) const
Not equal operator, needed for algorithms like copy.
Definition: matpackI.h:759
ConstMatrixView::ConstVectorView
friend class ConstVectorView
Definition: matpackI.h:443
Iterator1D::Iterator1D
Iterator1D()
Default constructor.
Definition: matpackI.h:732
Vector
The Vector class.
Definition: matpackI.h:389
Range::mstride
Index mstride
The stride.
Definition: matpackI.h:173
ConstVectorView
A constant view of a Vector.
Definition: matpackI.h:232
VectorView::operator+=
VectorView operator+=(Numeric x)
Addition of scalar.
Definition: matpackI.h:1197
Array::nelem
Index nelem() const
Number of elements.
Definition: array.h:115
ConstVectorView::ConstMatrixView
friend class ConstMatrixView
Definition: matpackI.h:253
ConstIterator1D::mx
const Numeric * mx
Current position.
Definition: matpackI.h:213
Iterator2D::operator*
VectorView & operator*()
Dereferencing.
Definition: matpackI.h:866
Iterator2D::operator++
Iterator2D & operator++()
Prefix increment operator.
Definition: matpackI.h:842
arts.h
The global header file for ARTS.
ConstIterator1D::operator*
const Numeric & operator*() const
Dereferencing.
Definition: matpackI.h:813
VectorView::operator[]
Numeric operator[](Index n) const
Plain const index operator.
Definition: matpackI.h:1059