ARTS 2.5.4 (git: 4c0d3b4d)
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 "nonstd.h"
32#include <complex>
33#include <utility>
34
35using Complex = std::complex<Numeric>;
37
39inline Numeric& real_val(Complex& c) noexcept {return reinterpret_cast<ComplexLayout(&)>(c).real;}
40
42inline Numeric& imag_val(Complex& c) noexcept {return reinterpret_cast<ComplexLayout(&)>(c).imag;}
43
45inline const Numeric& real_val(const Complex& c) noexcept {return reinterpret_cast<const ComplexLayout(&)>(c).real;}
46
48inline const Numeric& imag_val(const Complex& c) noexcept {return reinterpret_cast<const ComplexLayout(&)>(c).imag;}
49
50inline std::complex<float> operator+(const double& d,
51 const std::complex<float>& c) {
52 return (float(d) + c);
53}
54inline std::complex<float> operator*(const double& d,
55 const std::complex<float>& c) {
56 return (float(d) * c);
57}
58
59inline std::complex<float> operator+(const std::complex<float>& c,
60 const double& d) {
61 return (c + float(d));
62}
63inline std::complex<float> operator*(const std::complex<float>& c,
64 const double& d) {
65 return (c * float(d));
66}
67
68// Constexpr versions of common Complex operations
69
70// Helpers to keep equations readable
71#define a1 c.real()
72#define b1 c.imag()
73#define a2 z.real()
74#define b2 z.imag()
75
77constexpr Numeric abs2(Complex c) noexcept { return a1 * a1 + b1 * b1; }
78
80constexpr Complex conj(Complex c) noexcept { return Complex(a1, -b1); }
81
83constexpr Numeric real(Complex c) noexcept { return a1; }
84
86constexpr Numeric imag(Complex c) noexcept { return b1; }
87
88// Basic constexpr operations for Complex that don't exist in the standard yet (C++11)
89// NOTE: Remove these if there is ever an overload warning updating the C++ compiler version
90
91constexpr Complex operator+(Complex c, Numeric n) noexcept {
92 return Complex(a1 + n, b1);
93}
94constexpr Complex operator-(Complex c, Numeric n) noexcept {
95 return Complex(a1 - n, b1);
96}
97constexpr Complex operator*(Complex c, Numeric n) noexcept {
98 return Complex(a1 * n, b1 * n);
99}
100constexpr Complex operator/(Complex c, Numeric n) noexcept {
101 return Complex(a1 / n, b1 / n);
102}
103
104constexpr Complex operator+(Numeric n, Complex c) noexcept {
105 return Complex(n + a1, b1);
106}
107constexpr Complex operator-(Numeric n, Complex c) noexcept {
108 return Complex(n - a1, -b1);
109}
110constexpr Complex operator*(Numeric n, Complex c) noexcept {
111 return Complex(n * a1, n * b1);
112}
113constexpr Complex operator/(Numeric n, Complex c) noexcept {
114 return Complex(n * a1, -n * b1) / abs2(c);
115}
116
117constexpr Complex operator+(Complex c, Complex z) noexcept {
118 return Complex(a1 + a2, b1 + b2);
119}
120constexpr Complex operator-(Complex c, Complex z) noexcept {
121 return Complex(a1 - a2, b1 - b2);
122}
123constexpr Complex operator*(Complex c, Complex z) noexcept {
124 return Complex(a1 * a2 - b1 * b2, a1 * b2 + b1 * a2);
125}
126constexpr Complex operator/(Complex c, Complex z) noexcept {
127 return Complex(a1 * a2 + b1 * b2, -a1 * b2 + b1 * a2) / abs2(z);
128}
129constexpr Complex operator-(Complex c) noexcept { return Complex(-a1, -b1); }
130
131// Remove helpers to keep global namespace usable
132#undef a1
133#undef b1
134#undef a2
135#undef b2
136
137// Basic constexpr operations for different types since C++11 std::complex is lacking conversions
138// FIXME: Cannot be template because Eigen interferes, so explicit copies are required for operations
139// NOTE: Remove these if there is ever an overload warning updating the C++ compiler version
140#define _complex_operations_(T) \
141 constexpr Complex operator+(Complex c, T x) noexcept { \
142 return operator+(c, static_cast<Numeric>(x)); \
143 } \
144 constexpr Complex operator-(Complex c, T x) noexcept { \
145 return operator-(c, static_cast<Numeric>(x)); \
146 } \
147 constexpr Complex operator*(Complex c, T x) noexcept { \
148 return operator*(c, static_cast<Numeric>(x)); \
149 } \
150 constexpr Complex operator/(Complex c, T x) noexcept { \
151 return operator/(c, static_cast<Numeric>(x)); \
152 } \
153 \
154 constexpr Complex operator+(T x, Complex c) noexcept { \
155 return operator+(static_cast<Numeric>(x), c); \
156 } \
157 constexpr Complex operator-(T x, Complex c) noexcept { \
158 return operator-(static_cast<Numeric>(x), c); \
159 } \
160 constexpr Complex operator*(T x, Complex c) noexcept { \
161 return operator*(static_cast<Numeric>(x), c); \
162 } \
163 constexpr Complex operator/(T x, Complex c) noexcept { \
164 return operator/(static_cast<Numeric>(x), c); \
165 }
166
170
171#undef _complex_operations_
172
173constexpr bool isnan(Complex c) noexcept {
174 return nonstd::isnan(c.real()) or nonstd::isnan(c.imag());
175}
176
177 // Declare existence of the global joker object:
178 extern const Joker joker;
179
180// Declare the existence of class ConstComplexMatrixView:
182
183// Declare the existence of class ComplexVectorView:
185
186// Declare the existence of class ConstComplexVectorView:
188
189// Declare the existence of class ConstMatrixView:
191
192// Eigen library interactions:
193using ComplexMatrixType = Eigen::Matrix<Complex, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>;
194using ComplexMatrixViewMap = Eigen::Map<ComplexMatrixType, 0, StrideType>;
195using ConstComplexMatrixViewMap = Eigen::Map<const ComplexMatrixType, 0, StrideType>;
196
200 public:
202 ComplexIterator1D() = default;
203
206 : mx(x), mstride(stride) { /* Nothing to do here. */
207 }
208
209 // Operators:
210
213 mx += mstride;
214 return *this;
215 }
216
218 Complex& operator*() const { return *mx; }
219
221 bool operator!=(const ComplexIterator1D& other) const {
222 if (mx != other.mx)
223 return true;
224 return false;
225 }
226
227 friend void copy(ConstComplexIterator1D origin,
229 ComplexIterator1D target);
230
231 private:
233 Complex* mx{nullptr};
236};
237
241 public:
244
247 : mx(x), mstride(stride) { /* Nothing to do here. */
248 }
249
250 // Operators:
253 mx += mstride;
254 return *this;
255 }
256
258 const Complex& operator*() const { return *mx; }
259
261 bool operator!=(const ConstComplexIterator1D& other) const {
262 if (mx != other.mx)
263 return true;
264 return false;
265 }
266
267 friend void copy(ConstComplexIterator1D origin,
269 ComplexIterator1D target);
270
271 private:
273 const Complex* mx{nullptr};
276};
277
278// Declare the complex vector class:
279class ComplexVector;
280
281// Declare the ComplexMatrixView class
283
290 public:
295
296 // Typedef for compatibility with STL
298
299 // Member functions:
300 [[nodiscard]] bool empty() const noexcept { return (nelem() == 0); }
301 [[nodiscard]] Index nelem() const noexcept { return mrange.mextent; }
302 [[nodiscard]] Complex sum() const;
303
304 // Const index operators:
306 const Complex& operator[](Index n) const { // Check if index is valid:
307 ARTS_ASSERT(0 <= n);
309 return get(n);
310 }
311
313 [[nodiscard]] const Complex& get(Index n) const {
314 return *(mdata + mrange.mstart + n * mrange.mstride);
315 }
316
318 [[nodiscard]] const Numeric& get_real(Index n) const {
319 return reinterpret_cast<const ComplexLayout(&)>(get(n)).real;
320 }
321
323 [[nodiscard]] const Numeric& get_imag(Index n) const {
324 return reinterpret_cast<const ComplexLayout(&)>(get(n)).imag;
325 }
326
328 [[nodiscard]] ConstVectorView real() const {return ConstVectorView(reinterpret_cast<Numeric *>(mdata), Range(2*mrange.mstart, mrange.mextent, mrange.mstride*2));}
329
331 [[nodiscard]] ConstVectorView imag() const {return ConstVectorView(reinterpret_cast<Numeric *>(mdata), Range(2*mrange.mstart + 1, mrange.mextent, mrange.mstride*2));}
332
336
337 // Functions returning iterators:
338 [[nodiscard]] ConstComplexIterator1D begin() const;
339 [[nodiscard]] ConstComplexIterator1D end() const;
340
341 // Conversion to 1 column matrix:
342 operator ConstComplexMatrixView() const;
343
345 virtual ~ConstComplexVectorView() = default;
346
347 // Friends:
348 friend class ComplexVectorView;
351 friend void mult(ComplexVectorView,
354
359
360 // A special constructor, that allows to make a ConstVectorView of a scalar.
362
363 protected:
364 // Constructors:
366 ConstComplexVectorView(Complex* data, const Range& range);
367 ConstComplexVectorView(Complex* data, const Range& p, const Range& n);
368
369 // Data members:
370 // -------------
374 Complex* mdata{nullptr};
375};
376
389 public:
390 // Make const methods visible from base class
393 using ConstComplexVectorView::operator[];
399
400 constexpr ComplexVectorView(const ComplexVectorView&) = default;
403
404 // Typedef for compatibility with STL
406
408 Complex& operator[](Index n) { // Check if index is valid:
409 ARTS_ASSERT(0 <= n);
411 return get(n);
412 }
413
416 return *(mdata + mrange.mstart + n * mrange.mstride);
417 }
418
421 return reinterpret_cast<ComplexLayout(&)>(get(n)).real;
422 }
423
426 return reinterpret_cast<ComplexLayout(&)>(get(n)).imag;
427 }
428
431
433 VectorView imag() {return VectorView(reinterpret_cast<Numeric *>(mdata), Range(2*mrange.mstart + 1, mrange.mextent, mrange.mstride*2));}
434
436
437 // ComplexIterators:
440
441 // Assignment operators:
452
453 // Other operators:
462
471
472 // Conversion to 1 column matrix:
473 operator ComplexMatrixView();
474 // Conversion to a plain C-array
475 [[nodiscard]] const Complex* get_c_array() const ARTS_NOEXCEPT;
477
479 ~ComplexVectorView() override = default;
480
481 // Friends:
483 friend class ComplexIterator2D;
484 friend class ComplexMatrixView;
485
486 // A special constructor, that allows to make a ComplexVectorView of a scalar.
488
489 protected:
490 // Constructors:
491 ComplexVectorView() = default;
492 ComplexVectorView(Complex* data, const Range& range);
493 ComplexVectorView(Complex* data, const Range& p, const Range& n);
494};
495
500 public:
501 // Constructors:
503 ComplexIterator2D() = default;
504
507 : msv(x), mstride(stride) { /* Nothing to do here. */
508 }
509
510 // Operators:
513 msv.mdata += mstride;
514 return *this;
515 }
516
518 bool operator!=(const ComplexIterator2D& other) const {
519 if (msv.mdata + msv.mrange.mstart !=
520 other.msv.mdata + other.msv.mrange.mstart)
521 return true;
522 return false;
523 }
524
527 ComplexVectorView* operator->() { return &msv; }
528
530 ComplexVectorView& operator*() { return msv; }
531
532 private:
536 Index mstride{0};
537};
538
543 public:
544 // Constructors:
547
550 : msv(std::move(x)), mstride(stride) { /* Nothing to do here. */
551 }
552
553 // Operators:
556 msv.mdata += mstride;
557 return *this;
558 }
559
561 bool operator!=(const ConstComplexIterator2D& other) const {
562 if (msv.mdata + msv.mrange.mstart !=
563 other.msv.mdata + other.msv.mrange.mstart)
564 return true;
565 return false;
566 }
567
570 const ConstComplexVectorView* operator->() const { return &msv; }
571
573 const ConstComplexVectorView& operator*() const { return msv; }
574
575 private:
579 Index mstride{0};
580};
581
593 public:
594 // Constructors:
595 ComplexVector() = default;
596 ComplexVector(ComplexVector&& cv) noexcept : ComplexVectorView(std::forward<ComplexVectorView>(cv)) {
597 cv.mdata = nullptr;
598 }
599 explicit ComplexVector(Index n);
600 ComplexVector(Index n, Complex fill);
601 ComplexVector(Index n, Numeric fill);
602 ComplexVector(Complex start, Index extent, Complex stride);
603 ComplexVector(Complex start, Index extent, Numeric stride);
604 ComplexVector(Numeric start, Index extent, Complex stride);
605 ComplexVector(Numeric start, Index extent, Numeric stride);
606 explicit ComplexVector(const ConstComplexVectorView& v);
608 explicit ComplexVector(const Vector& v);
609 explicit ComplexVector(const std::vector<Complex>&);
610 explicit ComplexVector(const std::vector<Numeric>&);
613 ARTS_ASSERT(r0.get_extent() >= 0, "Must have size. Has: ", r0.get_extent());
614 }
615
616 // Assignment operators:
620
622 if (this != &v) {
623 delete[] mdata;
624 mdata = v.mdata;
625 mrange = v.mrange;
626 v.mrange = Range(0, 0);
627 v.mdata = nullptr;
628 }
629 return *this;
630 }
631
632 // Resize function:
633 void resize(Index n);
634
635 // Swap function:
636 friend void swap(ComplexVector& v1, ComplexVector& v2);
637
638 // Destructor:
639 ~ComplexVector() override;
640
641 // Total size
642 [[nodiscard]] Index size() const noexcept {return nelem();}
643};
644
645// Declare class ComplexMatrix:
646class ComplexMatrix;
647
659 public:
664
665 // Typedef for compatibility with STL
667
668 // Member functions:
669 [[nodiscard]] Index nrows() const noexcept { return mrr.mextent; }
670 [[nodiscard]] Index ncols() const noexcept { return mcr.mextent; }
671 [[nodiscard]] bool empty() const noexcept { return not nrows() or not ncols(); }
672
673 // Const index operators:
675 Complex operator()(Index r, Index c) const { // Check if indices are valid:
676 ARTS_ASSERT(0 <= r);
677 ARTS_ASSERT(0 <= c);
678 ARTS_ASSERT(r < mrr.mextent);
679 ARTS_ASSERT(c < mcr.mextent);
680
681 return get(r, c);
682 }
683
685 [[nodiscard]] Complex get(Index r, Index c) const {
686 return *(mdata + mrr.mstart + r * mrr.mstride + mcr.mstart +
687 c * mcr.mstride);
688 }
689
691 [[nodiscard]] Numeric get_real(Index r, Index c) const { return get(r, c).real(); }
692
694 [[nodiscard]] Numeric get_imag(Index r, Index c) const { return get(r, c).imag(); }
695
697 [[nodiscard]] ConstMatrixView real() const {return ConstMatrixView(reinterpret_cast<Numeric *>(mdata), Range(2*mrr.mstart, mrr.mextent, mrr.mstride*2),
698 Range(2*mcr.mstart, mcr.mextent, mcr.mstride*2));}
699
701 [[nodiscard]] ConstMatrixView imag() const {return ConstMatrixView(reinterpret_cast<Numeric *>(mdata), Range(2*mrr.mstart, mrr.mextent, mrr.mstride*2),
702 Range(2*mcr.mstart + 1, mcr.mextent, mcr.mstride*2));}
703
705 [[nodiscard]] Index get_column_extent() const {return mcr.get_extent();}
706
707 ConstComplexMatrixView operator()(const Range& r, const Range& c) const;
708 ConstComplexVectorView operator()(const Range& r, Index c) const;
709 ConstComplexVectorView operator()(Index r, const Range& c) const;
710
711 // Functions returning iterators:
712 [[nodiscard]] ConstComplexIterator2D begin() const;
713 [[nodiscard]] ConstComplexIterator2D end() const;
714
715 // View on diagonal complex vector
716 [[nodiscard]] ConstComplexVectorView diagonal() const;
717
719 virtual ~ConstComplexMatrixView() = default;
720
721 // Friends:
722 friend class ComplexMatrixView;
725 friend void mult(ComplexVectorView,
728 friend void mult(ComplexMatrixView,
731 friend void mult(ComplexMatrixView,
732 const ConstMatrixView&,
734 friend void mult(ComplexMatrixView,
736 const ConstMatrixView&);
737
738
741
742 protected:
743 // Constructors:
745 ConstComplexMatrixView(Complex* data, const Range& r, const Range& c);
747 const Range& pr,
748 const Range& pc,
749 const Range& nr,
750 const Range& nc);
751
752 // Data members:
753 // -------------
755 Range mrr{0, 0, 1};
757 Range mcr{0, 0, 1};
759 Complex* mdata{nullptr};
760};
761
772 public:
773 // Make const methods visible from base class
776 using ConstComplexMatrixView::operator();
783
784 constexpr ComplexMatrixView(const ComplexMatrixView&) = default;
785
786 // Typedef for compatibility with STL
788
789 // Index Operators:
791 Complex& operator()(Index r, Index c) { // Check if indices are valid:
792 ARTS_ASSERT(0 <= r);
793 ARTS_ASSERT(0 <= c);
794 ARTS_ASSERT(r < mrr.mextent);
795 ARTS_ASSERT(c < mcr.mextent);
796
797 return get(r, c);
798 }
799
802 return *(mdata + mrr.mstart + r * mrr.mstride + mcr.mstart +
803 c * mcr.mstride);
804 }
805
808 return reinterpret_cast<ComplexLayout(&)>(get(r, c)).real;
809 }
810
813 return reinterpret_cast<ComplexLayout(&)>(get(r, c)).imag;
814 }
815
817 MatrixView real() {return MatrixView(reinterpret_cast<Numeric *>(mdata), Range(2*mrr.mstart, mrr.mextent, mrr.mstride*2),
818 Range(2*mcr.mstart, mcr.mextent, mcr.mstride*2));}
819
821 MatrixView imag() {return MatrixView(reinterpret_cast<Numeric *>(mdata), Range(2*mrr.mstart, mrr.mextent, mrr.mstride*2),
822 Range(2*mcr.mstart + 1, mcr.mextent, mcr.mstride*2));}
823
824 ComplexMatrixView operator()(const Range& r, const Range& c);
825 ComplexVectorView operator()(const Range& r, Index c);
826 ComplexVectorView operator()(Index r, const Range& c);
827
828 // Functions returning iterators:
831
832 // View on diagonal complex vector
833 ComplexVectorView diagonal();
834
835 // Assignment operators:
841
842 // Other operators:
851
856
861
866
867 // Conversion to a plain C-array
868 [[nodiscard]] const Complex* get_c_array() const ARTS_NOEXCEPT;
870
872 ~ComplexMatrixView() override = default;
873
874 // Friends:
875 friend class ComplexVectorView;
878
879 protected:
880 // Constructors:
882 ComplexMatrixView(Complex* data, const Range& r, const Range& c);
884 const Range& pr,
885 const Range& pc,
886 const Range& nr,
887 const Range& nc);
888};
889
899 public:
900 // Constructors:
901 ComplexMatrix() = default;
907
908 // Assignment operators:
912
913 // Inverse in place
915
916 // Resize function:
917 void resize(Index r, Index c);
918
919 // Swap function:
920 friend void swap(ComplexMatrix& m1, ComplexMatrix& m2);
921
922 // Destructor:
923 ~ComplexMatrix() override;
924
925 // Total size
926 [[nodiscard]] Index size() const noexcept {return nrows() * ncols();}
927
929};
930
931// Function declarations:
932// ----------------------
933
935
937
938void copy(ConstComplexIterator1D origin,
940 ComplexIterator1D target);
941
942void copy(Complex x, ComplexIterator1D target, const ComplexIterator1D& end);
943
944void copy(ConstComplexIterator2D origin,
946 ComplexIterator2D target);
947
948void copy(Complex x, ComplexIterator2D target, const ComplexIterator2D& end);
949
952 const ConstComplexVectorView& x);
953
955 const ConstComplexMatrixView& B,
956 const ConstComplexMatrixView& C);
958 const ConstMatrixView& B,
959 const ConstComplexMatrixView& C);
961 const ConstComplexMatrixView& B,
962 const ConstMatrixView& C);
964 const ConstMatrixView& B,
965 const ConstMatrixView& C);
966
969
970std::ostream& operator<<(std::ostream& os, const ConstComplexVectorView& v);
971
972std::ostream& operator<<(std::ostream& os, const ConstComplexMatrixView& v);
973
974// Converts constant matrix to constant eigen map
976// Converts constant vector to constant eigen row-view
978// Converts constant vector to constant eigen row-view
980// Converts constant vector to constant eigen column-view
982// Converts matrix to eigen map
984// Converts vector to eigen map row-view
986// Converts vector to eigen map row-view
988// Converts vector to eigen map column-view
990
993
994#endif
This can be used to make arrays out of anything.
Definition: array.h:108
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.
The ComplexMatrixView class.
ComplexMatrixView & operator-=(const ConstComplexVectorView &x)
ComplexMatrixView & operator*=(const ConstComplexVectorView &x)
Complex & operator()(Index r, Index c)
Plain index operator.
MatrixView imag()
Get a view of the imaginary parts of the matrix.
MatrixView real()
Get a view of the real part of the matrix.
ComplexMatrixView & operator+=(const ConstComplexVectorView &x)
Numeric & get_imag(Index r, Index c)
Get element implementation without assertions.
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)
The ComplexMatrix class.
Complex * get_raw_data()
ComplexMatrix()=default
Index size() const noexcept
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)
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.
friend class ComplexIterator2D
ComplexVectorView operator/=(Complex x)
Division by scalar.
const Complex * get_c_array() const ARTS_NOEXCEPT
Conversion to plain C-array.
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 & operator=(ComplexVector &&v) noexcept
Index size() const noexcept
ComplexVector(Complex *c, const Range &r0) ARTS_NOEXCEPT
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.
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.
constexpr ConstComplexMatrixView(const ConstComplexMatrixView &)=default
ConstComplexVectorView diagonal() const
ComplexMatrix diagonal as vector.
bool empty() 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
ConstComplexMatrixView()=default
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.
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
ConstVectorView real() const
Get a view of the real part of the vector.
friend ConstComplexMatrixViewMap MapToEigen(const ConstComplexVectorView &)
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.
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.
constexpr ConstComplexVectorView(const ConstComplexVectorView &)=default
Index nelem() const noexcept
friend ConstComplexMatrixViewMap MapToEigenCol(const ConstComplexVectorView &)
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:1050
A constant view of a Vector.
Definition: matpackI.h:517
The Joker class.
Definition: matpackI.h:132
The MatrixView class.
Definition: matpackI.h:1169
The range class.
Definition: matpackI.h:166
Index mstart
The start index.
Definition: matpackI.h:368
Index mstride
The stride.
Definition: matpackI.h:377
Index mextent
The number of elements.
Definition: matpackI.h:375
The VectorView class.
Definition: matpackI.h:658
The Vector class.
Definition: matpackI.h:908
#define ARTS_NOEXCEPT
Definition: debug.h:80
#define ARTS_ASSERT(condition,...)
Definition: debug.h:83
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)
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
Eigen::Matrix< Complex, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > ComplexMatrixType
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
std::ostream & operator<<(std::ostream &os, const ConstComplexVectorView &v)
Output operator.
#define a1
ConstComplexMatrixViewMap MapToEigenRow(const ConstComplexVectorView &A)
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.
Eigen::Map< const ComplexMatrixType, 0, StrideType > ConstComplexMatrixViewMap
Eigen::Map< ComplexMatrixType, 0, StrideType > ComplexMatrixViewMap
constexpr Numeric r0
The reference radius in IGRF13.
Definition: igrf13.cc:203
VectorView std(VectorView std, const Vector &y, const ArrayOfVector &ys, const Index start, const Index end_tmp)
Compute the standard deviation of the ranged ys.
Definition: raw.cc:205
constexpr Rational start(Rational Ju, Rational Jl, Polarization type) noexcept
Gives the lowest M for a polarization type of this transition.
Definition: zeemandata.h:80
constexpr Rational end(Rational Ju, Rational Jl, Polarization type) noexcept
Gives the largest M for a polarization type of this transition.
Definition: zeemandata.h:113
constexpr bool isnan(double d) noexcept
Definition: nonstd.h:53
#define d
#define v
#define a
#define c
#define b
#define M
Definition: rng.cc:165
Struct cannot be const, but can be passed as const to allow defaults.
Definition: lapack.h:23