ARTS 2.5.10 (git: 2f1c442c)
matpack_complex.h
Go to the documentation of this file.
1/* Copyright (C) 2002-2012 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
26#ifndef matpack_complex_h
27#define matpack_complex_h
28
29#include "lapack.h"
30#include "matpackI.h"
31#include "matpack_concepts.h"
32#include "nonstd.h"
33#include <complex>
34#include <utility>
35
36using Complex = std::complex<Numeric>;
38
40inline Numeric& real_val(Complex& c) noexcept {return reinterpret_cast<ComplexLayout(&)>(c).real;}
41
43inline Numeric& imag_val(Complex& c) noexcept {return reinterpret_cast<ComplexLayout(&)>(c).imag;}
44
46inline const Numeric& real_val(const Complex& c) noexcept {return reinterpret_cast<const ComplexLayout(&)>(c).real;}
47
49inline const Numeric& imag_val(const Complex& c) noexcept {return reinterpret_cast<const ComplexLayout(&)>(c).imag;}
50
51inline std::complex<float> operator+(const double& d,
52 const std::complex<float>& c) {
53 return (float(d) + c);
54}
55inline std::complex<float> operator*(const double& d,
56 const std::complex<float>& c) {
57 return (float(d) * c);
58}
59
60inline std::complex<float> operator+(const std::complex<float>& c,
61 const double& d) {
62 return (c + float(d));
63}
64inline std::complex<float> operator*(const std::complex<float>& c,
65 const double& d) {
66 return (c * float(d));
67}
68
69// Constexpr versions of common Complex operations
70
71// Helpers to keep equations readable
72#define a1 c.real()
73#define b1 c.imag()
74#define a2 z.real()
75#define b2 z.imag()
76
78constexpr Numeric abs2(Complex c) noexcept { return a1 * a1 + b1 * b1; }
79
81constexpr Complex conj(Complex c) noexcept { return {a1, -b1}; }
82
84constexpr Numeric real(Complex c) noexcept { return a1; }
85
87constexpr Numeric imag(Complex c) noexcept { return b1; }
88
89// Basic constexpr operations for Complex that don't exist in the standard yet (C++11)
90// NOTE: Remove these if there is ever an overload warning updating the C++ compiler version
91
92constexpr Complex operator+(Complex c, Numeric n) noexcept {
93 return {a1 + n, b1};
94}
95constexpr Complex operator-(Complex c, Numeric n) noexcept {
96 return {a1 - n, b1};
97}
98constexpr Complex operator*(Complex c, Numeric n) noexcept {
99 return {a1 * n, b1 * n};
100}
101constexpr Complex operator/(Complex c, Numeric n) noexcept {
102 return {a1 / n, b1 / n};
103}
104
105constexpr Complex operator+(Numeric n, Complex c) noexcept {
106 return {n + a1, b1};
107}
108constexpr Complex operator-(Numeric n, Complex c) noexcept {
109 return {n - a1, -b1};
110}
111constexpr Complex operator*(Numeric n, Complex c) noexcept {
112 return {n * a1, n * b1};
113}
114constexpr Complex operator/(Numeric n, Complex c) noexcept {
115 return Complex(n * a1, -n * b1) / abs2(c);
116}
117
118constexpr Complex operator+(Complex c, Complex z) noexcept {
119 return {a1 + a2, b1 + b2};
120}
121constexpr Complex operator-(Complex c, Complex z) noexcept {
122 return {a1 - a2, b1 - b2};
123}
124constexpr Complex operator*(Complex c, Complex z) noexcept {
125 return {a1 * a2 - b1 * b2, a1 * b2 + b1 * a2};
126}
127constexpr Complex operator/(Complex c, Complex z) noexcept {
128 return Complex(a1 * a2 + b1 * b2, -a1 * b2 + b1 * a2) / abs2(z);
129}
130constexpr Complex operator-(Complex c) noexcept { return {-a1, -b1}; }
131
132// Remove helpers to keep global namespace usable
133#undef a1
134#undef b1
135#undef a2
136#undef b2
137
138// Basic constexpr operations for different types since C++11 std::complex is lacking conversions
139// FIXME: Cannot be template because Eigen interferes, so explicit copies are required for operations
140// NOTE: Remove these if there is ever an overload warning updating the C++ compiler version
141#define _complex_operations_(T) \
142 constexpr Complex operator+(Complex c, T x) noexcept { \
143 return operator+(c, static_cast<Numeric>(x)); \
144 } \
145 constexpr Complex operator-(Complex c, T x) noexcept { \
146 return operator-(c, static_cast<Numeric>(x)); \
147 } \
148 constexpr Complex operator*(Complex c, T x) noexcept { \
149 return operator*(c, static_cast<Numeric>(x)); \
150 } \
151 constexpr Complex operator/(Complex c, T x) noexcept { \
152 return operator/(c, static_cast<Numeric>(x)); \
153 } \
154 \
155 constexpr Complex operator+(T x, Complex c) noexcept { \
156 return operator+(static_cast<Numeric>(x), c); \
157 } \
158 constexpr Complex operator-(T x, Complex c) noexcept { \
159 return operator-(static_cast<Numeric>(x), c); \
160 } \
161 constexpr Complex operator*(T x, Complex c) noexcept { \
162 return operator*(static_cast<Numeric>(x), c); \
163 } \
164 constexpr Complex operator/(T x, Complex c) noexcept { \
165 return operator/(static_cast<Numeric>(x), c); \
166 }
167
171
172#undef _complex_operations_
173
174constexpr bool isnan(Complex c) noexcept {
175 return nonstd::isnan(c.real()) or nonstd::isnan(c.imag());
176}
177
178 // Declare existence of the global joker object:
179 extern const Joker joker;
180
181// Declare the existence of class ConstComplexMatrixView:
183
184// Declare the existence of class ComplexVectorView:
186
187// Declare the existence of class ConstComplexVectorView:
189
190// Declare the existence of class ConstMatrixView:
192
196 public:
198 ComplexIterator1D() = default;
199
202 : mx(x), mstride(stride) { /* Nothing to do here. */
203 }
204
205 // Operators:
206
209 mx += mstride;
210 return *this;
211 }
212
214 Complex& operator*() const { return *mx; }
215
217 bool operator!=(const ComplexIterator1D& other) const {
218 if (mx != other.mx)
219 return true;
220 return false;
221 }
222
223 friend void copy(ConstComplexIterator1D origin,
224 const ConstComplexIterator1D& end,
225 ComplexIterator1D target);
226
227 private:
229 Complex* mx{nullptr};
232};
233
237 public:
240
243 : mx(x), mstride(stride) { /* Nothing to do here. */
244 }
245
246 // Operators:
249 mx += mstride;
250 return *this;
251 }
252
254 const Complex& operator*() const { return *mx; }
255
257 bool operator!=(const ConstComplexIterator1D& other) const {
258 if (mx != other.mx)
259 return true;
260 return false;
261 }
262
263 friend void copy(ConstComplexIterator1D origin,
264 const ConstComplexIterator1D& end,
265 ComplexIterator1D target);
266
267 private:
269 const Complex* mx{nullptr};
272};
273
274// Declare the complex vector class:
275class ComplexVector;
276
277// Declare the ComplexMatrixView class
279
286 public:
287 static constexpr bool matpack_type{true};
288
293
294 // Typedef for compatibility with STL
296
297 // Member functions:
298 [[nodiscard]] bool empty() const noexcept { return (nelem() == 0); }
299 [[nodiscard]] Index nelem() const noexcept { return mrange.mextent; }
300 [[nodiscard]] Index size() const noexcept { return mrange.mextent; }
301 [[nodiscard]] Complex sum() const;
302
303 // Const index operators:
305 const Complex& operator[](Index n) const { // Check if index is valid:
306 ARTS_ASSERT(0 <= n);
308 return get(n);
309 }
310
312 [[nodiscard]] const Complex& get(Index n) const {
313 return *(mdata + mrange.mstart + n * mrange.mstride);
314 }
315
317 [[nodiscard]] const Numeric& get_real(Index n) const {
318 return reinterpret_cast<const ComplexLayout(&)>(get(n)).real;
319 }
320
322 [[nodiscard]] const Numeric& get_imag(Index n) const {
323 return reinterpret_cast<const ComplexLayout(&)>(get(n)).imag;
324 }
325
327 [[nodiscard]] ConstVectorView real() const;
328
330 [[nodiscard]] ConstVectorView imag() const;
331
335
336 // Functions returning iterators:
337 [[nodiscard]] ConstComplexIterator1D begin() const;
338 [[nodiscard]] ConstComplexIterator1D end() const;
339
340 // Conversion to 1 column matrix:
341 operator ConstComplexMatrixView() const;
342
344 virtual ~ConstComplexVectorView() = default;
345
346 // Friends:
347 friend class ComplexVectorView;
350 friend void mult(ComplexVectorView,
353
354 friend std::ostream& operator<<(std::ostream& os, const ConstComplexVectorView& v);
355
356 // A special constructor, that allows to make a ConstVectorView of a scalar.
358
360 [[nodiscard]] Index selem() const noexcept {return mrange.mstart;}
361
363 [[nodiscard]] Index delem() const noexcept {return mrange.mstride;}
364
365 [[nodiscard]] Complex* get_c_array() const noexcept {return mdata;}
366
367 protected:
368 // Constructors:
370 ConstComplexVectorView(Complex* data, const Range& range);
371 ConstComplexVectorView(Complex* data, const Range& p, const Range& n);
372
373 // Data members:
374 // -------------
378 Complex* mdata{nullptr};
379};
380
393 public:
394 // Make const methods visible from base class
397 using ConstComplexVectorView::operator[];
403
404 constexpr ComplexVectorView(const ComplexVectorView&) = default;
407
408 // Typedef for compatibility with STL
410
412 Complex& operator[](Index n) { // Check if index is valid:
413 ARTS_ASSERT(0 <= n);
415 return get(n);
416 }
417
420 return *(mdata + mrange.mstart + n * mrange.mstride);
421 }
422
425 return reinterpret_cast<ComplexLayout(&)>(get(n)).real;
426 }
427
430 return reinterpret_cast<ComplexLayout(&)>(get(n)).imag;
431 }
432
434 [[nodiscard]] VectorView real();
435
437 [[nodiscard]] VectorView imag();
438
440
441 // ComplexIterators:
444
445 // Assignment operators:
456
457 // Other operators:
466
475
476 // Conversion to 1 column matrix:
477 operator ComplexMatrixView();
478
480 ~ComplexVectorView() override = default;
481
482 // Friends:
484 friend class ComplexIterator2D;
485 friend class ComplexMatrixView;
486
487 // A special constructor, that allows to make a ComplexVectorView of a scalar.
489
490 protected:
491 // Constructors:
492 ComplexVectorView() = default;
493 ComplexVectorView(Complex* data, const Range& range);
494 ComplexVectorView(Complex* data, const Range& p, const Range& n);
495};
496
501 public:
502 // Constructors:
504 ComplexIterator2D() = default;
505
508 : msv(x), mstride(stride) { /* Nothing to do here. */
509 }
510
511 // Operators:
514 msv.mdata += mstride;
515 return *this;
516 }
517
519 bool operator!=(const ComplexIterator2D& other) const {
520 if (msv.mdata + msv.mrange.mstart !=
521 other.msv.mdata + other.msv.mrange.mstart)
522 return true;
523 return false;
524 }
525
529
532
533 private:
538};
539
544 public:
545 // Constructors:
548
551 : msv(std::move(x)), mstride(stride) { /* Nothing to do here. */
552 }
553
554 // Operators:
557 msv.mdata += mstride;
558 return *this;
559 }
560
562 bool operator!=(const ConstComplexIterator2D& other) const {
563 if (msv.mdata + msv.mrange.mstart !=
564 other.msv.mdata + other.msv.mrange.mstart)
565 return true;
566 return false;
567 }
568
571 const ConstComplexVectorView* operator->() const { return &msv; }
572
574 const ConstComplexVectorView& operator*() const { return msv; }
575
576 private:
581};
582
594 public:
595 // Constructors:
596 ComplexVector() = default;
597 ComplexVector(ComplexVector&& cv) noexcept : ComplexVectorView(std::forward<ComplexVectorView>(cv)) {
598 cv.mdata = nullptr;
599 }
600 explicit ComplexVector(Index n);
601 ComplexVector(Index n, Complex fill);
602 ComplexVector(Index n, Numeric fill);
603 ComplexVector(Complex start, Index extent, Complex stride);
604 ComplexVector(Complex start, Index extent, Numeric stride);
605 ComplexVector(Numeric start, Index extent, Complex stride);
606 ComplexVector(Numeric start, Index extent, Numeric stride);
607 explicit ComplexVector(const ConstComplexVectorView& v);
609 explicit ComplexVector(const Vector& v);
610 explicit ComplexVector(const std::vector<Complex>&);
611 explicit ComplexVector(const std::vector<Numeric>&);
613 : ComplexVectorView(c, r0) {
614 ARTS_ASSERT(r0.get_extent() >= 0, "Must have size. Has: ", r0.get_extent());
615 }
616
619 : ComplexVector(matpack::column_size(init)) {
620 *this = init;
621 }
622
623 [[nodiscard]] Shape<1> shape() const { return {nelem()}; }
624
625 // Assignment operators:
629
632 if (const auto s = matpack::shape<Index, 1>(init); shape().data not_eq s)
633 resize(s[0]);
634
635 for (Index i = 0; i < size(); i++)
636 operator[](i) = init[i];
637
638 return *this;
639 }
640
642 if (this != &v) {
643 delete[] mdata;
644 mdata = v.mdata;
645 mrange = v.mrange;
646 v.mrange = Range(0, 0);
647 v.mdata = nullptr;
648 }
649 return *this;
650 }
651
652 // Resize function:
653 void resize(Index n);
654
655 // Swap function:
656 friend void swap(ComplexVector& v1, ComplexVector& v2) noexcept;
657
658 // Destructor:
659 ~ComplexVector() noexcept override;
660};
661
662// Declare class ComplexMatrix:
663class ComplexMatrix;
664
676 public:
677 static constexpr bool matpack_type{true};
678
683
684 // Typedef for compatibility with STL
686
687 // Member functions:
688 [[nodiscard]] Index selem() const noexcept { return mrr.mstart + mcr.mstart; }
689 [[nodiscard]] Index nrows() const noexcept { return mrr.mextent; }
690 [[nodiscard]] Index ncols() const noexcept { return mcr.mextent; }
691 [[nodiscard]] Index drows() const noexcept { return mrr.mstride; }
692 [[nodiscard]] Index dcols() const noexcept { return mcr.mstride; }
693
694 // Total size
695 [[nodiscard]] Index size() const noexcept {return nrows() * ncols();}
696 [[nodiscard]] bool empty() const noexcept { return not nrows() or not ncols(); }
697
698 // Const index operators:
700 Complex operator()(Index r, Index c) const { // Check if indices are valid:
701 ARTS_ASSERT(0 <= r);
702 ARTS_ASSERT(0 <= c);
703 ARTS_ASSERT(r < mrr.mextent);
704 ARTS_ASSERT(c < mcr.mextent);
705
706 return get(r, c);
707 }
708
710 [[nodiscard]] Complex get(Index r, Index c) const {
711 return *(mdata + mrr.mstart + r * mrr.mstride + mcr.mstart +
712 c * mcr.mstride);
713 }
714
716 [[nodiscard]] Numeric get_real(Index r, Index c) const { return get(r, c).real(); }
717
719 [[nodiscard]] Numeric get_imag(Index r, Index c) const { return get(r, c).imag(); }
720
722 [[nodiscard]] ConstMatrixView real() const;
723
725 [[nodiscard]] ConstMatrixView imag() const;
726
728 [[nodiscard]] Index get_column_extent() const {return mcr.get_extent();}
729
730 ConstComplexMatrixView operator()(const Range& r, const Range& c) const;
731 ConstComplexVectorView operator()(const Range& r, Index c) const;
732 ConstComplexVectorView operator()(Index r, const Range& c) const;
733
734 // Functions returning iterators:
735 [[nodiscard]] ConstComplexIterator2D begin() const;
736 [[nodiscard]] ConstComplexIterator2D end() const;
737
738 // View on diagonal complex vector
739 [[nodiscard]] ConstComplexVectorView diagonal() const;
740
742 virtual ~ConstComplexMatrixView() = default;
743
744 // Friends:
745 friend class ComplexMatrixView;
748 friend void mult(ComplexVectorView,
751 friend void mult(ComplexMatrixView,
754 friend void mult(ComplexMatrixView,
755 const ConstMatrixView&,
757 friend void mult(ComplexMatrixView,
759 const ConstMatrixView&);
760
761 friend std::ostream& operator<<(std::ostream& os, const ConstComplexMatrixView& v);
762
763 [[nodiscard]] Complex* get_c_array() const noexcept {return mdata;}
764
765 protected:
766 // Constructors:
768 ConstComplexMatrixView(Complex* data, const Range& r, const Range& c);
770 const Range& pr,
771 const Range& pc,
772 const Range& nr,
773 const Range& nc);
774
775 // Data members:
776 // -------------
778 Range mrr{0, 0, 1};
780 Range mcr{0, 0, 1};
782 Complex* mdata{nullptr};
783};
784
795 public:
796 // Make const methods visible from base class
799 using ConstComplexMatrixView::operator();
806
807 constexpr ComplexMatrixView(const ComplexMatrixView&) = default;
808
809 // Typedef for compatibility with STL
811
812#define GETFUN(r, c) \
813 *(mdata + mrr.mstart + r * mrr.mstride + mcr.mstart + c * mcr.mstride)
814 // Index Operators:
816 Complex& operator()(Index r, Index c) { // Check if indices are valid:
817 ARTS_ASSERT(0 <= r);
818 ARTS_ASSERT(0 <= c);
821
822 return GETFUN(r, c);
823 }
824
826 Complex& get(Index r, Index c) { return GETFUN(r, c); }
827#undef GETFUN
828
831 return reinterpret_cast<ComplexLayout(&)>(get(r, c)).real;
832 }
833
836 return reinterpret_cast<ComplexLayout(&)>(get(r, c)).imag;
837 }
838
840 [[nodiscard]] MatrixView real();
841
843 [[nodiscard]] MatrixView imag();
844
845 ComplexMatrixView operator()(const Range& r, const Range& c);
846 ComplexVectorView operator()(const Range& r, Index c);
847 ComplexVectorView operator()(Index r, const Range& c);
848
849 // Functions returning iterators:
852
853 // View on diagonal complex vector
854 ComplexVectorView diagonal();
855
856 // Assignment operators:
862
863 // Other operators:
872
877
882
887
889 ~ComplexMatrixView() override = default;
890
891 // Friends:
892 friend class ComplexVectorView;
895
896 protected:
897 // Constructors:
899 ComplexMatrixView(Complex* data, const Range& r, const Range& c);
901 const Range& pr,
902 const Range& pc,
903 const Range& nr,
904 const Range& nc);
905};
906
916 public:
917 // Constructors:
918 ComplexMatrix() = default;
924
927 : ComplexMatrix(matpack::row_size(init), matpack::column_size(init)) {
928 *this = init;
929 }
930
931 [[nodiscard]] Shape<2> shape() const { return {nrows(), ncols()}; }
932
933 // Assignment operators:
934 ComplexMatrix& operator=(ComplexMatrix x);
935 ComplexMatrix& operator=(Complex x);
936 ComplexMatrix& operator=(const ConstComplexVectorView& v);
937
940 if (const auto s = matpack::shape<Index, 2>(init); shape().data not_eq s)
941 resize(s[0], s[1]);
942
943 auto [I, J] = shape().data;
944 for (Index i = 0; i < I; i++)
945 for (Index j = 0; j < J; j++)
946 operator()(i, j) = init(i, j);
947
948 return *this;
949 }
950
951 // Inverse in place
953
954 // Resize function:
955 void resize(Index r, Index c);
956
957 // Swap function:
958 friend void swap(ComplexMatrix& m1, ComplexMatrix& m2) noexcept;
959
960 // Destructor:
961 ~ComplexMatrix() noexcept override;
962
963 Complex* get_raw_data() { return mdata; }
964};
965
966// Function declarations:
967// ----------------------
968
970
972
973void copy(ConstComplexIterator1D origin,
975 ComplexIterator1D target);
976
977void copy(Complex x, ComplexIterator1D target, const ComplexIterator1D& end);
978
979void copy(ConstComplexIterator2D origin,
981 ComplexIterator2D target);
982
983void copy(Complex x, ComplexIterator2D target, const ComplexIterator2D& end);
984
987 const ConstComplexVectorView& x);
988
990 const ConstComplexMatrixView& B,
991 const ConstComplexMatrixView& C);
993 const ConstMatrixView& B,
994 const ConstComplexMatrixView& C);
996 const ConstComplexMatrixView& B,
997 const ConstMatrixView& C);
999 const ConstMatrixView& B,
1000 const ConstMatrixView& C);
1001
1003 const ConstComplexVectorView& b);
1004
1007
1008#endif
This can be used to make arrays out of anything.
Definition: array.h:48
The iterator class for sub vectors.
ComplexIterator1D & operator++()
Prefix increment operator.
bool operator!=(const ComplexIterator1D &other) const
Not equal operator, needed for algorithms like copy.
ComplexIterator1D()=default
Default constructor.
ComplexIterator1D(Complex *x, Index stride)
Explicit constructor.
Index mstride
Stride.
Complex & operator*() const
Dereferencing.
Complex * mx
Current position.
friend void copy(ConstComplexIterator1D origin, const ConstComplexIterator1D &end, ComplexIterator1D target)
Copy data between begin and end to target.
The row iterator class for sub matrices.
ComplexIterator2D & operator++()
Prefix increment operator.
ComplexVectorView & operator*()
Dereferencing.
ComplexVectorView msv
Current position.
ComplexVectorView * operator->()
The -> operator is needed, so that we can write i->begin() to get the 1D iterators.
bool operator!=(const ComplexIterator2D &other) const
Not equal operator, needed for algorithms like copy.
ComplexIterator2D(const ComplexVectorView &x, Index stride)
Explicit constructor.
ComplexIterator2D()=default
Default constructor.
Index mstride
Row stride.
The ComplexMatrixView class.
ComplexMatrixView & operator-=(const ConstComplexVectorView &x)
ComplexMatrixView & operator*=(const ConstComplexVectorView &x)
Complex & operator()(Index r, Index c)
Plain index operator.
~ComplexMatrixView() override=default
Destructor.
ComplexMatrixView & operator+=(const ConstComplexVectorView &x)
Numeric & get_imag(Index r, Index c)
Get element implementation without assertions.
ComplexIterator2D end()
Return iterator behind last row.
Complex & get(Index r, Index c)
Get element implementation without assertions.
constexpr ComplexMatrixView(const ComplexMatrixView &)=default
Numeric & get_real(Index r, Index c)
Get element implementation without assertions.
ComplexMatrixView & operator/=(const ConstComplexVectorView &x)
ComplexMatrixView()
Default constructor.
ComplexIterator2D begin()
Return iterator to first row.
The ComplexMatrix class.
Shape< 2 > shape() const
ComplexMatrix(const matpack::matrix_like_not_matrix auto &init)
Initialization from a vector type.
ComplexMatrix & operator=(const matpack::matrix_like_not_matrix auto &init)
Set from a matrix type.
ComplexMatrix()=default
The ComplexVectorView class.
ComplexVectorView & operator=(const Vector &v)
VectorView real()
Get a view of the real part of the vector.
ComplexVectorView & operator=(const Array< Numeric > &v)
ComplexVectorView operator-=(Complex x)
Subtraction of scalar.
ComplexVectorView & operator=(const VectorView &v)
~ComplexVectorView() override=default
Destructor.
Numeric & get_real(Index n)
Get element implementation without assertions.
friend class ConstComplexIterator2D
constexpr ComplexVectorView(const ComplexVectorView &)=default
ComplexVectorView operator+=(Complex x)
Addition of scalar.
VectorView imag()
Get a view of the imaginary part of the vector.
ComplexVectorView operator*=(Complex x)
Multiplication by scalar.
ComplexVectorView & operator=(const ConstComplexVectorView &v)
Assignment operator.
ComplexVectorView()=default
ComplexIterator1D end()
Return iterator behind last element.
ComplexVectorView & operator=(const ConstVectorView &v)
Complex & operator[](Index n)
Plain Index operator.
ComplexVectorView operator/=(Complex x)
Division by scalar.
Complex & get(Index n)
Get element implementation without assertions.
Numeric & get_imag(Index n)
Get element implementation without assertions.
ComplexIterator1D begin()
Return iterator to first element.
friend class ComplexMatrixView
The ComplexVector class.
ComplexVector()=default
ComplexVector(ComplexVector &&cv) noexcept
ComplexVector(const matpack::vector_like_not_vector auto &init)
Initialization from a vector type.
ComplexVector & operator=(ComplexVector &&v) ARTS_NOEXCEPT
friend void swap(ComplexVector &v1, ComplexVector &v2) noexcept
Swaps two objects.
Shape< 1 > shape() const
~ComplexVector() noexcept override
Destructor for ComplexVector.
ComplexVector(Complex *c, const Range &r0) ARTS_NOEXCEPT
void resize(Index n)
Resize function.
ComplexVector & operator=(const ComplexVector &v)
Assignment from another Vector.
ComplexVector & operator=(const matpack::vector_like_not_vector auto &init)
Set from a vector type.
The constant iterator class for sub vectors.
ConstComplexIterator1D()=default
Default constructor.
const Complex & operator*() const
Dereferencing.
ConstComplexIterator1D & operator++()
Prefix increment operator.
const Complex * mx
Current position.
bool operator!=(const ConstComplexIterator1D &other) const
Not equal operator, needed for algorithms like copy.
friend void copy(ConstComplexIterator1D origin, const ConstComplexIterator1D &end, ComplexIterator1D target)
Copy data between begin and end to target.
ConstComplexIterator1D(Complex *x, Index stride)
Explicit constructor.
The const row iterator class for sub matrices.
bool operator!=(const ConstComplexIterator2D &other) const
Not equal operator, needed for algorithms like copy.
ConstComplexIterator2D(ConstComplexVectorView x, Index stride)
Explicit constructor.
ConstComplexIterator2D & operator++()
Prefix increment operator.
const ConstComplexVectorView & operator*() const
Dereferencing.
Index mstride
Row stride.
ConstComplexIterator2D()=default
Default constructor.
const ConstComplexVectorView * operator->() const
The -> operator is needed, so that we can write i->begin() to get t he 1D iterators.
ConstComplexVectorView msv
Current position.
A constant view of a ComplexMatrix.
Complex get(Index r, Index c) const
Get element implementation without assertions.
ConstComplexIterator2D begin() const
Return const iterator to first row.
Range mcr
The column range of mdata that is actually used.
constexpr ConstComplexMatrixView(const ConstComplexMatrixView &)=default
ConstComplexVectorView diagonal() const
ComplexMatrix diagonal as vector.
bool empty() const noexcept
Index drows() const noexcept
Index dcols() const noexcept
Complex operator()(Index r, Index c) const
Plain const index operator.
Numeric get_imag(Index r, Index c) const
Get element implementation without assertions.
Index ncols() const noexcept
Index selem() const noexcept
ConstComplexMatrixView()=default
Range mrr
The row range of mdata that is actually used.
Index size() const noexcept
ConstComplexMatrixView & operator=(ConstComplexMatrixView &&)=default
Index nrows() const noexcept
Index get_column_extent() const
Get the extent of the underlying data.
ConstMatrixView imag() const
Get a view of the imaginary part of the matrix.
ConstComplexMatrixView & operator=(const ConstComplexMatrixView &)=default
constexpr ConstComplexMatrixView(ConstComplexMatrixView &&)=default
ConstComplexIterator2D end() const
Return const iterator behind last row.
Complex * get_c_array() const noexcept
virtual ~ConstComplexMatrixView()=default
Destructor.
Numeric get_real(Index r, Index c) const
Get element implementation without assertions.
ConstMatrixView real() const
Get a view of the real part of the matrix.
A constant view of a ComplexVector.
Complex sum() const
Returns true if variable size is zero.
ConstVectorView imag() const
Get a view of the imaginary part of the vector.
bool empty() const noexcept
const Numeric & get_imag(Index n) const
Get element implementation without assertions.
ConstComplexIterator1D end() const
Return const iterator behind last element.
friend class ConstComplexMatrixView
ConstComplexVectorView & operator=(ConstComplexVectorView &&)=default
static constexpr bool matpack_type
Complex * get_c_array() const noexcept
ConstVectorView real() const
Get a view of the real part of the vector.
Range mrange
The range of mdata that is actually used.
ConstComplexVectorView()=default
constexpr ConstComplexVectorView(ConstComplexVectorView &&)=default
Complex * mdata
Pointer to the plain C array that holds the data.
ConstComplexIterator1D begin() const
Return const iterator to first element.
Index size() const noexcept
friend Complex operator*(const ConstComplexVectorView &a, const ConstComplexVectorView &b)
Scalar product.
const Numeric & get_real(Index n) const
Get element implementation without assertions.
const Complex & get(Index n) const
Get element implementation without assertions.
friend std::ostream & operator<<(std::ostream &os, const ConstComplexVectorView &v)
Output operator.
constexpr ConstComplexVectorView(const ConstComplexVectorView &)=default
Index nelem() const noexcept
Index selem() const noexcept
Start element in memory.
Index delem() const noexcept
Steps in memory between elements.
const Complex & operator[](Index n) const
Plain const index operator.
virtual ~ConstComplexVectorView()=default
Destructor.
ConstComplexVectorView & operator=(const ConstComplexVectorView &)=default
friend void mult(ComplexVectorView, const ConstComplexMatrixView &, const ConstComplexVectorView &)
Matrix-Vector Multiplication.
A constant view of a Matrix.
Definition: matpackI.h:1065
A constant view of a Vector.
Definition: matpackI.h:521
The Joker class.
Definition: matpackI.h:126
The MatrixView class.
Definition: matpackI.h:1188
The range class.
Definition: matpackI.h:160
Index mstart
The start index.
Definition: matpackI.h:377
Index mstride
The stride.
Definition: matpackI.h:382
Index mextent
The number of elements.
Definition: matpackI.h:380
The VectorView class.
Definition: matpackI.h:674
The Vector class.
Definition: matpackI.h:910
A concept precluding Arts matrix objects but allowing things similar to matrices.
A concept precluding Arts vector objects but allowing things similar to vectors.
#define ARTS_NOEXCEPT
Definition: debug.h:99
#define ARTS_ASSERT(condition,...)
Definition: debug.h:102
Interface for the LAPACK library.
void inv(MatrixView Ainv, ConstMatrixView A)
Matrix Inverse.
Definition: lin_alg.cc:167
Implementation of Matrix, Vector, and such stuff.
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:33
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
void swap(ComplexVector &v1, ComplexVector &v2) noexcept
Swaps two objects.
#define _complex_operations_(T)
ConstComplexMatrixView transpose(ConstComplexMatrixView m)
Const version of transpose.
std::complex< float > operator+(const double &d, const std::complex< float > &c)
#define b1
std::complex< float > operator*(const double &d, const std::complex< float > &c)
Numeric & real_val(Complex &c) noexcept
Return a reference to the real value of c.
constexpr Numeric imag(Complex c) noexcept
imag
const Joker joker
constexpr Complex conj(Complex c) noexcept
the conjugate of c
#define a2
Numeric & imag_val(Complex &c) noexcept
Return a reference to the imaginary value of c.
constexpr Numeric abs2(Complex c) noexcept
squared magnitude of c
#define a1
std::complex< Numeric > Complex
constexpr Complex operator/(Complex c, Numeric n) noexcept
constexpr Complex operator-(Complex c, Numeric n) noexcept
#define b2
constexpr Numeric real(Complex c) noexcept
real
void copy(ConstComplexIterator1D origin, const ConstComplexIterator1D &end, ComplexIterator1D target)
Copy data between begin and end to target.
#define GETFUN(r, c)
constexpr bool isnan(double d) noexcept
Definition: nonstd.h:53
#define M
Definition: rng.cc:165
Helper shape class.
Definition: matpackI.h:387
Struct cannot be const, but can be passed as const to allow defaults.
Definition: lapack.h:23
#define d
#define v
#define a
#define c
#define b