ARTS 2.5.4 (git: 31ce4f0e)
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 {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 {a1 + n, b1};
93}
94constexpr Complex operator-(Complex c, Numeric n) noexcept {
95 return {a1 - n, b1};
96}
97constexpr Complex operator*(Complex c, Numeric n) noexcept {
98 return {a1 * n, b1 * n};
99}
100constexpr Complex operator/(Complex c, Numeric n) noexcept {
101 return {a1 / n, b1 / n};
102}
103
104constexpr Complex operator+(Numeric n, Complex c) noexcept {
105 return {n + a1, b1};
106}
107constexpr Complex operator-(Numeric n, Complex c) noexcept {
108 return {n - a1, -b1};
109}
110constexpr Complex operator*(Numeric n, Complex c) noexcept {
111 return {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 {a1 + a2, b1 + b2};
119}
120constexpr Complex operator-(Complex c, Complex z) noexcept {
121 return {a1 - a2, b1 - b2};
122}
123constexpr Complex operator*(Complex c, Complex z) noexcept {
124 return {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 {-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
195 public:
197 ComplexIterator1D() = default;
198
201 : mx(x), mstride(stride) { /* Nothing to do here. */
202 }
203
204 // Operators:
205
208 mx += mstride;
209 return *this;
210 }
211
213 Complex& operator*() const { return *mx; }
214
216 bool operator!=(const ComplexIterator1D& other) const {
217 if (mx != other.mx)
218 return true;
219 return false;
220 }
221
222 friend void copy(ConstComplexIterator1D origin,
224 ComplexIterator1D target);
225
226 private:
228 Complex* mx{nullptr};
231};
232
236 public:
239
242 : mx(x), mstride(stride) { /* Nothing to do here. */
243 }
244
245 // Operators:
248 mx += mstride;
249 return *this;
250 }
251
253 const Complex& operator*() const { return *mx; }
254
256 bool operator!=(const ConstComplexIterator1D& other) const {
257 if (mx != other.mx)
258 return true;
259 return false;
260 }
261
262 friend void copy(ConstComplexIterator1D origin,
264 ComplexIterator1D target);
265
266 private:
268 const Complex* mx{nullptr};
271};
272
273// Declare the complex vector class:
274class ComplexVector;
275
276// Declare the ComplexMatrixView class
278
285 public:
290
291 // Typedef for compatibility with STL
293
294 // Member functions:
295 [[nodiscard]] bool empty() const noexcept { return (nelem() == 0); }
296 [[nodiscard]] Index nelem() const noexcept { return mrange.mextent; }
297 [[nodiscard]] Index size() const noexcept { return mrange.mextent; }
298 [[nodiscard]] Complex sum() const;
299
300 // Const index operators:
302 const Complex& operator[](Index n) const { // Check if index is valid:
303 ARTS_ASSERT(0 <= n);
305 return get(n);
306 }
307
309 [[nodiscard]] const Complex& get(Index n) const {
310 return *(mdata + mrange.mstart + n * mrange.mstride);
311 }
312
314 [[nodiscard]] const Numeric& get_real(Index n) const {
315 return reinterpret_cast<const ComplexLayout(&)>(get(n)).real;
316 }
317
319 [[nodiscard]] const Numeric& get_imag(Index n) const {
320 return reinterpret_cast<const ComplexLayout(&)>(get(n)).imag;
321 }
322
324 [[nodiscard]] ConstVectorView real() const {return ConstVectorView(reinterpret_cast<Numeric *>(mdata), Range(2*mrange.mstart, mrange.mextent, mrange.mstride*2));}
325
327 [[nodiscard]] ConstVectorView imag() const {return ConstVectorView(reinterpret_cast<Numeric *>(mdata), Range(2*mrange.mstart + 1, mrange.mextent, mrange.mstride*2));}
328
332
333 // Functions returning iterators:
334 [[nodiscard]] ConstComplexIterator1D begin() const;
335 [[nodiscard]] ConstComplexIterator1D end() const;
336
337 // Conversion to 1 column matrix:
338 operator ConstComplexMatrixView() const;
339
341 virtual ~ConstComplexVectorView() = default;
342
343 // Friends:
344 friend class ComplexVectorView;
347 friend void mult(ComplexVectorView,
350
351 friend std::ostream& operator<<(std::ostream& os, const ConstComplexVectorView& v);
352
353 // A special constructor, that allows to make a ConstVectorView of a scalar.
355
357 [[nodiscard]] Index selem() const noexcept {return mrange.mstart;}
358
360 [[nodiscard]] Index delem() const noexcept {return mrange.mstride;}
361
362 [[nodiscard]] Complex* get_c_array() const noexcept {return mdata;}
363
364 protected:
365 // Constructors:
367 ConstComplexVectorView(Complex* data, const Range& range);
368 ConstComplexVectorView(Complex* data, const Range& p, const Range& n);
369
370 // Data members:
371 // -------------
375 Complex* mdata{nullptr};
376};
377
390 public:
391 // Make const methods visible from base class
394 using ConstComplexVectorView::operator[];
400
401 constexpr ComplexVectorView(const ComplexVectorView&) = default;
404
405 // Typedef for compatibility with STL
407
409 Complex& operator[](Index n) { // Check if index is valid:
410 ARTS_ASSERT(0 <= n);
412 return get(n);
413 }
414
417 return *(mdata + mrange.mstart + n * mrange.mstride);
418 }
419
422 return reinterpret_cast<ComplexLayout(&)>(get(n)).real;
423 }
424
427 return reinterpret_cast<ComplexLayout(&)>(get(n)).imag;
428 }
429
432
434 VectorView imag() {return VectorView(reinterpret_cast<Numeric *>(mdata), Range(2*mrange.mstart + 1, mrange.mextent, mrange.mstride*2));}
435
437
438 // ComplexIterators:
441
442 // Assignment operators:
453
454 // Other operators:
463
472
473 // Conversion to 1 column matrix:
474 operator ComplexMatrixView();
475
477 ~ComplexVectorView() override = default;
478
479 // Friends:
481 friend class ComplexIterator2D;
482 friend class ComplexMatrixView;
483
484 // A special constructor, that allows to make a ComplexVectorView of a scalar.
486
487 protected:
488 // Constructors:
489 ComplexVectorView() = default;
490 ComplexVectorView(Complex* data, const Range& range);
491 ComplexVectorView(Complex* data, const Range& p, const Range& n);
492};
493
498 public:
499 // Constructors:
501 ComplexIterator2D() = default;
502
505 : msv(x), mstride(stride) { /* Nothing to do here. */
506 }
507
508 // Operators:
511 msv.mdata += mstride;
512 return *this;
513 }
514
516 bool operator!=(const ComplexIterator2D& other) const {
517 if (msv.mdata + msv.mrange.mstart !=
518 other.msv.mdata + other.msv.mrange.mstart)
519 return true;
520 return false;
521 }
522
526
529
530 private:
535};
536
541 public:
542 // Constructors:
545
548 : msv(std::move(x)), mstride(stride) { /* Nothing to do here. */
549 }
550
551 // Operators:
554 msv.mdata += mstride;
555 return *this;
556 }
557
559 bool operator!=(const ConstComplexIterator2D& other) const {
560 if (msv.mdata + msv.mrange.mstart !=
561 other.msv.mdata + other.msv.mrange.mstart)
562 return true;
563 return false;
564 }
565
568 const ConstComplexVectorView* operator->() const { return &msv; }
569
571 const ConstComplexVectorView& operator*() const { return msv; }
572
573 private:
578};
579
591 public:
592 // Constructors:
593 ComplexVector() = default;
594 ComplexVector(ComplexVector&& cv) noexcept : ComplexVectorView(std::forward<ComplexVectorView>(cv)) {
595 cv.mdata = nullptr;
596 }
597 explicit ComplexVector(Index n);
598 ComplexVector(Index n, Complex fill);
599 ComplexVector(Index n, Numeric fill);
600 ComplexVector(Complex start, Index extent, Complex stride);
601 ComplexVector(Complex start, Index extent, Numeric stride);
602 ComplexVector(Numeric start, Index extent, Complex stride);
603 ComplexVector(Numeric start, Index extent, Numeric stride);
604 explicit ComplexVector(const ConstComplexVectorView& v);
606 explicit ComplexVector(const Vector& v);
607 explicit ComplexVector(const std::vector<Complex>&);
608 explicit ComplexVector(const std::vector<Numeric>&);
611 ARTS_ASSERT(r0.get_extent() >= 0, "Must have size. Has: ", r0.get_extent());
612 }
613
615 explicit ComplexVector(const matpack::vector_like auto& init) : ComplexVector(init.size()) {
616 for (Index i=0; i<size(); i++) operator[](i) = init[i];
617 }
618
619 // Assignment operators:
623
625 if (this != &v) {
626 delete[] mdata;
627 mdata = v.mdata;
628 mrange = v.mrange;
629 v.mrange = Range(0, 0);
630 v.mdata = nullptr;
631 }
632 return *this;
633 }
634
635 // Resize function:
636 void resize(Index n);
637
638 // Swap function:
639 friend void swap(ComplexVector& v1, ComplexVector& v2);
640
641 // Destructor:
642 ~ComplexVector() override;
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 selem() const noexcept { return mrr.mstart + mcr.mstart; }
670 [[nodiscard]] Index nrows() const noexcept { return mrr.mextent; }
671 [[nodiscard]] Index ncols() const noexcept { return mcr.mextent; }
672 [[nodiscard]] Index drows() const noexcept { return mrr.mstride; }
673 [[nodiscard]] Index dcols() const noexcept { return mcr.mstride; }
674
675 // Total size
676 [[nodiscard]] Index size() const noexcept {return nrows() * ncols();}
677 [[nodiscard]] bool empty() const noexcept { return not nrows() or not ncols(); }
678
679 // Const index operators:
681 Complex operator()(Index r, Index c) const { // Check if indices are valid:
682 ARTS_ASSERT(0 <= r);
683 ARTS_ASSERT(0 <= c);
686
687 return get(r, c);
688 }
689
691 [[nodiscard]] Complex get(Index r, Index c) const {
692 return *(mdata + mrr.mstart + r * mrr.mstride + mcr.mstart +
693 c * mcr.mstride);
694 }
695
697 [[nodiscard]] Numeric get_real(Index r, Index c) const { return get(r, c).real(); }
698
700 [[nodiscard]] Numeric get_imag(Index r, Index c) const { return get(r, c).imag(); }
701
703 [[nodiscard]] ConstMatrixView real() const {return ConstMatrixView(reinterpret_cast<Numeric *>(mdata), Range(2*mrr.mstart, mrr.mextent, mrr.mstride*2),
705
707 [[nodiscard]] ConstMatrixView imag() const {return ConstMatrixView(reinterpret_cast<Numeric *>(mdata), Range(2*mrr.mstart, mrr.mextent, mrr.mstride*2),
708 Range(2*mcr.mstart + 1, mcr.mextent, mcr.mstride*2));}
709
711 [[nodiscard]] Index get_column_extent() const {return mcr.get_extent();}
712
713 ConstComplexMatrixView operator()(const Range& r, const Range& c) const;
716
717 // Functions returning iterators:
718 [[nodiscard]] ConstComplexIterator2D begin() const;
719 [[nodiscard]] ConstComplexIterator2D end() const;
720
721 // View on diagonal complex vector
722 [[nodiscard]] ConstComplexVectorView diagonal() const;
723
725 virtual ~ConstComplexMatrixView() = default;
726
727 // Friends:
728 friend class ComplexMatrixView;
731 friend void mult(ComplexVectorView,
734 friend void mult(ComplexMatrixView,
737 friend void mult(ComplexMatrixView,
738 const ConstMatrixView&,
740 friend void mult(ComplexMatrixView,
742 const ConstMatrixView&);
743
744 friend std::ostream& operator<<(std::ostream& os, const ConstComplexMatrixView& v);
745
746 [[nodiscard]] Complex* get_c_array() const noexcept {return mdata;}
747
748 protected:
749 // Constructors:
751 ConstComplexMatrixView(Complex* data, const Range& r, const Range& c);
753 const Range& pr,
754 const Range& pc,
755 const Range& nr,
756 const Range& nc);
757
758 // Data members:
759 // -------------
761 Range mrr{0, 0, 1};
763 Range mcr{0, 0, 1};
765 Complex* mdata{nullptr};
766};
767
778 public:
779 // Make const methods visible from base class
782 using ConstComplexMatrixView::operator();
789
790 constexpr ComplexMatrixView(const ComplexMatrixView&) = default;
791
792 // Typedef for compatibility with STL
794
795 // Index Operators:
797 Complex& operator()(Index r, Index c) { // Check if indices are valid:
798 ARTS_ASSERT(0 <= r);
799 ARTS_ASSERT(0 <= c);
802
803 return get(r, c);
804 }
805
808 return *(mdata + mrr.mstart + r * mrr.mstride + mcr.mstart +
809 c * mcr.mstride);
810 }
811
814 return reinterpret_cast<ComplexLayout(&)>(get(r, c)).real;
815 }
816
819 return reinterpret_cast<ComplexLayout(&)>(get(r, c)).imag;
820 }
821
823 MatrixView real() {return MatrixView(reinterpret_cast<Numeric *>(mdata), Range(2*mrr.mstart, mrr.mextent, mrr.mstride*2),
825
827 MatrixView imag() {return MatrixView(reinterpret_cast<Numeric *>(mdata), Range(2*mrr.mstart, mrr.mextent, mrr.mstride*2),
828 Range(2*mcr.mstart + 1, mcr.mextent, mcr.mstride*2));}
829
830 ComplexMatrixView operator()(const Range& r, const Range& c);
833
834 // Functions returning iterators:
837
838 // View on diagonal complex vector
840
841 // Assignment operators:
847
848 // Other operators:
857
862
867
872
874 ~ComplexMatrixView() override = default;
875
876 // Friends:
877 friend class ComplexVectorView;
880
881 protected:
882 // Constructors:
884 ComplexMatrixView(Complex* data, const Range& r, const Range& c);
886 const Range& pr,
887 const Range& pc,
888 const Range& nr,
889 const Range& nc);
890};
891
901 public:
902 // Constructors:
903 ComplexMatrix() = default;
909
912 for (Index i=0; i<nrows(); i++) for (Index j=0; j<ncols(); j++) operator()(i, j) = init(i, j);
913 }
914
915 // Assignment operators:
919
920 // Inverse in place
922
923 // Resize function:
924 void resize(Index r, Index c);
925
926 // Swap function:
927 friend void swap(ComplexMatrix& m1, ComplexMatrix& m2);
928
929 // Destructor:
930 ~ComplexMatrix() override;
931
933};
934
935// Function declarations:
936// ----------------------
937
939
941
942void copy(ConstComplexIterator1D origin,
944 ComplexIterator1D target);
945
946void copy(Complex x, ComplexIterator1D target, const ComplexIterator1D& end);
947
948void copy(ConstComplexIterator2D origin,
950 ComplexIterator2D target);
951
952void copy(Complex x, ComplexIterator2D target, const ComplexIterator2D& end);
953
956 const ConstComplexVectorView& x);
957
959 const ConstComplexMatrixView& B,
960 const ConstComplexMatrixView& C);
962 const ConstMatrixView& B,
963 const ConstComplexMatrixView& C);
965 const ConstComplexMatrixView& B,
966 const ConstMatrixView& C);
968 const ConstMatrixView& B,
969 const ConstMatrixView& C);
970
973
976
977#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/=(Complex x)
Division by scalar.
friend ConstComplexMatrixView transpose(ConstComplexMatrixView m)
Const version of transpose.
ComplexVectorView diagonal()
ComplexMatrix diagonal as vector.
ComplexMatrixView & operator-=(const ConstComplexVectorView &x)
ComplexMatrixView & operator*=(const ConstComplexVectorView &x)
Complex & operator()(Index r, Index c)
Plain index operator.
ComplexMatrixView & operator+=(Complex x)
Addition of scalar.
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() 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.
ComplexMatrixView & operator=(const ConstComplexMatrixView &v)
Assignment operator.
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 & operator-=(Complex x)
Subtraction of scalar.
ComplexMatrixView()
Default constructor.
ComplexMatrixView & operator*=(Complex x)
Multiplication by scalar.
ComplexIterator2D begin()
Return iterator to first row.
The ComplexMatrix class.
ComplexMatrix(const matpack::matrix_like auto &init)
Initialization from a vector type.
Complex * get_raw_data()
void resize(Index r, Index c)
Resize function.
ComplexMatrix & inv(const lapack_help::Inverse< Complex > &help=lapack_help::Inverse< Complex >{0})
~ComplexMatrix() override
Destructor for Matrix.
ComplexMatrix & operator=(ComplexMatrix x)
Assignment operator from another matrix.
ComplexMatrix()=default
friend void swap(ComplexMatrix &m1, ComplexMatrix &m2)
Swaps two objects.
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.
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 & operator=(ComplexVector &&v) noexcept
ComplexVector(Complex *c, const Range &r0) ARTS_NOEXCEPT
void resize(Index n)
Resize function.
ComplexVector & operator=(const ComplexVector &v)
Assignment from another Vector.
~ComplexVector() override
Destructor for ComplexVector.
ComplexVector(const matpack::vector_like auto &init)
Initialization from a vector type.
friend void swap(ComplexVector &v1, ComplexVector &v2)
Swaps two objects.
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
friend ConstComplexMatrixView transpose(ConstComplexMatrixView m)
Const version of transpose.
Index dcols() const noexcept
Complex operator()(Index r, Index c) const
Plain const index operator.
Complex * mdata
Pointer to the plain C array that holds the data.
friend std::ostream & operator<<(std::ostream &os, const ConstComplexMatrixView &v)
Output 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.
friend void mult(ComplexVectorView, const ConstComplexMatrixView &, const ConstComplexVectorView &)
Matrix-Vector Multiplication.
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
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:1043
A constant view of a Vector.
Definition: matpackI.h:512
The Joker class.
Definition: matpackI.h:125
The MatrixView class.
Definition: matpackI.h:1164
The range class.
Definition: matpackI.h:159
Index mstart
The start index.
Definition: matpackI.h:367
constexpr Index get_extent() const noexcept
Returns the extent of the range.
Definition: matpackI.h:342
Index mstride
The stride.
Definition: matpackI.h:372
Index mextent
The number of elements.
Definition: matpackI.h:370
The VectorView class.
Definition: matpackI.h:663
The Vector class.
Definition: matpackI.h:899
A concept for an Arts matrix-like type with access operations.
A concept for an Arts vector-like type with access operations.
#define ARTS_NOEXCEPT
Definition: debug.h:80
#define ARTS_ASSERT(condition,...)
Definition: debug.h:83
Interface for the LAPACK library.
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
#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.
void mult(ComplexVectorView y, const ConstComplexMatrixView &M, const ConstComplexVectorView &x)
Matrix-Vector Multiplication.
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 auto column_size(column_keeper auto &&x)
Get a column size from x.
constexpr auto row_size(row_keeper auto &&x)
Get a row size from x.
constexpr bool isnan(double d) noexcept
Definition: nonstd.h:53
#define M
Definition: rng.cc:165
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