ARTS 2.5.0 (git: 9ee3ac6c)
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#pragma GCC diagnostic push
99#pragma GCC diagnostic ignored "-Wshadow"
100#pragma GCC diagnostic ignored "-Wconversion"
101#pragma GCC diagnostic ignored "-Wfloat-conversion"
102#include <Eigen/Dense>
103#pragma GCC diagnostic pop
104
105#include "array.h"
106#include "matpack.h"
107
108// Declare existance of some classes
109class bofstream;
110
111// Declaration of Eigen types
112typedef Eigen::Stride<Eigen::Dynamic, Eigen::Dynamic> StrideType;
113typedef Eigen::Matrix<Numeric, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>
115typedef Eigen::Map<MatrixType, 0, StrideType> MatrixViewMap;
116typedef Eigen::Map<const MatrixType, 0, StrideType> ConstMatrixViewMap;
117typedef Eigen::Matrix<Numeric, 4, 4, Eigen::RowMajor> Matrix4x4Type;
118typedef Eigen::Map<Matrix4x4Type, 0, StrideType> Matrix4x4ViewMap;
119typedef Eigen::Map<const Matrix4x4Type, 0, StrideType> ConstMatrix4x4ViewMap;
120
131class Joker {
132 // Nothing here.
133};
134
135// Declare existence of the global joker object:
136extern const Joker joker;
137
138// Declare the existence of class ConstMatrixView:
139class ConstIterator1D;
140
141// Declare the existence of class VectorView:
142class VectorView;
143
144// Declare the existence of class ConstVectorView:
145class ConstVectorView;
146
147// Declare the existence of class ConstMatrixView:
148class ConstMatrixView;
149
165class Range {
166 public:
167
168 // Constructors:
169
180 constexpr Range(Index start, Index extent, Index stride = 1) ARTS_NOEXCEPT
181 : mstart(start), mextent(extent), mstride(stride) {
182 // Start must be >= 0:
183 ARTS_ASSERT(0 <= mstart);
184 // Extent also. Although internally negative extent means "to the end",
185 // this can not be created this way, only with the joker. Zero
186 // extent is allowed, though, which corresponds to an empty range.
187 ARTS_ASSERT(0 <= mextent);
188 // Stride can be anything except 0.
189 // SAB 2001-09-21: Allow 0 stride.
190 // ARTS_ASSERT( 0!=mstride);
191 }
192
195 constexpr Range(Index start, Joker, Index stride = 1) ARTS_NOEXCEPT
196 : mstart(start), mextent(-1), mstride(stride) {
197 // Start must be >= 0:
198 ARTS_ASSERT(0 <= mstart);
199 }
200
204 constexpr Range(Joker, Index stride = 1) noexcept : mstart(0), mextent(-1), mstride(stride) {
205 // Nothing to do here.
206 };
207
213 constexpr Range(Index max_size, const Range& r) ARTS_NOEXCEPT
214 : mstart(r.mstart), mextent(r.mextent), mstride(r.mstride) {
215 // Start must be >= 0:
216 ARTS_ASSERT(0 <= mstart);
217 // ... and < max_size:
218 ARTS_ASSERT(mstart < max_size);
219
220 // Stride must be != 0:
221 ARTS_ASSERT(0 != mstride);
222
223 // Convert negative extent (joker) to explicit extent
224 if (mextent < 0) {
225 if (0 < mstride)
226 mextent = 1 + (max_size - 1 - mstart) / mstride;
227 else
228 mextent = 1 + (0 - mstart) / mstride;
229 } else {
230 #ifndef NDEBUG
231 // Check that extent is ok:
232 Index fin = mstart + (mextent - 1) * mstride;
233 ARTS_ASSERT(0 <= fin);
234 ARTS_ASSERT(fin < max_size);
235 #endif
236 }
237 }
238
244 constexpr Range(const Range& p, const Range& n) ARTS_NOEXCEPT
245 : mstart(p.mstart + n.mstart * p.mstride),
246 mextent(n.mextent),
247 mstride(p.mstride * n.mstride) {
248 // We have to juggle here a bit with previous, new, and resulting
249 // quantities. I.e.;
250 // p.mstride: Previous stride
251 // n.mstride: New stride (as specified)
252 // mstride: Resulting stride (old*new)
253
254 // Get the previous final element:
255 Index prev_fin = p.mstart + (p.mextent - 1) * p.mstride;
256
257 // Resulting start must be >= previous start:
258 ARTS_ASSERT(p.mstart <= mstart);
259 // and <= prev_fin, except for Joker:
260 ARTS_ASSERT(mstart <= prev_fin || mextent == -1);
261
262 // Resulting stride must be != 0:
263 ARTS_ASSERT(0 != mstride, "Problem: mstride==", mstride, " for mstart==",mstart, " and mextent==", mextent);
264
265 // Convert negative extent (joker) to explicit extent
266 if (mextent < 0) {
267 if (0 < mstride)
268 mextent = 1 + (prev_fin - mstart) / mstride;
269 else
270 mextent = 1 + (p.mstart - mstart) / mstride;
271 } else {
272 #ifndef NDEBUG
273 // Check that extent is ok:
274 Index fin = mstart + (mextent - 1) * mstride;
275 ARTS_ASSERT(p.mstart <= fin);
276 ARTS_ASSERT(fin <= prev_fin);
277 #endif
278 }
279 };
280
281 // Friends:
282 friend class ConstVectorView;
283 friend class VectorView;
284 friend class Vector;
285 friend class ConstMatrixView;
286 friend class MatrixView;
287 friend class Matrix;
288 friend class Iterator2D;
289 friend class Iterator3D;
290 friend class Iterator4D;
291 friend class Iterator5D;
292 friend class Iterator6D;
293 friend class Iterator7D;
294 friend class ConstIterator2D;
295 friend class ConstIterator3D;
296 friend class ConstIterator4D;
297 friend class ConstIterator5D;
298 friend class ConstIterator6D;
299 friend class ConstIterator7D;
300 friend class ConstTensor3View;
301 friend class Tensor3View;
302 friend class Tensor3;
303 friend class ConstTensor4View;
304 friend class Tensor4View;
305 friend class Tensor4;
306 friend class ConstTensor5View;
307 friend class Tensor5View;
308 friend class Tensor5;
309 friend class ConstTensor6View;
310 friend class Tensor6View;
311 friend class Tensor6;
312 friend class ConstTensor7View;
313 friend class Tensor7View;
314 friend class Tensor7;
315 friend class Sparse;
317 friend class ComplexVectorView;
318 friend class ComplexVector;
320 friend class ComplexMatrixView;
321 friend class ComplexMatrix;
322 friend class ComplexIterator2D;
324
325 friend void mult_general(VectorView,
326 const ConstMatrixView&,
328
329 // Member functions:
330
332 constexpr Index get_start() const ARTS_NOEXCEPT { return mstart; }
334 constexpr Index get_extent() const ARTS_NOEXCEPT { return mextent; }
336 constexpr Index get_stride() const ARTS_NOEXCEPT { return mstride; }
337
339 constexpr Range operator()(const Range r) const ARTS_NOEXCEPT {
340 return (r.mextent < 0) ? (mextent < 0) ? Range(mstart + r.mstart * mstride,
341 joker,
342 r.mstride * mstride)
343 : Range(mstart + r.mstart * mstride,
344 mextent,
345 r.mstride * mstride)
346 : Range(mstart + r.mstart * mstride,
347 r.mextent,
348 r.mstride * mstride);
349 }
350
351 constexpr Index operator()(const Index i) const ARTS_NOEXCEPT { return mstart + i * mstride; };
352
353 private:
361};
362
366 public:
369 using pointer = Numeric*;
371 using iterator_category = std::random_access_iterator_tag;
372
374 Iterator1D() = default;
375
378 : mx(x), mstride(stride) { /* Nothing to do here. */
379 }
380
381 // Operators:
382
385 mx += mstride;
386 return *this;
387 }
388
390 Numeric& operator*() const ARTS_NOEXCEPT { return *mx; }
391
393 bool operator!=(const Iterator1D& other) const ARTS_NOEXCEPT {
394 if (mx != other.mx)
395 return true;
396 else
397 return false;
398 }
399
400 bool operator==(const Iterator1D& other) const ARTS_NOEXCEPT {
401 return !operator!=(other);
402 }
403
405 return (Index)(mx - other.mx) / mstride;
406 }
407
412 friend void copy(ConstIterator1D origin,
413 const ConstIterator1D& end,
414 Iterator1D target);
415
416 private:
418 Numeric* mx{nullptr};
421};
422
426 public:
428 using value_type = const Numeric;
429 using pointer = const Numeric*;
430 using reference = const Numeric&;
431 using iterator_category = std::random_access_iterator_tag;
432
434 ConstIterator1D() = default;
435
438 : mx(x), mstride(stride) { /* Nothing to do here. */
439 }
440
441 // Operators:
444 mx += mstride;
445 return *this;
446 }
447
449 const Numeric& operator*() const ARTS_NOEXCEPT { return *mx; }
450
452 bool operator!=(const ConstIterator1D& other) const ARTS_NOEXCEPT {
453 if (mx != other.mx)
454 return true;
455 else
456 return false;
457 }
458
459 bool operator==(const ConstIterator1D& other) const ARTS_NOEXCEPT {
460 return !operator!=(other);
461 }
462
464 return (Index)(mx - other.mx) / mstride;
465 }
466
467 friend void copy(ConstIterator1D origin,
468 const ConstIterator1D& end,
469 Iterator1D target);
470
471 private:
473 const Numeric* mx{nullptr};
476};
477
478// Declare the vector class:
479class Vector;
480
481// Declare the MatrixView class
482class MatrixView;
483
490 public:
491 constexpr ConstVectorView(const ConstVectorView&) = default;
492 constexpr ConstVectorView(ConstVectorView&&) = default;
495
496 // Typedef for compatibility with STL
498
499 // Member functions:
500
502 bool empty() const ARTS_NOEXCEPT;
503
513 Index nelem() const ARTS_NOEXCEPT;
514
516 Index size() const ARTS_NOEXCEPT;
517
519 Numeric sum() const ARTS_NOEXCEPT;
520
521 // Const index operators:
523 Numeric operator[](Index n) const ARTS_NOEXCEPT { // Check if index is valid:
524 ARTS_ASSERT(0 <= n);
526 return get(n);
527 }
528
531 return *(mdata + mrange.mstart + n * mrange.mstride);
532 }
533
538
540
541 // Functions returning iterators:
542
545
548
550 operator ConstMatrixView() const;
551
553 virtual ~ConstVectorView() = default;
554
555 // Friends:
556 friend class VectorView;
557 friend class ConstIterator2D;
558 friend class ConstMatrixView;
559 friend class ConstTensor3View;
560 friend class ConstTensor4View;
561 friend class ConstTensor5View;
562 friend class ConstTensor6View;
563 friend class ConstTensor7View;
565 friend int poly_root_solve(Matrix& roots, Vector& coeffs);
566 friend void mult(VectorView, const ConstMatrixView&, const ConstVectorView&);
567 friend void mult(VectorView, const Sparse&, ConstVectorView);
568 friend void transpose_mult(VectorView, const Sparse&, ConstVectorView);
569 friend void mult_general(VectorView,
570 const ConstMatrixView&,
572 friend void lubacksub(VectorView,
575 const ArrayOfIndex&);
577
582
586
587 protected:
588 // Constructors:
589 ConstVectorView() = default;
590
594
605 ConstVectorView(Numeric* data, const Range& p, const Range& n) ARTS_NOEXCEPT;
606
607 // Data members:
608 // -------------
612 Numeric* mdata{nullptr};
613};
614
627 public:
628 // Make const methods visible from base class
631 using ConstVectorView::operator[];
633
634 constexpr VectorView(const VectorView&) = default;
635
638 VectorView(const Vector&);
639
642
643 // Typedef for compatibility with STL
645
647 Numeric& operator[](Index n) ARTS_NOEXCEPT { // Check if index is valid:
648 ARTS_ASSERT(0 <= n);
650 return get(n);
651 }
652
655 return *(mdata + mrange.mstart + n * mrange.mstride);
656 }
657
662
663 // Iterators:
664
667
670
671 // Assignment operators:
672
677 VectorView& operator=(const ConstVectorView& v);
678
684 VectorView& operator=(const VectorView& v);
685
688 VectorView& operator=(const Vector& v);
689
690 VectorView& operator=(const Array<Numeric>& v);
691
694 VectorView& operator=(Numeric x);
695
696 // Other operators:
697
699 VectorView operator*=(Numeric x) ARTS_NOEXCEPT;
700
702 VectorView operator/=(Numeric x) ARTS_NOEXCEPT;
703
705 VectorView operator+=(Numeric x) ARTS_NOEXCEPT;
706
708 VectorView operator-=(Numeric x) ARTS_NOEXCEPT;
709
711 VectorView operator*=(const ConstVectorView& x) ARTS_NOEXCEPT;
712
714 VectorView operator/=(const ConstVectorView& x) ARTS_NOEXCEPT;
715
717 VectorView operator+=(const ConstVectorView& x) ARTS_NOEXCEPT;
718
720 VectorView operator-=(const ConstVectorView& x) ARTS_NOEXCEPT;
721
723 operator MatrixView() ARTS_NOEXCEPT;
724
730 const Numeric* get_c_array() const ARTS_NOEXCEPT;
731
738
740 virtual ~VectorView() = default;
741
742 // Friends:
743 friend class ConstIterator2D;
744 friend class Iterator2D;
745 friend class MatrixView;
746 friend class Tensor3View;
747 friend class Tensor4View;
748 friend class Tensor5View;
749 friend class Tensor6View;
750 friend class Tensor7View;
751 friend class ComplexVectorView;
752
756
757 protected:
758 // Constructors:
759 VectorView() = default;
760
763 VectorView(Numeric* data, const Range& range) ARTS_NOEXCEPT;
764
775 VectorView(Numeric* data, const Range& p, const Range& n) ARTS_NOEXCEPT;
776};
777
782 public:
783 // Constructors:
785 Iterator2D() = default;
786
789 : msv(x), mstride(stride) { /* Nothing to do here. */
790 }
791
792 // Operators:
795 msv.mdata += mstride;
796 return *this;
797 }
798
800 bool operator!=(const Iterator2D& other) const ARTS_NOEXCEPT {
801 if (msv.mdata + msv.mrange.mstart !=
802 other.msv.mdata + other.msv.mrange.mstart)
803 return true;
804 else
805 return false;
806 }
807
811
814
815 private:
819 Index mstride{0};
820};
821
826 public:
827 // Constructors:
829 ConstIterator2D() = default;
830
833 : msv(x), mstride(stride) { /* Nothing to do here. */
834 }
835
836 // Operators:
839 msv.mdata += mstride;
840 return *this;
841 }
842
844 bool operator!=(const ConstIterator2D& other) const ARTS_NOEXCEPT {
845 if (msv.mdata + msv.mrange.mstart !=
846 other.msv.mdata + other.msv.mrange.mstart)
847 return true;
848 else
849 return false;
850 }
851
854 const ConstVectorView* operator->() const ARTS_NOEXCEPT { return &msv; }
855
857 const ConstVectorView& operator*() const ARTS_NOEXCEPT { return msv; }
858
859 private:
863 Index mstride{0};
864};
865
876class Vector : public VectorView {
877 public:
878 // Constructors:
879 Vector() = default;
880
882 Vector(std::initializer_list<Numeric> init);
883
885 Vector(const Eigen::VectorXd& init);
886
888 explicit Vector(Index n);
889
891 Vector(Index n, Numeric fill);
892
900 Vector(Numeric start, Index extent, Numeric stride);
901
907 Vector(const ConstVectorView& v);
908
911 Vector(const Vector& v);
912 Vector(Vector&& v) noexcept : VectorView(std::forward<VectorView>(v)) {
913 v.mdata = nullptr;
914 }
915
917 Vector(const std::vector<Numeric>&);
918
928 : VectorView(d, r0) {
929 ARTS_ASSERT(r0.get_extent() >= 0, "Must have size. Has: ", r0.get_extent());
930 }
931
932 // Assignment operators:
933
958 Vector& operator=(const Vector& v);
959
961 Vector& operator=(Vector&& v) noexcept;
962
964 Vector& operator=(std::initializer_list<Numeric> v);
965
983
987
991 void resize(Index n);
992
994 friend void swap(Vector& v1, Vector& v2);
995
998 virtual ~Vector();
999};
1000
1001// Declare class Matrix:
1002class Matrix;
1003
1015 public:
1016 constexpr ConstMatrixView(const ConstMatrixView&) = default;
1017 constexpr ConstMatrixView(ConstMatrixView&&) = default;
1020
1021 // Typedef for compatibility with STL
1023
1024 // Member functions:
1025 bool empty() const ARTS_NOEXCEPT;
1026 Index nrows() const ARTS_NOEXCEPT;
1027 Index ncols() const ARTS_NOEXCEPT;
1028
1029 // Const index operators:
1031 Numeric operator()(Index r, Index c) const ARTS_NOEXCEPT { // Check if indices are valid:
1032 ARTS_ASSERT(0 <= r);
1033 ARTS_ASSERT(0 <= c);
1034 ARTS_ASSERT(r < mrr.mextent);
1035 ARTS_ASSERT(c < mcr.mextent);
1036
1037 return get(r, c);
1038 }
1039
1042 return *(mdata + mrr.mstart + r * mrr.mstride + mcr.mstart +
1043 c * mcr.mstride);
1044 }
1045
1046 ConstMatrixView operator()(const Range& r, const Range& c) const ARTS_NOEXCEPT;
1047 ConstVectorView operator()(const Range& r, Index c) const ARTS_NOEXCEPT;
1048 ConstVectorView operator()(Index r, const Range& c) const ARTS_NOEXCEPT;
1049
1050 // Functions returning iterators:
1053
1054 // View on diagonal vector
1055 ConstVectorView diagonal() const ARTS_NOEXCEPT;
1056
1058 virtual ~ConstMatrixView() = default;
1059
1060 // Friends:
1061 friend class MatrixView;
1062 friend class ConstIterator3D;
1063 friend class ConstVectorView;
1064 friend class ConstTensor3View;
1065 friend class ConstTensor4View;
1066 friend class ConstTensor5View;
1067 friend class ConstTensor6View;
1068 friend class ConstTensor7View;
1071 friend int poly_root_solve(Matrix& roots, Vector& coeffs);
1072 friend void mult(VectorView, const ConstMatrixView&, const ConstVectorView&);
1073 friend void mult(MatrixView, const ConstMatrixView&, const ConstMatrixView&);
1074 friend void mult(MatrixView, const Sparse&, const ConstMatrixView&);
1075 friend void mult(MatrixView, const ConstMatrixView&, const Sparse&);
1076 friend void mult_general(VectorView,
1077 const ConstMatrixView&,
1079 friend void mult_general(MatrixView,
1080 const ConstMatrixView&,
1082 friend void ludcmp(Matrix&, ArrayOfIndex&, ConstMatrixView);
1083 friend void lubacksub(VectorView,
1086 const ArrayOfIndex&);
1087 friend void inv(MatrixView, ConstMatrixView);
1089
1092
1095
1096 protected:
1097 // Constructors:
1098 ConstMatrixView() = default;
1101 const Range& pr,
1102 const Range& pc,
1103 const Range& nr,
1104 const Range& nc) ARTS_NOEXCEPT;
1105
1106 // Data members:
1107 // -------------
1109 Range mrr{0, 0, 1};
1111 Range mcr{0, 0, 1};
1113 Numeric* mdata{nullptr};
1114};
1115
1126 public:
1127 // Make const methods visible from base class
1130 using ConstMatrixView::operator();
1132
1133 constexpr MatrixView(const MatrixView&) = default;
1134
1135 // Typedef for compatibility with STL
1137
1138 // Index Operators:
1140 Numeric& operator()(Index r, Index c) ARTS_NOEXCEPT { // Check if indices are valid:
1141 ARTS_ASSERT(0 <= r);
1142 ARTS_ASSERT(0 <= c);
1143 ARTS_ASSERT(r < mrr.mextent);
1144 ARTS_ASSERT(c < mcr.mextent);
1145
1146 return get(r, c);
1147 }
1148
1151 return *(mdata + mrr.mstart + r * mrr.mstride + mcr.mstart +
1152 c * mcr.mstride);
1153 }
1154
1155 MatrixView operator()(const Range& r, const Range& c) ARTS_NOEXCEPT;
1156 VectorView operator()(const Range& r, Index c) ARTS_NOEXCEPT;
1157 VectorView operator()(Index r, const Range& c) ARTS_NOEXCEPT;
1158
1159 // Functions returning iterators:
1162
1163 // Assignment operators:
1164 MatrixView& operator=(const ConstMatrixView& m);
1165 MatrixView& operator=(const MatrixView& m);
1166 MatrixView& operator=(const Matrix& m);
1167 MatrixView& operator=(const ConstVectorView& m);
1168 MatrixView& operator=(Numeric x);
1169
1170 // Other operators:
1171 MatrixView& operator*=(Numeric x) ARTS_NOEXCEPT;
1172 MatrixView& operator/=(Numeric x) ARTS_NOEXCEPT;
1173 MatrixView& operator+=(Numeric x) ARTS_NOEXCEPT;
1174 MatrixView& operator-=(Numeric x) ARTS_NOEXCEPT;
1175
1176 MatrixView& operator*=(const ConstMatrixView& x) ARTS_NOEXCEPT;
1177 MatrixView& operator/=(const ConstMatrixView& x) ARTS_NOEXCEPT;
1178 MatrixView& operator+=(const ConstMatrixView& x) ARTS_NOEXCEPT;
1179 MatrixView& operator-=(const ConstMatrixView& x) ARTS_NOEXCEPT;
1180
1181 MatrixView& operator*=(const ConstVectorView& x) ARTS_NOEXCEPT;
1182 MatrixView& operator/=(const ConstVectorView& x) ARTS_NOEXCEPT;
1183 MatrixView& operator+=(const ConstVectorView& x) ARTS_NOEXCEPT;
1184 MatrixView& operator-=(const ConstVectorView& x) ARTS_NOEXCEPT;
1185
1186 // Conversion to a plain C-array
1187 const Numeric* get_c_array() const ARTS_NOEXCEPT;
1189
1191 virtual ~MatrixView() = default;
1192
1193 // Friends:
1194 friend class VectorView;
1195 friend class Iterator3D;
1196 friend class Tensor3View;
1197 friend class Tensor4View;
1198 friend class Tensor5View;
1199 friend class Tensor6View;
1200 friend class Tensor7View;
1201 friend class ComplexMatrixView;
1204 friend void mult(MatrixView, const ConstMatrixView&, const ConstMatrixView&);
1205
1206 protected:
1207 // Constructors:
1208 MatrixView() = default;
1209 MatrixView(Numeric* data, const Range& rr, const Range& cr) ARTS_NOEXCEPT;
1211 const Range& pr,
1212 const Range& pc,
1213 const Range& nr,
1214 const Range& nc) ARTS_NOEXCEPT;
1215};
1216
1225class Matrix : public MatrixView {
1226 public:
1227 // Constructors:
1228 Matrix() = default;
1229 Matrix(Index r, Index c);
1230 Matrix(Index r, Index c, Numeric fill);
1231 Matrix(const ConstMatrixView& m);
1232 Matrix(const Matrix& m);
1233 Matrix(Matrix&& v) noexcept : MatrixView(std::forward<MatrixView>(v)) {
1234 v.mdata = nullptr;
1235 }
1236
1247 : MatrixView(d, r0, r1) {
1248 ARTS_ASSERT(r0.get_extent() >= 0, "Must have size. Has: ", r0.get_extent());
1249 ARTS_ASSERT(r1.get_extent() >= 0, "Must have size. Has: ", r1.get_extent());
1250 }
1251
1252 // Assignment operators:
1253 Matrix& operator=(const Matrix& m);
1254 Matrix& operator=(Matrix&& m) noexcept;
1257
1258 // Resize function:
1259 void resize(Index r, Index c);
1260
1261 // Swap function:
1262 friend void swap(Matrix& m1, Matrix& m2);
1263
1264 // Destructor:
1265 virtual ~Matrix();
1266
1267 // Total size
1268 Index size() const noexcept {return nrows() * ncols();}
1269
1271 template <std::size_t dim0>
1273 static_assert(dim0 < 2, "Bad Dimension, Out-of-Bounds");
1274
1275 Range r0(0, dim0 == 0 ? nrows() : ncols());
1276
1277 Vector out(mdata, r0);
1278 ARTS_ASSERT(size() == out.size(), "Can only reduce size on same size input. "
1279 "The sizes are (input v. output): ", size(), " v. ", out.size());
1280 mdata = nullptr;
1281 return out;
1282 }
1283
1285};
1286
1287// Function declarations:
1288// ----------------------
1289
1290void copy(ConstIterator1D origin,
1291 const ConstIterator1D& end,
1292 Iterator1D target);
1293
1295void copy(Numeric x, Iterator1D target, const Iterator1D& end) ARTS_NOEXCEPT;
1296
1297void copy(ConstIterator2D origin,
1298 const ConstIterator2D& end,
1299 Iterator2D target);
1300
1301void copy(Numeric x, Iterator2D target, const Iterator2D& end) ARTS_NOEXCEPT;
1302
1303void mult(VectorView y, const ConstMatrixView& M, const ConstVectorView& x);
1304
1306 const ConstMatrixView& B,
1308
1309void mult(MatrixView A, const ConstMatrixView& B, const ConstMatrixView& C);
1310
1312 const ConstMatrixView& B,
1314
1316
1318
1320
1322
1324
1325void transform(VectorView y, double (&my_func)(double), ConstVectorView x);
1326
1327void transform(MatrixView y, double (&my_func)(double), ConstMatrixView x);
1328
1330
1332
1334
1336
1338
1340
1342
1344
1345std::ostream& operator<<(std::ostream& os, const ConstVectorView& v);
1346
1347std::ostream& operator<<(std::ostream& os, const ConstMatrixView& v);
1348
1349std::ostream& operator<<(std::ostream& os, const Range& r);
1350
1351// Converts constant matrix to constant eigen map
1353// Converts constant vector to constant eigen row-view
1355// Converts constant vector to constant eigen row-view
1357// Converts constant vector to constant eigen row-view
1359// Converts constant vector to constant eigen column-view
1361// Converts matrix to eigen map
1363// Converts vector to eigen map row-view
1365// Converts vector to eigen map row-view
1367// Converts vector to eigen map row-view
1369// Converts vector to eigen map column-view
1371
1373// Helper function for debugging
1374#ifndef NDEBUG
1375
1377
1378#endif
1380
1381#endif // matpackI_h
This file contains the definition of Array.
Index nrows
void * data
Index ncols
The row iterator class for sub matrices.
The ComplexMatrixView class.
The ComplexMatrix class.
The ComplexVectorView class.
The ComplexVector class.
The const row iterator class for sub matrices.
A constant view of a ComplexMatrix.
A constant view of a ComplexVector.
The constant iterator class for sub vectors.
Definition: matpackI.h:425
bool operator!=(const ConstIterator1D &other) const ARTS_NOEXCEPT
Not equal operator, needed for algorithms like copy.
Definition: matpackI.h:452
const Numeric * pointer
Definition: matpackI.h:429
std::random_access_iterator_tag iterator_category
Definition: matpackI.h:431
const Numeric * mx
Current position.
Definition: matpackI.h:473
Index mstride
Stride.
Definition: matpackI.h:475
ConstIterator1D()=default
Default constructor.
const Numeric value_type
Definition: matpackI.h:428
const Numeric & reference
Definition: matpackI.h:430
bool operator==(const ConstIterator1D &other) const ARTS_NOEXCEPT
Definition: matpackI.h:459
ConstIterator1D & operator++() ARTS_NOEXCEPT
Prefix increment operator.
Definition: matpackI.h:443
Index difference_type
Definition: matpackI.h:427
ConstIterator1D(const Numeric *x, Index stride) ARTS_NOEXCEPT
Explicit constructor.
Definition: matpackI.h:437
const Numeric & operator*() const ARTS_NOEXCEPT
Dereferencing.
Definition: matpackI.h:449
Index operator-(const ConstIterator1D &other) const ARTS_NOEXCEPT
Definition: matpackI.h:463
friend void copy(ConstIterator1D origin, const ConstIterator1D &end, Iterator1D target)
Definition: matpackI.cc:299
The const row iterator class for sub matrices.
Definition: matpackI.h:825
const ConstVectorView & operator*() const ARTS_NOEXCEPT
Dereferencing.
Definition: matpackI.h:857
ConstVectorView msv
Current position.
Definition: matpackI.h:861
ConstIterator2D()=default
Default constructor.
const ConstVectorView * operator->() const ARTS_NOEXCEPT
The -> operator is needed, so that we can write i->begin() to get the 1D iterators.
Definition: matpackI.h:854
bool operator!=(const ConstIterator2D &other) const ARTS_NOEXCEPT
Not equal operator, needed for algorithms like copy.
Definition: matpackI.h:844
ConstIterator2D(const ConstVectorView &x, Index stride) ARTS_NOEXCEPT
Explicit constructor.
Definition: matpackI.h:832
ConstIterator2D & operator++() ARTS_NOEXCEPT
Prefix increment operator.
Definition: matpackI.h:838
Const version of Iterator3D.
Definition: matpackIII.h:76
Const version of Iterator4D.
Definition: matpackIV.h:77
Const version of Iterator5D.
Definition: matpackV.h:85
Const version of Iterator6D.
Definition: matpackVI.h:87
Const version of Iterator7D.
Definition: matpackVII.h:84
A constant view of a Matrix.
Definition: matpackI.h:1014
constexpr ConstMatrixView(ConstMatrixView &&)=default
ConstMatrixView & operator=(const ConstMatrixView &)=default
ConstIterator2D begin() const ARTS_NOEXCEPT
Return const iterator to first row.
Definition: matpackI.cc:473
constexpr ConstMatrixView(const ConstMatrixView &)=default
ConstIterator2D const_iterator
Definition: matpackI.h:1022
ConstIterator2D end() const ARTS_NOEXCEPT
Return const iterator behind last row.
Definition: matpackI.cc:478
ConstMatrixView & operator=(ConstMatrixView &&)=default
Numeric get(Index r, Index c) const ARTS_NOEXCEPT
Get element implementation without assertions.
Definition: matpackI.h:1041
A constant view of a Tensor3.
Definition: matpackIII.h:132
A constant view of a Tensor4.
Definition: matpackIV.h:133
A constant view of a Tensor5.
Definition: matpackV.h:143
A constant view of a Tensor6.
Definition: matpackVI.h:149
A constant view of a Tensor7.
Definition: matpackVII.h:147
A constant view of a Vector.
Definition: matpackI.h:489
Numeric get(Index n) const ARTS_NOEXCEPT
Get element implementation without assertions.
Definition: matpackI.h:530
ConstIterator1D end() const ARTS_NOEXCEPT
Return const iterator behind last element.
Definition: matpackI.cc:70
bool empty() const ARTS_NOEXCEPT
Returns true if variable size is zero.
Definition: matpackI.cc:46
ConstIterator1D begin() const ARTS_NOEXCEPT
Return const iterator to first element.
Definition: matpackI.cc:66
friend void lubacksub(VectorView, ConstMatrixView, ConstVectorView, const ArrayOfIndex &)
LU backsubstitution.
Definition: lin_alg.cc:91
Numeric * mdata
Pointer to the plain C array that holds the data.
Definition: matpackI.h:612
ConstIterator1D const_iterator
Definition: matpackI.h:497
friend int poly_root_solve(Matrix &roots, Vector &coeffs)
Definition: poly_roots.cc:90
friend void mult_general(VectorView, const ConstMatrixView &, const ConstVectorView &) ARTS_NOEXCEPT
Matrix Vector multiplication.
Definition: matpackI.cc:1181
Numeric sum() const ARTS_NOEXCEPT
The sum of all elements of a Vector.
Definition: matpackI.cc:52
Numeric operator[](Index n) const ARTS_NOEXCEPT
Plain const index operator.
Definition: matpackI.h:523
constexpr ConstVectorView(ConstVectorView &&)=default
constexpr ConstVectorView(const ConstVectorView &)=default
friend void mult(VectorView, const ConstMatrixView &, const ConstVectorView &)
Matrix-Vector Multiplication.
Definition: matpackI.cc:1123
friend ConstMatrixViewMap MapToEigen(const ConstVectorView &)
Definition: matpackI.cc:1677
Index size() const ARTS_NOEXCEPT
Definition: matpackI.cc:50
Range mrange
The range of mdata that is actually used.
Definition: matpackI.h:610
friend void transpose_mult(VectorView, const Sparse &, ConstVectorView)
Sparse matrix - Vector multiplication.
Definition: matpackII.cc:452
friend void diagonalize(MatrixView, VectorView, VectorView, ConstMatrixView)
Matrix Diagonalization.
Definition: lin_alg.cc:241
ConstVectorView & operator=(const ConstVectorView &)=default
friend ConstMatrixViewMap MapToEigenCol(const ConstVectorView &)
Definition: matpackI.cc:1690
Index nelem() const ARTS_NOEXCEPT
Returns the number of elements.
Definition: matpackI.cc:48
ConstVectorView & operator=(ConstVectorView &&)=default
friend Numeric operator*(const ConstVectorView &a, const ConstVectorView &b) ARTS_NOEXCEPT
Scalar product.
Definition: matpackI.cc:1092
The iterator class for sub vectors.
Definition: matpackI.h:365
Iterator1D & operator++() ARTS_NOEXCEPT
Prefix increment operator.
Definition: matpackI.h:384
bool operator==(const Iterator1D &other) const ARTS_NOEXCEPT
Definition: matpackI.h:400
Index operator-(const Iterator1D &other) const ARTS_NOEXCEPT
Definition: matpackI.h:404
Iterator1D()=default
Default constructor.
Index difference_type
Definition: matpackI.h:367
Numeric & operator*() const ARTS_NOEXCEPT
Dereferencing.
Definition: matpackI.h:390
Index mstride
Stride.
Definition: matpackI.h:420
std::random_access_iterator_tag iterator_category
Definition: matpackI.h:371
Numeric * mx
Current position.
Definition: matpackI.h:418
friend void copy(ConstIterator1D origin, const ConstIterator1D &end, Iterator1D target)
Copy data between begin and end to target.
Definition: matpackI.cc:299
Numeric * pointer
Definition: matpackI.h:369
bool operator!=(const Iterator1D &other) const ARTS_NOEXCEPT
Not equal operator, needed for algorithms like copy.
Definition: matpackI.h:393
Numeric & reference
Definition: matpackI.h:370
Numeric value_type
Definition: matpackI.h:368
Iterator1D(Numeric *x, Index stride) ARTS_NOEXCEPT
Explicit constructor.
Definition: matpackI.h:377
The row iterator class for sub matrices.
Definition: matpackI.h:781
Iterator2D(const VectorView &x, Index stride) ARTS_NOEXCEPT
Explicit constructor.
Definition: matpackI.h:788
VectorView & operator*() ARTS_NOEXCEPT
Dereferencing.
Definition: matpackI.h:813
bool operator!=(const Iterator2D &other) const ARTS_NOEXCEPT
Not equal operator, needed for algorithms like copy.
Definition: matpackI.h:800
Iterator2D()=default
Default constructor.
VectorView msv
Current position.
Definition: matpackI.h:817
Iterator2D & operator++() ARTS_NOEXCEPT
Prefix increment operator.
Definition: matpackI.h:794
VectorView * operator->() ARTS_NOEXCEPT
The -> operator is needed, so that we can write i->begin() to get the 1D iterators.
Definition: matpackI.h:810
Implementation of Tensors of Rank 3.
Definition: matpackIII.h:34
Implementation of Tensors of Rank 4.
Definition: matpackIV.h:38
Implementation of Tensors of Rank 5.
Definition: matpackV.h:38
The outermost iterator class for rank 6 tensors.
Definition: matpackVI.h:40
Implementation of Tensors of Rank 7.
Definition: matpackVII.h:36
The Joker class.
Definition: matpackI.h:131
The MatrixView class.
Definition: matpackI.h:1125
Numeric & operator()(Index r, Index c) ARTS_NOEXCEPT
Plain index operator.
Definition: matpackI.h:1140
Numeric & get(Index r, Index c) ARTS_NOEXCEPT
Get element implementation without assertions.
Definition: matpackI.h:1150
constexpr MatrixView(const MatrixView &)=default
Iterator2D iterator
Definition: matpackI.h:1136
The Matrix class.
Definition: matpackI.h:1225
Matrix(Matrix &&v) noexcept
Definition: matpackI.h:1233
Matrix()=default
Vector reduce_rank() &&ARTS_NOEXCEPT
Definition: matpackI.h:1272
Index size() const noexcept
Definition: matpackI.h:1268
Numeric * get_raw_data() ARTS_NOEXCEPT
Definition: matpackI.h:1284
Matrix(Numeric *d, const Range &r0, const Range &r1) ARTS_NOEXCEPT
Definition: matpackI.h:1246
The range class.
Definition: matpackI.h:165
constexpr Range(Index start, Joker, Index stride=1) ARTS_NOEXCEPT
Constructor with joker extent.
Definition: matpackI.h:195
friend void mult_general(VectorView, const ConstMatrixView &, const ConstVectorView &) ARTS_NOEXCEPT
Matrix Vector multiplication.
Definition: matpackI.cc:1181
constexpr Index operator()(const Index i) const ARTS_NOEXCEPT
Definition: matpackI.h:351
constexpr Index get_stride() const ARTS_NOEXCEPT
Returns the stride of the range.
Definition: matpackI.h:336
constexpr Range(const Range &p, const Range &n) ARTS_NOEXCEPT
Constructor of a new range relative to an old range.
Definition: matpackI.h:244
constexpr Range(Index start, Index extent, Index stride=1) ARTS_NOEXCEPT
Explicit constructor.
Definition: matpackI.h:180
Index mstart
The start index.
Definition: matpackI.h:351
constexpr Index get_start() const ARTS_NOEXCEPT
Returns the start index of the range.
Definition: matpackI.h:332
constexpr Range operator()(const Range r) const ARTS_NOEXCEPT
Range of range.
Definition: matpackI.h:339
Index mstride
The stride.
Definition: matpackI.h:360
constexpr Index get_extent() const ARTS_NOEXCEPT
Returns the extent of the range.
Definition: matpackI.h:334
Index mextent
The number of elements.
Definition: matpackI.h:358
constexpr Range(Index max_size, const Range &r) ARTS_NOEXCEPT
Constructor which converts a range with joker to an explicit range.
Definition: matpackI.h:213
constexpr Range(Joker, Index stride=1) noexcept
Constructor with just a joker.
Definition: matpackI.h:204
The Sparse class.
Definition: matpackII.h:67
The Tensor3View class.
Definition: matpackIII.h:239
The Tensor3 class.
Definition: matpackIII.h:339
The Tensor4View class.
Definition: matpackIV.h:284
The Tensor4 class.
Definition: matpackIV.h:421
The Tensor5View class.
Definition: matpackV.h:333
The Tensor5 class.
Definition: matpackV.h:506
The Tensor6View class.
Definition: matpackVI.h:621
The Tensor6 class.
Definition: matpackVI.h:1088
The Tensor7View class.
Definition: matpackVII.h:1286
The Tensor7 class.
Definition: matpackVII.h:2382
The VectorView class.
Definition: matpackI.h:626
Numeric & get(Index n) ARTS_NOEXCEPT
Get element implementation without assertions.
Definition: matpackI.h:654
VectorView()=default
friend class MatrixView
Definition: matpackI.h:745
constexpr VectorView(const VectorView &)=default
VectorView & operator=(const ConstVectorView &v)
Assignment operator.
Definition: matpackI.cc:152
const Numeric * get_c_array() const ARTS_NOEXCEPT
Conversion to plain C-array, const-version.
Definition: matpackI.cc:271
Numeric & operator[](Index n) ARTS_NOEXCEPT
Plain Index operator.
Definition: matpackI.h:647
Iterator1D iterator
Definition: matpackI.h:644
Iterator1D begin() ARTS_NOEXCEPT
Return iterator to first element.
Definition: matpackI.cc:143
Iterator1D end() ARTS_NOEXCEPT
Return iterator behind last element.
Definition: matpackI.cc:147
The Vector class.
Definition: matpackI.h:876
Vector(Numeric *d, const Range &r0) ARTS_NOEXCEPT
Definition: matpackI.h:927
Vector(Vector &&v) noexcept
Definition: matpackI.h:912
Vector()=default
Binary output file stream class.
Definition: bofstream.h:42
#define ARTS_NOEXCEPT
Definition: debug.h:80
#define ARTS_ASSERT(condition,...)
Definition: debug.h:83
void ludcmp(Matrix &LU, ArrayOfIndex &indx, ConstMatrixView A)
LU decomposition.
Definition: lin_alg.cc:56
void inv(MatrixView Ainv, ConstMatrixView A)
Matrix Inverse.
Definition: lin_alg.cc:167
Numeric mean(const ConstVectorView &x) ARTS_NOEXCEPT
Mean function, vector version.
Definition: matpackI.cc:1585
ConstMatrixViewMap MapToEigenRow(const ConstVectorView &A)
Definition: matpackI.cc:1685
Eigen::Map< MatrixType, 0, StrideType > MatrixViewMap
Definition: matpackI.h:115
Numeric vector_angle(ConstVectorView a, ConstVectorView b)
Definition: matpackI.cc:1412
Numeric max(const ConstVectorView &x) ARTS_NOEXCEPT
Max function, vector version.
Definition: matpackI.cc:1517
ConstMatrix4x4ViewMap MapToEigen4x4(const ConstMatrixView &A)
Definition: matpackI.cc:1737
Numeric nanmean(const ConstVectorView &x) ARTS_NOEXCEPT
Mean function, vector version ignoring nans and infs.
Definition: matpackI.cc:1600
void proj(Vector &c, ConstVectorView a, ConstVectorView b) ARTS_NOEXCEPT
Definition: matpackI.cc:1434
const Joker joker
Eigen::Map< const Matrix4x4Type, 0, StrideType > ConstMatrix4x4ViewMap
Definition: matpackI.h:119
std::ostream & operator<<(std::ostream &os, const ConstVectorView &v)
Definition: matpackI.cc:106
Eigen::Map< const MatrixType, 0, StrideType > ConstMatrixViewMap
Definition: matpackI.h:116
Eigen::Map< Matrix4x4Type, 0, StrideType > Matrix4x4ViewMap
Definition: matpackI.h:118
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:1472
void cross3(VectorView c, const ConstVectorView &a, const ConstVectorView &b) ARTS_NOEXCEPT
cross3
Definition: matpackI.cc:1393
Numeric min(const ConstVectorView &x) ARTS_NOEXCEPT
Min function, vector version.
Definition: matpackI.cc:1551
void copy(ConstIterator1D origin, const ConstIterator1D &end, Iterator1D target)
Definition: matpackI.cc:299
Eigen::Stride< Eigen::Dynamic, Eigen::Dynamic > StrideType
Definition: matpackI.h:109
Eigen::Matrix< Numeric, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > MatrixType
Definition: matpackI.h:114
Numeric debug_matrixview_get_elem(MatrixView &mv, Index r, Index c)
Helper function to access matrix elements.
Definition: matpackI.cc:1762
ConstMatrixView transpose(ConstMatrixView m) ARTS_NOEXCEPT
Const version of transpose.
Definition: matpackI.cc:1444
Eigen::Matrix< Numeric, 4, 4, Eigen::RowMajor > Matrix4x4Type
Definition: matpackI.h:117
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:33
void swap(ComplexVector &v1, ComplexVector &v2)
Swaps two objects.
Workspace & init(Workspace &ws)
constexpr Numeric r0
The reference radius in IGRF13.
Definition: igrf13.cc:203
constexpr Rational start(Rational Ju, Rational Jl, Polarization type) noexcept
Gives the lowest M for a polarization type of this transition.
Definition: zeemandata.h:78
constexpr Rational end(Rational Ju, Rational Jl, Polarization type) noexcept
Gives the largest M for a polarization type of this transition.
Definition: zeemandata.h:109
invlib::Matrix< ArtsMatrix > Matrix
invlib wrapper type for ARTS matrices.
Definition: oem.h:33
invlib::Vector< ArtsVector > Vector
invlib wrapper type for ARTS vectors.
Definition: oem.h:31
#define d
#define v
#define a
#define c
#define b
#define M
Definition: rng.cc:165