ARTS  2.3.1285(git:92a29ea9-dirty)
matpackI.h
Go to the documentation of this file.
1 /* Copyright (C) 2001-2019 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 
95 #ifndef matpackI_h
96 #define matpackI_h
97 
98 #include <Eigen/Dense>
99 #include <cassert>
100 #include "array.h"
101 #include "matpack.h"
102 
103 // Declare existance of some classes
104 class bofstream;
105 
106 // Declaration of Eigen types
107 typedef Eigen::Stride<Eigen::Dynamic, Eigen::Dynamic> StrideType;
108 typedef Eigen::Matrix<Numeric, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>
110 typedef Eigen::Map<MatrixType, 0, StrideType> MatrixViewMap;
111 typedef Eigen::Map<const MatrixType, 0, StrideType> ConstMatrixViewMap;
112 typedef Eigen::Matrix<Numeric, 4, 4, Eigen::RowMajor> Matrix4x4Type;
113 typedef Eigen::Map<Matrix4x4Type, 0, StrideType> Matrix4x4ViewMap;
114 typedef Eigen::Map<const Matrix4x4Type, 0, StrideType> ConstMatrix4x4ViewMap;
115 
126 class Joker {
127  // Nothing here.
128 };
129 
130 // Declare existence of the global joker object:
131 extern const Joker joker;
132 
133 // Declare the existence of class ConstMatrixView:
134 class ConstIterator1D;
135 
136 // Declare the existence of class VectorView:
137 class VectorView;
138 
139 // Declare the existence of class ConstVectorView:
140 class ConstVectorView;
141 
142 // Declare the existence of class ConstMatrixView:
143 class ConstMatrixView;
144 
160 class Range {
161  public:
162 
163  // Constructors:
164 
175  constexpr Range(Index start, Index extent, Index stride = 1)
176  : mstart(start), mextent(extent), mstride(stride) {
177  // Start must be >= 0:
178  assert(0 <= mstart);
179  // Extent also. Although internally negative extent means "to the end",
180  // this can not be created this way, only with the joker. Zero
181  // extent is allowed, though, which corresponds to an empty range.
182  assert(0 <= mextent);
183  // Stride can be anything except 0.
184  // SAB 2001-09-21: Allow 0 stride.
185  // assert( 0!=mstride);
186  }
187 
190  constexpr Range(Index start, Joker, Index stride = 1)
191  : mstart(start), mextent(-1), mstride(stride) {
192  // Start must be >= 0:
193  assert(0 <= mstart);
194  }
195 
199  constexpr Range(Joker, Index stride = 1) : mstart(0), mextent(-1), mstride(stride) {
200  // Nothing to do here.
201  };
202 
208  constexpr Range(Index max_size, const Range& r)
209  : mstart(r.mstart), mextent(r.mextent), mstride(r.mstride) {
210  // Start must be >= 0:
211  assert(0 <= mstart);
212  // ... and < max_size:
213  assert(mstart < max_size);
214 
215  // Stride must be != 0:
216  assert(0 != mstride);
217 
218  // Convert negative extent (joker) to explicit extent
219  if (mextent < 0) {
220  if (0 < mstride)
221  mextent = 1 + (max_size - 1 - mstart) / mstride;
222  else
223  mextent = 1 + (0 - mstart) / mstride;
224  } else {
225  #ifndef NDEBUG
226  // Check that extent is ok:
227  Index fin = mstart + (mextent - 1) * mstride;
228  assert(0 <= fin);
229  assert(fin < max_size);
230  #endif
231  }
232  }
233 
239  constexpr Range(const Range& p, const Range& n)
240  : mstart(p.mstart + n.mstart * p.mstride),
241  mextent(n.mextent),
242  mstride(p.mstride * n.mstride) {
243  // We have to juggle here a bit with previous, new, and resulting
244  // quantities. I.e.;
245  // p.mstride: Previous stride
246  // n.mstride: New stride (as specified)
247  // mstride: Resulting stride (old*new)
248 
249  // Get the previous final element:
250  Index prev_fin = p.mstart + (p.mextent - 1) * p.mstride;
251 
252  // Resulting start must be >= previous start:
253  assert(p.mstart <= mstart);
254  // and <= prev_fin, except for Joker:
255  assert(mstart <= prev_fin || mextent == -1);
256 
257  // Resulting stride must be != 0:
258  assert(0 != mstride);
259 
260  // Convert negative extent (joker) to explicit extent
261  if (mextent < 0) {
262  if (0 < mstride)
263  mextent = 1 + (prev_fin - mstart) / mstride;
264  else
265  mextent = 1 + (p.mstart - mstart) / mstride;
266  } else {
267  #ifndef NDEBUG
268  // Check that extent is ok:
269  Index fin = mstart + (mextent - 1) * mstride;
270  assert(p.mstart <= fin);
271  assert(fin <= prev_fin);
272  #endif
273  }
274  };
275 
276  // Friends:
277  friend class ConstVectorView;
278  friend class VectorView;
279  friend class Vector;
280  friend class ConstMatrixView;
281  friend class MatrixView;
282  friend class Matrix;
283  friend class Iterator2D;
284  friend class Iterator3D;
285  friend class Iterator4D;
286  friend class Iterator5D;
287  friend class Iterator6D;
288  friend class Iterator7D;
289  friend class ConstIterator2D;
290  friend class ConstIterator3D;
291  friend class ConstIterator4D;
292  friend class ConstIterator5D;
293  friend class ConstIterator6D;
294  friend class ConstIterator7D;
295  friend class ConstTensor3View;
296  friend class Tensor3View;
297  friend class Tensor3;
298  friend class ConstTensor4View;
299  friend class Tensor4View;
300  friend class Tensor4;
301  friend class ConstTensor5View;
302  friend class Tensor5View;
303  friend class Tensor5;
304  friend class ConstTensor6View;
305  friend class Tensor6View;
306  friend class Tensor6;
307  friend class ConstTensor7View;
308  friend class Tensor7View;
309  friend class Tensor7;
310  friend class Sparse;
312  friend class ComplexVectorView;
313  friend class ComplexVector;
315  friend class ComplexMatrixView;
316  friend class ComplexMatrix;
317  friend class ComplexIterator2D;
319 
320  friend void mult_general(VectorView,
321  const ConstMatrixView&,
322  const ConstVectorView&);
323 
324  // Member functions:
325 
327  constexpr Index get_start() const { return mstart; }
329  constexpr Index get_extent() const { return mextent; }
331  constexpr Index get_stride() const { return mstride; }
332 
334  constexpr Range operator()(const Range r) const {
335  return (r.mextent < 0) ? (mextent < 0) ? Range(mstart + r.mstart * mstride,
336  joker,
337  r.mstride * mstride)
338  : Range(mstart + r.mstart * mstride,
339  mextent,
340  r.mstride * mstride)
341  : Range(mstart + r.mstart * mstride,
342  r.mextent,
343  r.mstride * mstride);
344  }
345 
346  constexpr Index operator()(const Index i) const { return mstart + i * mstride; };
347 
348  private:
350  Index mstart;
356 };
357 
360 class Iterator1D {
361  public:
364  using pointer = Numeric*;
365  using reference = Numeric&;
366  using iterator_category = std::random_access_iterator_tag;
367 
369  Iterator1D() = default;
370 
373  : mx(x), mstride(stride) { /* Nothing to do here. */
374  }
375 
376  // Operators:
377 
380  mx += mstride;
381  return *this;
382  }
383 
385  Numeric& operator*() const { return *mx; }
386 
388  bool operator!=(const Iterator1D& other) const {
389  if (mx != other.mx)
390  return true;
391  else
392  return false;
393  }
394 
395 #ifdef __GLIBCXX__
396  bool operator==(const Iterator1D& other) const { return !operator!=(other); }
397 
398  Index operator-(const Iterator1D& other) const {
399  return (Index)(mx - other.mx) / mstride;
400  }
401 #endif
402 
407  friend void copy(ConstIterator1D origin,
408  const ConstIterator1D& end,
409  Iterator1D target);
410 
411  private:
413  Numeric* mx{nullptr};
415  Index mstride{0};
416 };
417 
421  public:
423  using value_type = const Numeric;
424  using pointer = const Numeric*;
425  using reference = const Numeric&;
426  using iterator_category = std::random_access_iterator_tag;
427 
429  ConstIterator1D() = default;
430 
432  ConstIterator1D(const Numeric* x, Index stride)
433  : mx(x), mstride(stride) { /* Nothing to do here. */
434  }
435 
436  // Operators:
439  mx += mstride;
440  return *this;
441  }
442 
444  const Numeric& operator*() const { return *mx; }
445 
447  bool operator!=(const ConstIterator1D& other) const {
448  if (mx != other.mx)
449  return true;
450  else
451  return false;
452  }
453 
454  friend void copy(ConstIterator1D origin,
455  const ConstIterator1D& end,
456  Iterator1D target);
457 
458  private:
460  const Numeric* mx{nullptr};
462  Index mstride{0};
463 };
464 
465 // Declare the vector class:
466 class Vector;
467 
468 // Declare the MatrixView class
469 class MatrixView;
470 
477  public:
478  constexpr ConstVectorView(const ConstVectorView&) = default;
479  constexpr ConstVectorView(ConstVectorView&&) = default;
480  ConstVectorView& operator=(const ConstVectorView&) = default;
481  ConstVectorView& operator=(ConstVectorView&&) = default;
482 
483  // Typedef for compatibility with STL
485 
486  // Member functions:
487 
489  bool empty() const;
490 
500  Index nelem() const;
501 
503  Numeric sum() const;
504 
505  // Const index operators:
507  Numeric operator[](Index n) const { // Check if index is valid:
508  assert(0 <= n);
509  assert(n < mrange.mextent);
510  return get(n);
511  }
512 
514  Numeric get(Index n) const {
515  return *(mdata + mrange.mstart + n * mrange.mstride);
516  }
517 
521  ConstVectorView operator[](const Range& r) const;
522 
523  friend Numeric operator*(const ConstVectorView& a, const ConstVectorView& b);
524 
525  // Functions returning iterators:
526 
528  ConstIterator1D begin() const;
529 
531  ConstIterator1D end() const;
532 
534  operator ConstMatrixView() const;
535 
537  virtual ~ConstVectorView() = default;
538 
539  // Friends:
540  friend class VectorView;
541  friend class ConstIterator2D;
542  friend class ConstMatrixView;
543  friend class ConstTensor3View;
544  friend class ConstTensor4View;
545  friend class ConstTensor5View;
546  friend class ConstTensor6View;
547  friend class ConstTensor7View;
549  friend int poly_root_solve(Matrix& roots, Vector& coeffs);
550  friend void mult(VectorView, const ConstMatrixView&, const ConstVectorView&);
551  friend void mult(VectorView, const Sparse&, ConstVectorView);
552  friend void transpose_mult(VectorView, const Sparse&, ConstVectorView);
553  friend void mult_general(VectorView,
554  const ConstMatrixView&,
555  const ConstVectorView&);
556  friend void lubacksub(VectorView,
559  const ArrayOfIndex&);
561 
566 
569  ConstVectorView(const Numeric& a);
570 
571  protected:
572  // Constructors:
573  ConstVectorView() = default;
574 
577  ConstVectorView(Numeric* data, const Range& range);
578 
589  ConstVectorView(Numeric* data, const Range& p, const Range& n);
590 
591  // Data members:
592  // -------------
594  Range mrange{0, 0};
596  Numeric* mdata{nullptr};
597 };
598 
610 class VectorView : public ConstVectorView {
611  public:
612  // Make const methods visible from base class
614  using ConstVectorView::end;
615  using ConstVectorView::operator[];
616  using ConstVectorView::get;
617 
618  constexpr VectorView(const VectorView&) = default;
619 
622  VectorView(const Vector&);
623 
625  VectorView(Vector& v);
626 
627  // Typedef for compatibility with STL
629 
631  Numeric& operator[](Index n) { // Check if index is valid:
632  assert(0 <= n);
633  assert(n < mrange.mextent);
634  return get(n);
635  }
636 
638  Numeric& get(Index n) {
639  return *(mdata + mrange.mstart + n * mrange.mstride);
640  }
641 
645  VectorView operator[](const Range& r);
646 
647  // Iterators:
648 
650  Iterator1D begin();
651 
653  Iterator1D end();
654 
655  // Assignment operators:
656 
661  VectorView& operator=(const ConstVectorView& v);
662 
668  VectorView& operator=(const VectorView& v);
669 
672  VectorView& operator=(const Vector& v);
673 
674  VectorView& operator=(const Array<Numeric>& v);
675 
678  VectorView& operator=(Numeric x);
679 
680  // Other operators:
681 
683  VectorView operator*=(Numeric x);
684 
686  VectorView operator/=(Numeric x);
687 
690 
692  VectorView operator-=(Numeric x);
693 
695  VectorView operator*=(const ConstVectorView& x);
696 
698  VectorView operator/=(const ConstVectorView& x);
699 
702 
704  VectorView operator-=(const ConstVectorView& x);
705 
707  operator MatrixView();
708 
714  const Numeric* get_c_array() const;
715 
721  Numeric* get_c_array();
722 
724  virtual ~VectorView() = default;
725 
726  // Friends:
727  friend class ConstIterator2D;
728  friend class Iterator2D;
729  friend class MatrixView;
730  friend class Tensor3View;
731  friend class Tensor4View;
732  friend class Tensor5View;
733  friend class Tensor6View;
734  friend class Tensor7View;
735  friend class ComplexVectorView;
736 
739  VectorView(Numeric& a);
740 
741  protected:
742  // Constructors:
743  VectorView() = default;
744 
747  VectorView(Numeric* data, const Range& range);
748 
759  VectorView(Numeric* data, const Range& p, const Range& n);
760 };
761 
765 class Iterator2D {
766  public:
767  // Constructors:
769  Iterator2D() = default;
770 
772  Iterator2D(const VectorView& x, Index stride)
773  : msv(x), mstride(stride) { /* Nothing to do here. */
774  }
775 
776  // Operators:
779  msv.mdata += mstride;
780  return *this;
781  }
782 
784  bool operator!=(const Iterator2D& other) const {
785  if (msv.mdata + msv.mrange.mstart !=
786  other.msv.mdata + other.msv.mrange.mstart)
787  return true;
788  else
789  return false;
790  }
791 
794  VectorView* operator->() { return &msv; }
795 
797  VectorView& operator*() { return msv; }
798 
799  private:
803  Index mstride{0};
804 };
805 
810  public:
811  // Constructors:
813  ConstIterator2D() = default;
814 
817  : msv(x), mstride(stride) { /* Nothing to do here. */
818  }
819 
820  // Operators:
823  msv.mdata += mstride;
824  return *this;
825  }
826 
828  bool operator!=(const ConstIterator2D& other) const {
829  if (msv.mdata + msv.mrange.mstart !=
830  other.msv.mdata + other.msv.mrange.mstart)
831  return true;
832  else
833  return false;
834  }
835 
838  const ConstVectorView* operator->() const { return &msv; }
839 
841  const ConstVectorView& operator*() const { return msv; }
842 
843  private:
847  Index mstride{0};
848 };
849 
860 class Vector : public VectorView {
861  public:
862  // Constructors:
863  Vector() = default;
864 
866  Vector(std::initializer_list<Numeric> init);
867 
869  explicit Vector(Index n);
870 
872  Vector(Index n, Numeric fill);
873 
881  Vector(Numeric start, Index extent, Numeric stride);
882 
888  Vector(const ConstVectorView& v);
889 
892  Vector(const Vector& v);
893  Vector(Vector&& v) noexcept : VectorView(std::forward<VectorView>(v)) {
894  v.mdata = nullptr;
895  }
896 
898  Vector(const std::vector<Numeric>&);
899 
900  // Assignment operators:
901 
926  Vector& operator=(const Vector& v);
927 
929  Vector& operator=(Vector&& v) noexcept;
930 
932  Vector& operator=(std::initializer_list<Numeric> v);
933 
950  Vector& operator=(const Array<Numeric>& v);
951 
954  Vector& operator=(Numeric x);
955 
959  void resize(Index n);
960 
962  friend void swap(Vector& v1, Vector& v2);
963 
966  virtual ~Vector();
967 };
968 
969 // Declare class Matrix:
970 class Matrix;
971 
983  public:
984  constexpr ConstMatrixView(const ConstMatrixView&) = default;
985  constexpr ConstMatrixView(ConstMatrixView&&) = default;
986  ConstMatrixView& operator=(const ConstMatrixView&) = default;
987  ConstMatrixView& operator=(ConstMatrixView&&) = default;
988 
989  // Typedef for compatibility with STL
991 
992  // Member functions:
993  bool empty() const;
994  Index nrows() const;
995  Index ncols() const;
996 
997  // Const index operators:
999  Numeric operator()(Index r, Index c) const { // Check if indices are valid:
1000  assert(0 <= r);
1001  assert(0 <= c);
1002  assert(r < mrr.mextent);
1003  assert(c < mcr.mextent);
1004 
1005  return get(r, c);
1006  }
1007 
1009  Numeric get(Index r, Index c) const {
1010  return *(mdata + mrr.mstart + r * mrr.mstride + mcr.mstart +
1011  c * mcr.mstride);
1012  }
1013 
1014  ConstMatrixView operator()(const Range& r, const Range& c) const;
1015  ConstVectorView operator()(const Range& r, Index c) const;
1016  ConstVectorView operator()(Index r, const Range& c) const;
1017 
1018  // Functions returning iterators:
1019  ConstIterator2D begin() const;
1020  ConstIterator2D end() const;
1021 
1022  // View on diagonal vector
1023  ConstVectorView diagonal() const;
1024 
1026  virtual ~ConstMatrixView() = default;
1027 
1028  // Friends:
1029  friend class MatrixView;
1030  friend class ConstIterator3D;
1031  friend class ConstVectorView;
1032  friend class ConstTensor3View;
1033  friend class ConstTensor4View;
1034  friend class ConstTensor5View;
1035  friend class ConstTensor6View;
1036  friend class ConstTensor7View;
1039  friend int poly_root_solve(Matrix& roots, Vector& coeffs);
1040  friend void mult(VectorView, const ConstMatrixView&, const ConstVectorView&);
1041  friend void mult(MatrixView, const ConstMatrixView&, const ConstMatrixView&);
1042  friend void mult(MatrixView, const Sparse&, const ConstMatrixView&);
1043  friend void mult(MatrixView, const ConstMatrixView&, const Sparse&);
1044  friend void mult_general(VectorView,
1045  const ConstMatrixView&,
1046  const ConstVectorView&);
1047  friend void mult_general(MatrixView,
1048  const ConstMatrixView&,
1049  const ConstMatrixView&);
1050  friend void ludcmp(Matrix&, ArrayOfIndex&, ConstMatrixView);
1051  friend void lubacksub(VectorView,
1054  const ArrayOfIndex&);
1055  friend void inv(MatrixView, ConstMatrixView);
1057 
1060 
1063 
1064  protected:
1065  // Constructors:
1066  ConstMatrixView() = default;
1067  ConstMatrixView(Numeric* data, const Range& r, const Range& c);
1069  const Range& pr,
1070  const Range& pc,
1071  const Range& nr,
1072  const Range& nc);
1073 
1074  // Data members:
1075  // -------------
1077  Range mrr{0, 0, 1};
1079  Range mcr{0, 0, 1};
1081  Numeric* mdata{nullptr};
1082 };
1083 
1093 class MatrixView : public ConstMatrixView {
1094  public:
1095  // Make const methods visible from base class
1096  using ConstMatrixView::begin;
1097  using ConstMatrixView::end;
1098  using ConstMatrixView::operator();
1099  using ConstMatrixView::get;
1100 
1101  constexpr MatrixView(const MatrixView&) = default;
1102 
1103  // Typedef for compatibility with STL
1105 
1106  // Index Operators:
1108  Numeric& operator()(Index r, Index c) { // Check if indices are valid:
1109  assert(0 <= r);
1110  assert(0 <= c);
1111  assert(r < mrr.mextent);
1112  assert(c < mcr.mextent);
1113 
1114  return get(r, c);
1115  }
1116 
1118  Numeric& get(Index r, Index c) {
1119  return *(mdata + mrr.mstart + r * mrr.mstride + mcr.mstart +
1120  c * mcr.mstride);
1121  }
1122 
1123  MatrixView operator()(const Range& r, const Range& c);
1124  VectorView operator()(const Range& r, Index c);
1125  VectorView operator()(Index r, const Range& c);
1126 
1127  // Functions returning iterators:
1128  Iterator2D begin();
1129  Iterator2D end();
1130 
1131  // Assignment operators:
1132  MatrixView& operator=(const ConstMatrixView& v);
1133  MatrixView& operator=(const MatrixView& v);
1134  MatrixView& operator=(const Matrix& v);
1135  MatrixView& operator=(const ConstVectorView& v);
1136  MatrixView& operator=(Numeric x);
1137 
1138  // Other operators:
1139  MatrixView& operator*=(Numeric x);
1140  MatrixView& operator/=(Numeric x);
1142  MatrixView& operator-=(Numeric x);
1143 
1144  MatrixView& operator*=(const ConstMatrixView& x);
1145  MatrixView& operator/=(const ConstMatrixView& x);
1147  MatrixView& operator-=(const ConstMatrixView& x);
1148 
1149  MatrixView& operator*=(const ConstVectorView& x);
1150  MatrixView& operator/=(const ConstVectorView& x);
1152  MatrixView& operator-=(const ConstVectorView& x);
1153 
1154  // Conversion to a plain C-array
1155  const Numeric* get_c_array() const;
1156  Numeric* get_c_array();
1157 
1159  virtual ~MatrixView() = default;
1160 
1161  // Friends:
1162  friend class VectorView;
1163  friend class Iterator3D;
1164  friend class Tensor3View;
1165  friend class Tensor4View;
1166  friend class Tensor5View;
1167  friend class Tensor6View;
1168  friend class Tensor7View;
1169  friend class ComplexMatrixView;
1171  friend MatrixView transpose(MatrixView m);
1172  friend void mult(MatrixView, const ConstMatrixView&, const ConstMatrixView&);
1173 
1174  protected:
1175  // Constructors:
1176  MatrixView() = default;
1177  MatrixView(Numeric* data, const Range& r, const Range& c);
1179  const Range& pr,
1180  const Range& pc,
1181  const Range& nr,
1182  const Range& nc);
1183 };
1184 
1193 class Matrix : public MatrixView {
1194  public:
1195  // Constructors:
1196  Matrix() = default;
1197  Matrix(Index r, Index c);
1198  Matrix(Index r, Index c, Numeric fill);
1199  Matrix(const ConstMatrixView& v);
1200  Matrix(const Matrix& v);
1201  Matrix(Matrix&& v) noexcept : MatrixView(std::forward<MatrixView>(v)) {
1202  v.mdata = nullptr;
1203  }
1204 
1205  // Assignment operators:
1206  Matrix& operator=(const Matrix& x);
1207  Matrix& operator=(Matrix&& x) noexcept;
1208  Matrix& operator=(Numeric x);
1209  Matrix& operator=(const ConstVectorView& v);
1210 
1211  // Resize function:
1212  void resize(Index r, Index c);
1213 
1214  // Swap function:
1215  friend void swap(Matrix& m1, Matrix& m2);
1216 
1217  // Destructor:
1218  virtual ~Matrix();
1219 
1220  Numeric* get_raw_data() { return mdata; }
1221 };
1222 
1223 // Function declarations:
1224 // ----------------------
1225 
1226 void copy(ConstIterator1D origin,
1227  const ConstIterator1D& end,
1228  Iterator1D target);
1229 
1231 void copy(Numeric x, Iterator1D target, const Iterator1D& end);
1232 
1233 void copy(ConstIterator2D origin,
1234  const ConstIterator2D& end,
1235  Iterator2D target);
1236 
1237 void copy(Numeric x, Iterator2D target, const Iterator2D& end);
1238 
1239 void mult(VectorView y, const ConstMatrixView& M, const ConstVectorView& x);
1240 
1241 void mult_general(MatrixView A,
1242  const ConstMatrixView& B,
1243  const ConstMatrixView& C);
1244 
1245 void mult(MatrixView A, const ConstMatrixView& B, const ConstMatrixView& C);
1246 
1247 void mult_general(MatrixView A,
1248  const ConstMatrixView& B,
1249  const ConstMatrixView& C);
1250 
1251 void cross3(VectorView c, const ConstVectorView& a, const ConstVectorView& b);
1252 
1254 
1256 
1258 
1260 
1261 void transform(VectorView y, double (&my_func)(double), ConstVectorView x);
1262 
1263 void transform(MatrixView y, double (&my_func)(double), ConstMatrixView x);
1264 
1265 Numeric max(const ConstVectorView& x);
1266 
1267 Numeric max(const ConstMatrixView& x);
1268 
1269 Numeric min(const ConstVectorView& x);
1270 
1271 Numeric min(const ConstMatrixView& x);
1272 
1273 Numeric mean(const ConstVectorView& x);
1274 
1275 Numeric mean(const ConstMatrixView& x);
1276 
1277 Numeric operator*(const ConstVectorView& a, const ConstVectorView& b);
1278 
1279 std::ostream& operator<<(std::ostream& os, const ConstVectorView& v);
1280 
1281 std::ostream& operator<<(std::ostream& os, const ConstMatrixView& v);
1282 
1283 std::ostream& operator<<(std::ostream& os, const Range& r);
1284 
1285 // Converts constant matrix to constant eigen map
1287 // Converts constant vector to constant eigen row-view
1289 // Converts constant vector to constant eigen row-view
1291 // Converts constant vector to constant eigen row-view
1293 // Converts constant vector to constant eigen column-view
1295 // Converts matrix to eigen map
1297 // Converts vector to eigen map row-view
1299 // Converts vector to eigen map row-view
1301 // Converts vector to eigen map row-view
1303 // Converts vector to eigen map column-view
1305 
1307 // Helper function for debugging
1308 #ifndef NDEBUG
1309 
1311 
1312 #endif
1313 
1315 #endif // matpackI_h
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
Numeric & operator*() const
Dereferencing.
Definition: matpackI.h:385
Numeric * pointer
Definition: matpackI.h:364
constexpr Range(Joker, Index stride=1)
Constructor with just a joker.
Definition: matpackI.h:199
const Numeric * mx
Current position.
Definition: matpackI.h:460
Iterator1D & operator++()
Prefix increment operator.
Definition: matpackI.h:379
The VectorView class.
Definition: matpackI.h:610
Complex * mdata
Pointer to the plain C array that holds the data.
Definition: complex.h:353
Range mrange
The range of mdata that is actually used.
Definition: complex.h:351
bool operator!=(const Iterator1D &other) const
Not equal operator, needed for algorithms like copy.
Definition: matpackI.h:388
void transpose_mult(VectorView y, const Sparse &M, ConstVectorView x)
Sparse matrix - Vector multiplication.
Definition: matpackII.cc:452
The outermost iterator class for rank 6 tensors.
Definition: matpackVI.h:40
Index mstride
The stride.
Definition: matpackI.h:355
Vector(Vector &&v) noexcept
Definition: matpackI.h:893
The Tensor4View class.
Definition: matpackIV.h:284
ConstIterator1D begin() const
Return const iterator to first element.
Definition: matpackI.cc:67
constexpr Range operator()(const Range r) const
Range of range.
Definition: matpackI.h:334
void lubacksub(VectorView x, ConstMatrixView LU, ConstVectorView b, const ArrayOfIndex &indx)
LU backsubstitution.
Definition: lin_alg.cc:91
Const version of Iterator4D.
Definition: matpackIV.h:77
A constant view of a Tensor7.
Definition: matpackVII.h:147
void mult_general(MatrixView A, const ConstMatrixView &B, const ConstMatrixView &C)
General matrix multiplication.
Definition: matpackI.cc:1346
VectorView * operator->()
The -> operator is needed, so that we can write i->begin() to get the 1D iterators.
Definition: matpackI.h:794
The Tensor7View class.
Definition: matpackVII.h:1286
Index mstart
The start index.
Definition: matpackI.h:346
Numeric * mdata
Pointer to the plain C array that holds the data.
Definition: matpackI.h:1081
Eigen::Map< MatrixType, 0, StrideType > MatrixViewMap
Definition: matpackI.h:110
Numeric value_type
Definition: matpackI.h:363
The Vector class.
Definition: matpackI.h:860
The MatrixView class.
Definition: matpackI.h:1093
Implementation of Tensors of Rank 4.
Definition: matpackIV.h:38
A constant view of a Tensor6.
Definition: matpackVI.h:149
ConstMatrixView transpose(ConstMatrixView m)
Const version of transpose.
Definition: matpackI.cc:1444
The Sparse class.
Definition: matpackII.h:60
ConstMatrixViewMap MapToEigenCol(const ConstVectorView &A)
Definition: matpackI.cc:1673
VectorView msv
Current position.
Definition: matpackI.h:801
The Tensor4 class.
Definition: matpackIV.h:421
The range class.
Definition: matpackI.h:160
Numeric & operator[](Index n)
Plain Index operator.
Definition: matpackI.h:631
Const version of Iterator6D.
Definition: matpackVI.h:87
Eigen::Matrix< Numeric, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > MatrixType
Definition: matpackI.h:109
std::ostream & operator<<(std::ostream &os, const ConstVectorView &v)
Definition: matpackI.cc:107
constexpr Index operator()(const Index i) const
Definition: matpackI.h:346
Eigen::Map< Matrix4x4Type, 0, StrideType > Matrix4x4ViewMap
Definition: matpackI.h:113
Numeric get(Index r, Index c) const
Get element implementation without assertions.
Definition: matpackI.h:1009
ConstMatrix4x4ViewMap MapToEigen4x4(const ConstMatrixView &A)
Definition: matpackI.cc:1720
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.cc:1476
ConstVectorView msv
Current position.
Definition: matpackI.h:845
The ComplexVectorView class.
Definition: complex.h:367
invlib::Vector< ArtsVector > Vector
invlib wrapper type for ARTS vectors.
Definition: oem.h:32
bool operator==(const QuantumIdentifier &a, const QuantumIdentifier &b)
Is everything the same between the identifiers.
Definition: quantum.h:702
Index difference_type
Definition: matpackI.h:362
The Tensor6View class.
Definition: matpackVI.h:621
Index mstride
Row stride.
Definition: complex.h:560
The row iterator class for sub matrices.
Definition: matpackI.h:765
The Tensor7 class.
Definition: matpackVII.h:2382
Eigen::Stride< Eigen::Dynamic, Eigen::Dynamic > StrideType
Definition: matpackI.h:104
ConstIterator1D end() const
Return const iterator behind last element.
Definition: matpackI.cc:71
Numeric & reference
Definition: matpackI.h:365
constexpr Index get_start() const
Returns the start index of the range.
Definition: matpackI.h:327
G0 G2 FVC Y DV Numeric Numeric Numeric Zeeman LowerQuantumNumbers void * data
bool operator!=(const ConstIterator2D &other) const
Not equal operator, needed for algorithms like copy.
Definition: matpackI.h:828
const Numeric value_type
Definition: matpackI.h:423
const ConstVectorView * operator->() const
The -> operator is needed, so that we can write i->begin() to get the 1D iterators.
Definition: matpackI.h:838
A constant view of a Tensor4.
Definition: matpackIV.h:133
const Joker joker
This file contains the definition of Array.
ConstIterator2D begin() const
Return const iterator to first row.
Definition: matpackI.cc:469
bool operator!=(const QuantumIdentifier &a, const QuantumIdentifier &b)
Is anything different between the identifiers.
Definition: quantum.h:732
constexpr Range(const Range &p, const Range &n)
Constructor of a new range relative to an old range.
Definition: matpackI.h:239
Iterator1D(Numeric *x, Index stride)
Explicit constructor.
Definition: matpackI.h:372
The const row iterator class for sub matrices.
Definition: matpackI.h:809
The Tensor3 class.
Definition: matpackIII.h:339
void swap(ComplexVector &v1, ComplexVector &v2)
Swaps two objects.
Definition: complex.cc:731
The ComplexMatrix class.
Definition: complex.h:858
The Joker class.
Definition: matpackI.h:126
const Numeric & operator*() const
Dereferencing.
Definition: matpackI.h:444
Iterator2D(const VectorView &x, Index stride)
Explicit constructor.
Definition: matpackI.h:772
The Tensor3View class.
Definition: matpackIII.h:239
Numeric debug_matrixview_get_elem(MatrixView &mv, Index r, Index c)
Helper function to access matrix elements.
Definition: matpackI.cc:1745
Numeric get(Index n) const
Get element implementation without assertions.
Definition: matpackI.h:514
std::random_access_iterator_tag iterator_category
Definition: matpackI.h:426
bool operator!=(const Iterator2D &other) const
Not equal operator, needed for algorithms like copy.
Definition: matpackI.h:784
constexpr Index get_extent() const
Returns the extent of the range.
Definition: matpackI.h:329
void cross3(VectorView c, const ConstVectorView &a, const ConstVectorView &b)
cross3
Definition: matpackI.cc:1393
Eigen::Map< const Matrix4x4Type, 0, StrideType > ConstMatrix4x4ViewMap
Definition: matpackI.h:114
Complex * mdata
Pointer to the plain C array that holds the data.
Definition: complex.h:719
Numeric operator[](Index n) const
Plain const index operator.
Definition: matpackI.h:507
ConstIterator2D end() const
Return const iterator behind last row.
Definition: matpackI.cc:474
The const row iterator class for sub matrices.
Definition: complex.h:522
Index difference_type
Definition: matpackI.h:422
Matrix(Matrix &&v) noexcept
Definition: matpackI.h:1201
Numeric operator()(Index r, Index c) const
Plain const index operator.
Definition: matpackI.h:999
Eigen::Map< const MatrixType, 0, StrideType > ConstMatrixViewMap
Definition: matpackI.h:111
A constant view of a Tensor5.
Definition: matpackV.h:143
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:33
ConstMatrixViewMap MapToEigenRow(const ConstVectorView &A)
Definition: matpackI.cc:1668
The Matrix class.
Definition: matpackI.h:1193
Implementation of Tensors of Rank 7.
Definition: matpackVII.h:36
constexpr Index get_stride() const
Returns the stride of the range.
Definition: matpackI.h:331
Eigen::Matrix< Numeric, 4, 4, Eigen::RowMajor > Matrix4x4Type
Definition: matpackI.h:112
ConstIterator2D(const ConstVectorView &x, Index stride)
Explicit constructor.
Definition: matpackI.h:816
Index mextent
The number of elements.
Definition: matpackI.h:353
ConstMatrixViewMap MapToEigen(const ConstMatrixView &A)
Definition: matpackI.cc:1652
Const version of Iterator5D.
Definition: matpackV.h:85
The ComplexVector class.
Definition: complex.h:573
void diagonalize(MatrixView P, VectorView WR, VectorView WI, ConstMatrixView A)
Matrix Diagonalization.
Definition: lin_alg.cc:245
The Tensor5View class.
Definition: matpackV.h:333
This can be used to make arrays out of anything.
Definition: array.h:40
Numeric mean(const ConstVectorView &x)
Mean function, vector version.
Definition: matpackI.cc:1589
Iterator2D & operator++()
Prefix increment operator.
Definition: matpackI.h:778
ConstIterator1D & operator++()
Prefix increment operator.
Definition: matpackI.h:438
Implementation of Tensors of Rank 5.
Definition: matpackV.h:38
VectorView & operator*()
Dereferencing.
Definition: matpackI.h:797
Workspace & init(Workspace &ws)
Numeric operator*(const ConstVectorView &a, const ConstVectorView &b)
Scalar product.
Definition: matpackI.cc:1092
ConstIterator2D const_iterator
Definition: matpackI.h:990
void inv(MatrixView Ainv, ConstMatrixView A)
Matrix Inverse.
Definition: lin_alg.cc:167
Const version of Iterator7D.
Definition: matpackVII.h:84
A constant view of a Tensor3.
Definition: matpackIII.h:132
The Tensor6 class.
Definition: matpackVI.h:1088
constexpr Range(Index start, Index extent, Index stride=1)
Explicit constructor.
Definition: matpackI.h:175
A constant view of a Vector.
Definition: matpackI.h:476
const ConstVectorView & operator*() const
Dereferencing.
Definition: matpackI.h:841
Index nelem(const Lines &l)
Number of lines.
Range mcr
The column range of mdata that is actually used.
Definition: complex.h:717
Binary output file stream class.
Definition: bofstream.h:42
constexpr Rational start(Rational Ju, Rational Jl, Polarization type) noexcept
Gives the lowest M for a polarization type of this transition.
Definition: zeemandata.h:77
Numeric * mdata
Pointer to the plain C array that holds the data.
Definition: matpackI.h:596
A constant view of a Matrix.
Definition: matpackI.h:982
constexpr Range(Index max_size, const Range &r)
Constructor which converts a range with joker to an explicit range.
Definition: matpackI.h:208
const Numeric * pointer
Definition: matpackI.h:424
Implementation of Tensors of Rank 3.
Definition: matpackIII.h:34
std::random_access_iterator_tag iterator_category
Definition: matpackI.h:366
A constant view of a ComplexMatrix.
Definition: complex.h:618
Numeric max(const ConstVectorView &x)
Max function, vector version.
Definition: matpackI.cc:1521
Numeric * mx
Current position.
Definition: matpackI.h:413
Range mrange
The range of mdata that is actually used.
Definition: matpackI.h:594
The constant iterator class for sub vectors.
Definition: matpackI.h:420
const Numeric & reference
Definition: matpackI.h:425
void mult(VectorView y, const ConstMatrixView &M, const ConstVectorView &x)
Matrix-Vector Multiplication.
Definition: matpackI.cc:1123
A constant view of a ComplexVector.
Definition: complex.h:268
Iterator2D iterator
Definition: matpackI.h:1104
Numeric min(const ConstVectorView &x)
Min function, vector version.
Definition: matpackI.cc:1555
constexpr Range(Index start, Joker, Index stride=1)
Constructor with joker extent.
Definition: matpackI.h:190
Numeric vector_angle(ConstVectorView a, ConstVectorView b)
Definition: matpackI.cc:1412
bool operator!=(const ConstIterator1D &other) const
Not equal operator, needed for algorithms like copy.
Definition: matpackI.h:447
constexpr Rational end(Rational Ju, Rational Jl, Polarization type) noexcept
Gives the largest M for a polarization type of this transition.
Definition: zeemandata.h:108
Iterator1D iterator
Definition: matpackI.h:628
The iterator class for sub vectors.
Definition: matpackI.h:360
int poly_root_solve(Matrix &roots, Vector &coeffs)
Definition: poly_roots.cc:90
void ludcmp(Matrix &LU, ArrayOfIndex &indx, ConstMatrixView A)
LU decomposition.
Definition: lin_alg.cc:56
constexpr Complex operator-(Complex c, Numeric n)
Definition: complex.h:73
void copy(ConstIterator1D origin, const ConstIterator1D &end, Iterator1D target)
Definition: matpackI.cc:302
invlib::Matrix< ArtsMatrix > Matrix
invlib wrapper type for ARTS matrices.
Definition: oem.h:34
Numeric & operator()(Index r, Index c)
Plain index operator.
Definition: matpackI.h:1108
Range mrr
The row range of mdata that is actually used.
Definition: complex.h:715
Const version of Iterator3D.
Definition: matpackIII.h:76
MatrixView & operator+=(MatrixView &A, const Block &B)
ConstIterator1D const_iterator
Definition: matpackI.h:484
The row iterator class for sub matrices.
Definition: complex.h:478
The ComplexMatrixView class.
Definition: complex.h:731
Numeric * get_raw_data()
Definition: matpackI.h:1220
The Tensor5 class.
Definition: matpackV.h:506
ConstIterator1D(const Numeric *x, Index stride)
Explicit constructor.
Definition: matpackI.h:432
void proj(Vector &c, ConstVectorView a, ConstVectorView b)
Definition: matpackI.cc:1434
ConstIterator2D & operator++()
Prefix increment operator.
Definition: matpackI.h:822