ARTS  2.4.0(git:4fb77825)
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 complex_h
27 #define complex_h
28 
29 #include <complex>
30 #include "lapack.h"
31 #include "matpackI.h"
32 
33 typedef std::complex<Numeric> Complex;
34 
35 inline std::complex<float> operator+(const double& d,
36  const std::complex<float>& c) {
37  return (float(d) + c);
38 }
39 inline std::complex<float> operator*(const double& d,
40  const std::complex<float>& c) {
41  return (float(d) * c);
42 }
43 
44 inline std::complex<float> operator+(const std::complex<float>& c,
45  const double& d) {
46  return (c + float(d));
47 }
48 inline std::complex<float> operator*(const std::complex<float>& c,
49  const double& d) {
50  return (c * float(d));
51 }
52 
53 // Constexpr versions of common Complex operations
54 
55 // Helpers to keep equations readable
56 #define a1 c.real()
57 #define b1 c.imag()
58 #define a2 z.real()
59 #define b2 z.imag()
60 
62 constexpr Numeric abs2(Complex c) { return a1 * a1 + b1 * b1; }
63 
65 constexpr Complex conj(Complex c) { return Complex(a1, -b1); }
66 
67 // Basic constexpr operations for Complex that don't exist in the standard yet (C++11)
68 // NOTE: Remove these if there is ever an overload warning updating the C++ compiler version
69 
70 constexpr Complex operator+(Complex c, Numeric n) {
71  return Complex(a1 + n, b1);
72 }
73 constexpr Complex operator-(Complex c, Numeric n) {
74  return Complex(a1 - n, b1);
75 }
76 constexpr Complex operator*(Complex c, Numeric n) {
77  return Complex(a1 * n, b1 * n);
78 }
79 constexpr Complex operator/(Complex c, Numeric n) {
80  return Complex(a1 / n, b1 / n);
81 }
82 
83 constexpr Complex operator+(Numeric n, Complex c) {
84  return Complex(n + a1, b1);
85 }
86 constexpr Complex operator-(Numeric n, Complex c) {
87  return Complex(n - a1, -b1);
88 }
89 constexpr Complex operator*(Numeric n, Complex c) {
90  return Complex(n * a1, n * b1);
91 }
92 constexpr Complex operator/(Numeric n, Complex c) {
93  return Complex(n * a1, -n * b1) / abs2(c);
94 }
95 
96 constexpr Complex operator+(Complex c, Complex z) {
97  return Complex(a1 + a2, b1 + b2);
98 }
99 constexpr Complex operator-(Complex c, Complex z) {
100  return Complex(a1 - a2, b1 - b2);
101 }
102 constexpr Complex operator*(Complex c, Complex z) {
103  return Complex(a1 * a2 - b1 * b2, a1 * b2 + b1 * a2);
104 }
105 constexpr Complex operator/(Complex c, Complex z) {
106  return Complex(a1 * a2 + b1 * b2, -a1 * b2 + b1 * a2) / abs2(z);
107 }
108 
109 // Remove helpers to keep global namespace usable
110 #undef a1
111 #undef b1
112 #undef a2
113 #undef b2
114 
115 // Basic constexpr operations for different types since C++11 std::complex is lacking conversions
116 // FIXME: Cannot be template because Eigen interferes, so explicit copies are required for operations
117 // NOTE: Remove these if there is ever an overload warning updating the C++ compiler version
118 #define _complex_operations_(T) \
119  constexpr Complex operator+(Complex c, T x) { \
120  return operator+(c, static_cast<Numeric>(x)); \
121  } \
122  constexpr Complex operator-(Complex c, T x) { \
123  return operator-(c, static_cast<Numeric>(x)); \
124  } \
125  constexpr Complex operator*(Complex c, T x) { \
126  return operator*(c, static_cast<Numeric>(x)); \
127  } \
128  constexpr Complex operator/(Complex c, T x) { \
129  return operator/(c, static_cast<Numeric>(x)); \
130  } \
131  \
132  constexpr Complex operator+(T x, Complex c) { \
133  return operator+(static_cast<Numeric>(x), c); \
134  } \
135  constexpr Complex operator-(T x, Complex c) { \
136  return operator-(static_cast<Numeric>(x), c); \
137  } \
138  constexpr Complex operator*(T x, Complex c) { \
139  return operator*(static_cast<Numeric>(x), c); \
140  } \
141  constexpr Complex operator/(T x, Complex c) { \
142  return operator/(static_cast<Numeric>(x), c); \
143  }
144 
147 
148 #undef _complex_operations_
149 
150  // Declare existence of the global joker object:
151  extern const Joker joker;
152 
153 // Declare the existence of class ConstComplexMatrixView:
155 
156 // Declare the existence of class ComplexVectorView:
157 class ComplexVectorView;
158 
159 // Declare the existence of class ConstComplexVectorView:
161 
162 // Declare the existence of class ConstMatrixView:
164 
165 // Eigen library interactions:
166 typedef Eigen::Matrix<Complex, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>
168 typedef Eigen::Stride<Eigen::Dynamic, Eigen::Dynamic> ComplexStrideType;
169 typedef Eigen::Map<ComplexMatrixType, 0, ComplexStrideType>
171 typedef Eigen::Map<const ComplexMatrixType, 0, ComplexStrideType>
173 
177  public:
179  ComplexIterator1D() = default;
180 
183  : mx(x), mstride(stride) { /* Nothing to do here. */
184  }
185 
186  // Operators:
187 
190  mx += mstride;
191  return *this;
192  }
193 
195  Complex& operator*() const { return *mx; }
196 
198  bool operator!=(const ComplexIterator1D& other) const {
199  if (mx != other.mx)
200  return true;
201  else
202  return false;
203  }
204 
205  friend void copy(ConstComplexIterator1D origin,
207  ComplexIterator1D target);
208 
209  private:
211  Complex* mx{nullptr};
214 };
215 
219  public:
222 
225  : mx(x), mstride(stride) { /* Nothing to do here. */
226  }
227 
228  // Operators:
231  mx += mstride;
232  return *this;
233  }
234 
236  const Complex& operator*() const { return *mx; }
237 
239  bool operator!=(const ConstComplexIterator1D& other) const {
240  if (mx != other.mx)
241  return true;
242  else
243  return false;
244  }
245 
246  friend void copy(ConstComplexIterator1D origin,
248  ComplexIterator1D target);
249 
250  private:
252  const Complex* mx{nullptr};
255 };
256 
257 // Declare the complex vector class:
258 class ComplexVector;
259 
260 // Declare the ComplexMatrixView class
261 class ComplexMatrixView;
262 
269  public:
270  constexpr ConstComplexVectorView(const ConstComplexVectorView&) = default;
274 
275  // Typedef for compatibility with STL
277 
278  // Member functions:
279  bool empty() const { return (nelem() == 0); }
280  Index nelem() const { return mrange.mextent; }
281  Complex sum() const;
282 
283  // Const index operators:
285  const Complex& operator[](Index n) const { // Check if index is valid:
286  assert(0 <= n);
287  assert(n < mrange.mextent);
288  return get(n);
289  }
290 
292  const Complex& get(Index n) const {
293  return *(mdata + mrange.mstart + n * mrange.mstride);
294  }
295 
297  const Numeric& get_real(Index n) const {
298  return reinterpret_cast<const Numeric(&)[2]>(get(n))[0];
299  }
300 
302  const Numeric& get_imag(Index n) const {
303  return reinterpret_cast<const Numeric(&)[2]>(get(n))[1];
304  }
305 
307  ConstVectorView real() const {return ConstVectorView(reinterpret_cast<Numeric *>(mdata), Range(2*mrange.mstart, mrange.mextent, mrange.mstride*2));}
308 
310  ConstVectorView imag() const {return ConstVectorView(reinterpret_cast<Numeric *>(mdata), Range(2*mrange.mstart + 1, mrange.mextent, mrange.mstride*2));}
311 
312  ConstComplexVectorView operator[](const Range& r) const;
313  friend Complex operator*(const ConstComplexVectorView& a,
314  const ConstComplexVectorView& b);
315 
316  // Functions returning iterators:
318  ConstComplexIterator1D end() const;
319 
320  // Conversion to 1 column matrix:
321  operator ConstComplexMatrixView() const;
322 
324  virtual ~ConstComplexVectorView() = default;
325 
326  // Friends:
327  friend class ComplexVectorView;
330  friend void mult(ComplexVectorView,
331  const ConstComplexMatrixView&,
332  const ConstComplexVectorView&);
333 
338 
339  // A special constructor, that allows to make a ConstVectorView of a scalar.
341 
342  protected:
343  // Constructors:
345  ConstComplexVectorView(Complex* data, const Range& range);
346  ConstComplexVectorView(Complex* data, const Range& p, const Range& n);
347 
348  // Data members:
349  // -------------
351  Range mrange{0, 0};
353  Complex* mdata{nullptr};
354 };
355 
368  public:
369  // Make const methods visible from base class
372  using ConstComplexVectorView::operator[];
378 
379  constexpr ComplexVectorView(const ComplexVectorView&) = default;
382 
383  // Typedef for compatibility with STL
385 
387  Complex& operator[](Index n) { // Check if index is valid:
388  assert(0 <= n);
389  assert(n < mrange.mextent);
390  return get(n);
391  }
392 
395  return *(mdata + mrange.mstart + n * mrange.mstride);
396  }
397 
400  return reinterpret_cast<Numeric(&)[2]>(get(n))[0];
401  }
402 
405  return reinterpret_cast<Numeric(&)[2]>(get(n))[1];
406  }
407 
409  VectorView real() {return VectorView(reinterpret_cast<Numeric *>(mdata), Range(2*mrange.mstart, mrange.mextent, mrange.mstride*2));}
410 
412  VectorView imag() {return VectorView(reinterpret_cast<Numeric *>(mdata), Range(2*mrange.mstart + 1, mrange.mextent, mrange.mstride*2));}
413 
415 
416  // ComplexIterators:
419 
420  // Assignment operators:
431 
432  // Other operators:
441 
450 
451  // Conversion to 1 column matrix:
452  operator ComplexMatrixView();
453  // Conversion to a plain C-array
454  const Complex* get_c_array() const;
455  Complex* get_c_array();
456 
458  virtual ~ComplexVectorView() = default;
459 
460  // Friends:
462  friend class ComplexIterator2D;
463  friend class ComplexMatrixView;
464 
465  // A special constructor, that allows to make a ComplexVectorView of a scalar.
467 
468  protected:
469  // Constructors:
470  ComplexVectorView() = default;
471  ComplexVectorView(Complex* data, const Range& range);
472  ComplexVectorView(Complex* data, const Range& p, const Range& n);
473 };
474 
479  public:
480  // Constructors:
482  ComplexIterator2D() = default;
483 
486  : msv(x), mstride(stride) { /* Nothing to do here. */
487  }
488 
489  // Operators:
492  msv.mdata += mstride;
493  return *this;
494  }
495 
497  bool operator!=(const ComplexIterator2D& other) const {
498  if (msv.mdata + msv.mrange.mstart !=
499  other.msv.mdata + other.msv.mrange.mstart)
500  return true;
501  else
502  return false;
503  }
504 
508 
511 
512  private:
517 };
518 
523  public:
524  // Constructors:
527 
530  : msv(x), mstride(stride) { /* Nothing to do here. */
531  }
532 
533  // Operators:
536  msv.mdata += mstride;
537  return *this;
538  }
539 
541  bool operator!=(const ConstComplexIterator2D& other) const {
542  if (msv.mdata + msv.mrange.mstart !=
543  other.msv.mdata + other.msv.mrange.mstart)
544  return true;
545  else
546  return false;
547  }
548 
551  const ConstComplexVectorView* operator->() const { return &msv; }
552 
554  const ConstComplexVectorView& operator*() const { return msv; }
555 
556  private:
561 };
562 
574  public:
575  // Constructors:
576  ComplexVector();
577  explicit ComplexVector(Index n);
578  ComplexVector(Index n, Complex fill);
579  ComplexVector(Index n, Numeric fill);
580  ComplexVector(Complex start, Index extent, Complex stride);
581  ComplexVector(Complex start, Index extent, Numeric stride);
582  ComplexVector(Numeric start, Index extent, Complex stride);
583  ComplexVector(Numeric start, Index extent, Numeric stride);
585  ComplexVector(const ComplexVector& v);
587  ComplexVector(const std::vector<Complex>&);
588  ComplexVector(const std::vector<Numeric>&);
589 
590  // Assignment operators:
594 
595  // Resize function:
596  void resize(Index n);
597 
598  // Swap function:
599  friend void swap(ComplexVector& v1, ComplexVector& v2);
600 
601  // Destructor:
602  virtual ~ComplexVector();
603 };
604 
605 // Declare class ComplexMatrix:
606 class ComplexMatrix;
607 
619  public:
620  constexpr ConstComplexMatrixView(const ConstComplexMatrixView&) = default;
624 
625  // Typedef for compatibility with STL
627 
628  // Member functions:
629  bool empty() const { return not nrows() or not ncols(); }
630  Index nrows() const { return mrr.mextent; }
631  Index ncols() const { return mcr.mextent; }
632 
633  // Const index operators:
635  Complex operator()(Index r, Index c) const { // Check if indices are valid:
636  assert(0 <= r);
637  assert(0 <= c);
638  assert(r < mrr.mextent);
639  assert(c < mcr.mextent);
640 
641  return get(r, c);
642  }
643 
645  Complex get(Index r, Index c) const {
646  return *(mdata + mrr.mstart + r * mrr.mstride + mcr.mstart +
647  c * mcr.mstride);
648  }
649 
651  Numeric get_real(Index r, Index c) const { return get(r, c).real(); }
652 
654  Numeric get_imag(Index r, Index c) const { return get(r, c).imag(); }
655 
657  ConstMatrixView real() const {return ConstMatrixView(reinterpret_cast<Numeric *>(mdata), Range(2*mrr.mstart, mrr.mextent, mrr.mstride*2),
658  Range(2*mcr.mstart, mcr.mextent, mcr.mstride*2));}
659 
661  ConstMatrixView imag() const {return ConstMatrixView(reinterpret_cast<Numeric *>(mdata), Range(2*mrr.mstart, mrr.mextent, mrr.mstride*2),
662  Range(2*mcr.mstart + 1, mcr.mextent, mcr.mstride*2));}
663 
665  Index get_column_extent() const {return mcr.get_extent();}
666 
667  ConstComplexMatrixView operator()(const Range& r, const Range& c) const;
668  ConstComplexVectorView operator()(const Range& r, Index c) const;
669  ConstComplexVectorView operator()(Index r, const Range& c) const;
670 
671  // Functions returning iterators:
673  ConstComplexIterator2D end() const;
674 
675  // View on diagonal complex vector
677 
679  virtual ~ConstComplexMatrixView() = default;
680 
681  // Friends:
682  friend class ComplexMatrixView;
685  friend void mult(ComplexVectorView,
686  const ConstComplexMatrixView&,
687  const ConstComplexVectorView&);
688  friend void mult(ComplexMatrixView,
689  const ConstComplexMatrixView&,
690  const ConstComplexMatrixView&);
691  friend void mult(ComplexMatrixView,
692  const ConstMatrixView&,
693  const ConstComplexMatrixView&);
694  friend void mult(ComplexMatrixView,
695  const ConstComplexMatrixView&,
696  const ConstMatrixView&);
697 
698 
701 
702  protected:
703  // Constructors:
705  ConstComplexMatrixView(Complex* data, const Range& r, const Range& c);
707  const Range& pr,
708  const Range& pc,
709  const Range& nr,
710  const Range& nc);
711 
712  // Data members:
713  // -------------
715  Range mrr{0, 0, 1};
717  Range mcr{0, 0, 1};
719  Complex* mdata{nullptr};
720 };
721 
732  public:
733  // Make const methods visible from base class
736  using ConstComplexMatrixView::operator();
743 
744  constexpr ComplexMatrixView(const ComplexMatrixView&) = default;
745 
746  // Typedef for compatibility with STL
748 
749  // Index Operators:
751  Complex& operator()(Index r, Index c) { // Check if indices are valid:
752  assert(0 <= r);
753  assert(0 <= c);
754  assert(r < mrr.mextent);
755  assert(c < mcr.mextent);
756 
757  return get(r, c);
758  }
759 
762  return *(mdata + mrr.mstart + r * mrr.mstride + mcr.mstart +
763  c * mcr.mstride);
764  }
765 
768  return reinterpret_cast<Numeric(&)[2]>(get(r, c))[0];
769  }
770 
773  return reinterpret_cast<Numeric(&)[2]>(get(r, c))[1];
774  }
775 
777  MatrixView real() {return MatrixView(reinterpret_cast<Numeric *>(mdata), Range(2*mrr.mstart, mrr.mextent, mrr.mstride*2),
778  Range(2*mcr.mstart, mcr.mextent, mcr.mstride*2));}
779 
781  MatrixView imag() {return MatrixView(reinterpret_cast<Numeric *>(mdata), Range(2*mrr.mstart, mrr.mextent, mrr.mstride*2),
782  Range(2*mcr.mstart + 1, mcr.mextent, mcr.mstride*2));}
783 
784  ComplexMatrixView operator()(const Range& r, const Range& c);
787 
788  // Functions returning iterators:
791 
792  // View on diagonal complex vector
794 
795  // Assignment operators:
801 
802  // Other operators:
811 
816 
821 
826 
827  // Conversion to a plain C-array
828  const Complex* get_c_array() const;
829  Complex* get_c_array();
830 
832  virtual ~ComplexMatrixView() = default;
833 
834  // Friends:
835  friend class ComplexVectorView;
838 
839  protected:
840  // Constructors:
842  ComplexMatrixView(Complex* data, const Range& r, const Range& c);
844  const Range& pr,
845  const Range& pc,
846  const Range& nr,
847  const Range& nc);
848 };
849 
859  public:
860  // Constructors:
861  ComplexMatrix() = default;
862  ComplexMatrix(Index r, Index c);
863  ComplexMatrix(Index r, Index c, Complex fill);
864  ComplexMatrix(Index r, Index c, Numeric fill);
866  ComplexMatrix(const ComplexMatrix& v);
867 
868  // Assignment operators:
872 
873  // Inverse in place
875 
876  // Resize function:
877  void resize(Index r, Index c);
878 
879  // Swap function:
880  friend void swap(ComplexMatrix& m1, ComplexMatrix& m2);
881 
882  // Destructor:
883  virtual ~ComplexMatrix();
884 
885  Complex* get_raw_data() { return mdata; }
886 };
887 
888 // Function declarations:
889 // ----------------------
890 
892 
894 
895 void copy(ConstComplexIterator1D origin,
897  ComplexIterator1D target);
898 
899 void copy(Complex x, ComplexIterator1D target, const ComplexIterator1D& end);
900 
901 void copy(ConstComplexIterator2D origin,
903  ComplexIterator2D target);
904 
905 void copy(Complex x, ComplexIterator2D target, const ComplexIterator2D& end);
906 
908  const ConstComplexMatrixView& M,
909  const ConstComplexVectorView& x);
910 
911 void mult(ComplexMatrixView A,
912  const ConstComplexMatrixView& B,
913  const ConstComplexMatrixView& C);
914 void mult(ComplexMatrixView A,
915  const ConstMatrixView& B,
916  const ConstComplexMatrixView& C);
917 void mult(ComplexMatrixView A,
918  const ConstComplexMatrixView& B,
919  const ConstMatrixView& C);
920 void mult(ComplexMatrixView A,
921  const ConstMatrixView& B,
922  const ConstMatrixView& C);
923 
925  const ConstComplexVectorView& b);
926 
927 std::ostream& operator<<(std::ostream& os, const ConstComplexVectorView& v);
928 
929 std::ostream& operator<<(std::ostream& os, const ConstComplexMatrixView& v);
930 
931 // Converts constant matrix to constant eigen map
933 // Converts constant vector to constant eigen row-view
935 // Converts constant vector to constant eigen row-view
937 // Converts constant vector to constant eigen column-view
939 // Converts matrix to eigen map
941 // Converts vector to eigen map row-view
943 // Converts vector to eigen map row-view
945 // Converts vector to eigen map column-view
947 
950 
951 #endif
ComplexIterator1D::operator++
ComplexIterator1D & operator++()
Prefix increment operator.
Definition: complex.h:189
ComplexVectorView::ComplexVectorView
constexpr ComplexVectorView(const ComplexVectorView &)=default
ComplexMatrixView::operator+=
ComplexMatrixView & operator+=(const ConstComplexVectorView &x)
ComplexVectorView::get_real
Numeric & get_real(Index n)
Get element implementation without assertions.
Definition: complex.h:399
MatrixView
The MatrixView class.
Definition: matpackI.h:1093
ComplexMatrix::swap
friend void swap(ComplexMatrix &m1, ComplexMatrix &m2)
Swaps two objects.
Definition: complex.cc:1474
ComplexVectorView::operator=
ComplexVectorView & operator=(const Vector &v)
ComplexMatrixView::real
MatrixView real()
Get a view of the real part of the matrix.
Definition: complex.h:777
ComplexVectorView::get_c_array
const Complex * get_c_array() const
Conversion to plain C-array.
Definition: complex.cc:421
ComplexVectorView::operator=
ComplexVectorView & operator=(const VectorView &v)
lapack.h
Interface for the LAPACK library.
ComplexVectorView::ComplexVectorView
ComplexVectorView()=default
conj
constexpr Complex conj(Complex c)
the conjugate of c
Definition: complex.h:65
ConstComplexMatrixView::begin
ConstComplexIterator2D begin() const
Return const iterator to first row.
Definition: complex.cc:798
ComplexStrideType
Eigen::Stride< Eigen::Dynamic, Eigen::Dynamic > ComplexStrideType
Definition: complex.h:168
ComplexVectorView::get_imag
Numeric & get_imag(Index n)
Get element implementation without assertions.
Definition: complex.h:404
ComplexMatrixView::transpose
friend ConstComplexMatrixView transpose(ConstComplexMatrixView m)
Const version of transpose.
Definition: complex.cc:1509
ConstComplexMatrixView::get_imag
Numeric get_imag(Index r, Index c) const
Get element implementation without assertions.
Definition: complex.h:654
ComplexMatrix::~ComplexMatrix
virtual ~ComplexMatrix()
Destructor for Matrix.
Definition: complex.cc:1482
ConstComplexIterator2D
The const row iterator class for sub matrices.
Definition: complex.h:522
joker
const Joker joker
ComplexIterator2D::operator*
ComplexVectorView & operator*()
Dereferencing.
Definition: complex.h:510
ComplexIterator2D::operator++
ComplexIterator2D & operator++()
Prefix increment operator.
Definition: complex.h:491
ConstComplexIterator1D::ConstComplexIterator1D
ConstComplexIterator1D(Complex *x, Index stride)
Explicit constructor.
Definition: complex.h:224
ConstComplexVectorView::nelem
Index nelem() const
Definition: complex.h:280
ComplexVector
The ComplexVector class.
Definition: complex.h:573
ConstComplexVectorView::operator=
ConstComplexVectorView & operator=(const ConstComplexVectorView &)=default
ConstComplexMatrixView::const_iterator
ConstComplexIterator2D const_iterator
Definition: complex.h:626
ConstComplexVectorView::ConstComplexVectorView
constexpr ConstComplexVectorView(const ConstComplexVectorView &)=default
ConstComplexIterator1D::operator!=
bool operator!=(const ConstComplexIterator1D &other) const
Not equal operator, needed for algorithms like copy.
Definition: complex.h:239
ComplexVectorView::operator=
ComplexVectorView & operator=(const ConstVectorView &v)
ConstComplexIterator2D::operator->
const ConstComplexVectorView * operator->() const
The -> operator is needed, so that we can write i->begin() to get t he 1D iterators.
Definition: complex.h:551
ConstComplexVectorView::const_iterator
ConstComplexIterator1D const_iterator
Definition: complex.h:276
ARTS::Var::y
Vector y(Workspace &ws) noexcept
Definition: autoarts.h:7401
ConstComplexMatrixView::MapToEigen
friend ComplexConstMatrixViewMap MapToEigen(const ConstComplexMatrixView &)
Definition: complex.cc:1655
ComplexIterator1D::operator*
Complex & operator*() const
Dereferencing.
Definition: complex.h:195
ComplexVector::~ComplexVector
virtual ~ComplexVector()
Destructor for ComplexVector.
Definition: complex.cc:738
ConstComplexIterator2D::operator++
ConstComplexIterator2D & operator++()
Prefix increment operator.
Definition: complex.h:535
ConstComplexVectorView::get_imag
const Numeric & get_imag(Index n) const
Get element implementation without assertions.
Definition: complex.h:302
data
G0 G2 FVC Y DV Numeric Numeric Numeric Zeeman LowerQuantumNumbers void * data
Definition: arts_api_classes.cc:232
ComplexVectorView::end
ComplexIterator1D end()
Return iterator behind last element.
Definition: complex.cc:183
ComplexMatrixView::ComplexMatrixView
ComplexMatrixView()
Default constructor.
Definition: complex.cc:1270
ComplexVectorView::operator[]
Complex & operator[](Index n)
Plain Index operator.
Definition: complex.h:387
ComplexVector::operator=
ComplexVector & operator=(ComplexVector v)
Assignment from another Vector.
Definition: complex.cc:670
ComplexIterator1D::operator!=
bool operator!=(const ComplexIterator1D &other) const
Not equal operator, needed for algorithms like copy.
Definition: complex.h:198
ComplexVectorView::ComplexMatrixView
friend class ComplexMatrixView
Definition: complex.h:463
Range::mstart
Index mstart
The start index.
Definition: matpackI.h:346
ComplexMatrixView::get_c_array
const Complex * get_c_array() const
Conversion to plain C-array.
Definition: complex.cc:1112
ConstComplexMatrixView::ConstComplexMatrixView
ConstComplexMatrixView()=default
b2
#define b2
Definition: complex.h:59
Complex
std::complex< Numeric > Complex
Definition: complex.h:33
ConstComplexVectorView::ConstComplexVectorView
constexpr ConstComplexVectorView(ConstComplexVectorView &&)=default
ConstComplexVectorView::empty
bool empty() const
Definition: complex.h:279
ComplexIterator2D::msv
ComplexVectorView msv
Current position.
Definition: complex.h:514
ComplexVectorView::get
const Complex & get(Index n) const
Get element implementation without assertions.
Definition: complex.h:292
ComplexVectorView::operator-=
ComplexVectorView operator-=(Complex x)
Subtraction of scalar.
Definition: complex.cc:284
ComplexMatrixView::operator/=
ComplexMatrixView & operator/=(const ConstComplexVectorView &x)
ArrayOfComplexMatrix
Array< ComplexMatrix > ArrayOfComplexMatrix
Definition: complex.h:949
ComplexMatrixView::get_real
Numeric & get_real(Index r, Index c)
Get element implementation without assertions.
Definition: complex.h:767
ComplexVectorView::operator*=
ComplexVectorView operator*=(Complex x)
Multiplication by scalar.
Definition: complex.cc:242
ConstComplexIterator1D::mstride
Index mstride
Stride.
Definition: complex.h:254
matpackI.h
Implementation of Matrix, Vector, and such stuff.
ConstComplexMatrixView::nrows
Index nrows() const
Definition: complex.h:630
ConstComplexIterator2D::operator*
const ConstComplexVectorView & operator*() const
Dereferencing.
Definition: complex.h:554
ComplexMatrixView::operator=
ComplexMatrixView & operator=(const ConstComplexMatrixView &v)
Assignment operator.
Definition: complex.cc:968
Array
This can be used to make arrays out of anything.
Definition: array.h:108
ComplexMatrixView::operator+=
ComplexMatrixView & operator+=(Complex x)
Addition of scalar.
Definition: complex.cc:1067
ConstComplexVectorView::MapToEigen
friend ComplexConstMatrixViewMap MapToEigen(const ConstComplexVectorView &)
Definition: complex.cc:1664
ComplexVectorView::~ComplexVectorView
virtual ~ComplexVectorView()=default
Destructor.
copy
void copy(ConstComplexIterator1D origin, const ConstComplexIterator1D &end, ComplexIterator1D target)
Copy data between begin and end to target.
Definition: complex.cc:478
ComplexIterator1D::copy
friend void copy(ConstComplexIterator1D origin, const ConstComplexIterator1D &end, ComplexIterator1D target)
Copy data between begin and end to target.
Definition: complex.cc:478
ConstComplexMatrixView::end
ConstComplexIterator2D end() const
Return const iterator behind last row.
Definition: complex.cc:804
ConstComplexMatrixView::mcr
Range mcr
The column range of mdata that is actually used.
Definition: complex.h:717
ComplexVectorView::operator+=
ComplexVectorView operator+=(Complex x)
Addition of scalar.
Definition: complex.cc:270
ConstComplexMatrixView::get_column_extent
Index get_column_extent() const
Get the extent of the underlying data.
Definition: complex.h:665
ComplexIterator2D
The row iterator class for sub matrices.
Definition: complex.h:478
ComplexMatrixView::ComplexMatrixView
constexpr ComplexMatrixView(const ComplexMatrixView &)=default
ComplexMatrix::get_raw_data
Complex * get_raw_data()
Definition: complex.h:885
ConstComplexIterator1D::ConstComplexIterator1D
ConstComplexIterator1D()=default
Default constructor.
ConstComplexIterator2D::ConstComplexIterator2D
ConstComplexIterator2D(const ConstComplexVectorView &x, Index stride)
Explicit constructor.
Definition: complex.h:529
abs2
constexpr Numeric abs2(Complex c)
squared magnitude of c
Definition: complex.h:62
ComplexMatrixView::operator()
Complex & operator()(Index r, Index c)
Plain index operator.
Definition: complex.h:751
ConstComplexMatrixView::transpose
friend ConstComplexMatrixView transpose(ConstComplexMatrixView m)
Const version of transpose.
Definition: complex.cc:1509
ComplexMatrixView::begin
ComplexIterator2D begin()
Return iterator to first row.
Definition: complex.cc:937
ConstComplexMatrixView::ncols
Index ncols() const
Definition: complex.h:631
VectorView
The VectorView class.
Definition: matpackI.h:610
ComplexIterator1D::ComplexIterator1D
ComplexIterator1D(Complex *x, Index stride)
Explicit constructor.
Definition: complex.h:182
ComplexMatrixView::operator-=
ComplexMatrixView & operator-=(const ConstComplexVectorView &x)
ConstComplexVectorView::ConstComplexVectorView
ConstComplexVectorView()=default
ConstComplexIterator1D::operator++
ConstComplexIterator1D & operator++()
Prefix increment operator.
Definition: complex.h:230
ComplexMatrixViewMap
Eigen::Map< ComplexMatrixType, 0, ComplexStrideType > ComplexMatrixViewMap
Definition: complex.h:170
ComplexMatrix
The ComplexMatrix class.
Definition: complex.h:858
ConstComplexMatrixView::mult
friend void mult(ComplexVectorView, const ConstComplexMatrixView &, const ConstComplexVectorView &)
Matrix-Vector Multiplication.
Definition: complex.cc:1579
Numeric
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:33
ComplexMatrixView::~ComplexMatrixView
virtual ~ComplexMatrixView()=default
Destructor.
ComplexIterator2D::ComplexIterator2D
ComplexIterator2D()=default
Default constructor.
ConstComplexVectorView::mult
friend void mult(ComplexVectorView, const ConstComplexMatrixView &, const ConstComplexVectorView &)
Matrix-Vector Multiplication.
Definition: complex.cc:1579
ComplexMatrix::ComplexMatrix
ComplexMatrix()=default
ComplexVector::ComplexVector
ComplexVector(const Vector &v)
ConstComplexVectorView::get_real
const Numeric & get_real(Index n) const
Get element implementation without assertions.
Definition: complex.h:297
ComplexVectorView::imag
VectorView imag()
Get a view of the imaginary part of the vector.
Definition: complex.h:412
transpose
ConstComplexMatrixView transpose(ConstComplexMatrixView m)
Const version of transpose.
Definition: complex.cc:1509
ComplexVectorView::operator=
ComplexVectorView & operator=(const ConstComplexVectorView &v)
Assignment operator.
Definition: complex.cc:193
ConstComplexIterator1D::operator*
const Complex & operator*() const
Dereferencing.
Definition: complex.h:236
ComplexIterator2D::operator!=
bool operator!=(const ComplexIterator2D &other) const
Not equal operator, needed for algorithms like copy.
Definition: complex.h:497
ComplexVectorView::get
Complex & get(Index n)
Get element implementation without assertions.
Definition: complex.h:394
ComplexConstMatrixViewMap
Eigen::Map< const ComplexMatrixType, 0, ComplexStrideType > ComplexConstMatrixViewMap
Definition: complex.h:172
ConstComplexMatrixView::~ConstComplexMatrixView
virtual ~ConstComplexMatrixView()=default
Destructor.
ConstComplexVectorView
A constant view of a ComplexVector.
Definition: complex.h:268
ConstComplexVectorView::ConstComplexMatrixView
friend class ConstComplexMatrixView
Definition: complex.h:329
operator<<
std::ostream & operator<<(std::ostream &os, const ConstComplexVectorView &v)
Output operator.
Definition: complex.cc:134
ComplexMatrixView::imag
MatrixView imag()
Get a view of the imaginary parts of the matrix.
Definition: complex.h:781
a1
#define a1
Definition: complex.h:56
Zeeman::end
constexpr Rational end(Rational Ju, Rational Jl, Polarization type) noexcept
Gives the largest M for a polarization type of this transition.
Definition: zeemandata.h:108
ConstComplexVectorView::~ConstComplexVectorView
virtual ~ConstComplexVectorView()=default
Destructor.
ComplexVector::resize
void resize(Index n)
Resize function.
Definition: complex.cc:719
ComplexIterator2D::ComplexIterator2D
ComplexIterator2D(const ComplexVectorView &x, Index stride)
Explicit constructor.
Definition: complex.h:485
operator*
std::complex< float > operator*(const double &d, const std::complex< float > &c)
Definition: complex.h:39
ConstMatrixView
A constant view of a Matrix.
Definition: matpackI.h:982
Range::get_extent
constexpr Index get_extent() const
Returns the extent of the range.
Definition: matpackI.h:329
ConstComplexVectorView::operator[]
const Complex & operator[](Index n) const
Plain const index operator.
Definition: complex.h:285
ConstComplexMatrixView::mrr
Range mrr
The row range of mdata that is actually used.
Definition: complex.h:715
ComplexVectorView::operator=
ComplexVectorView & operator=(Numeric x)
ConstComplexVectorView::mdata
Complex * mdata
Pointer to the plain C array that holds the data.
Definition: complex.h:353
ComplexVectorView::begin
ComplexIterator1D begin()
Return iterator to first element.
Definition: complex.cc:178
ComplexMatrixView
The ComplexMatrixView class.
Definition: complex.h:731
Range
The range class.
Definition: matpackI.h:160
ConstComplexMatrixView::diagonal
ConstComplexVectorView diagonal() const
ComplexMatrix diagonal as vector.
Definition: complex.cc:820
ComplexIterator1D::ComplexIterator1D
ComplexIterator1D()=default
Default constructor.
ComplexVector::swap
friend void swap(ComplexVector &v1, ComplexVector &v2)
Swaps two objects.
Definition: complex.cc:731
ConstComplexVectorView::mrange
Range mrange
The range of mdata that is actually used.
Definition: complex.h:351
Range::mextent
Index mextent
The number of elements.
Definition: matpackI.h:353
ComplexMatrix::operator=
ComplexMatrix & operator=(ComplexMatrix x)
Assignment operator from another matrix.
Definition: complex.cc:1420
ComplexMatrixView::operator*=
ComplexMatrixView & operator*=(Complex x)
Multiplication by scalar.
Definition: complex.cc:1027
ComplexVectorView::operator=
ComplexVectorView & operator=(const Array< Numeric > &v)
ConstComplexVectorView::end
ConstComplexIterator1D end() const
Return const iterator behind last element.
Definition: complex.cc:83
ConstComplexVectorView::real
ConstVectorView real() const
Get a view of the real part of the vector.
Definition: complex.h:307
ConstComplexMatrixView::operator=
ConstComplexMatrixView & operator=(ConstComplexMatrixView &&)=default
Zeeman::start
constexpr Rational start(Rational Ju, Rational Jl, Polarization type) noexcept
Gives the lowest M for a polarization type of this transition.
Definition: zeemandata.h:77
Joker
The Joker class.
Definition: matpackI.h:126
ComplexMatrixView::end
ComplexIterator2D end()
Return iterator behind last row.
Definition: complex.cc:943
ComplexMatrixView::diagonal
ComplexVectorView diagonal()
ComplexMatrix diagonal as vector.
Definition: complex.cc:958
ConstComplexIterator2D::ConstComplexIterator2D
ConstComplexIterator2D()=default
Default constructor.
ConstComplexMatrixView::ConstComplexMatrixView
constexpr ConstComplexMatrixView(ConstComplexMatrixView &&)=default
ConstComplexIterator1D
The constant iterator class for sub vectors.
Definition: complex.h:218
ConstComplexVectorView::operator*
friend Complex operator*(const ConstComplexVectorView &a, const ConstComplexVectorView &b)
Scalar product.
Definition: complex.cc:1554
ComplexMatrixView::get
Complex get(Index r, Index c) const
Get element implementation without assertions.
Definition: complex.h:645
ComplexIterator2D::mstride
Index mstride
Row stride.
Definition: complex.h:516
ComplexVector::ComplexVector
ComplexVector()
Default constructor.
Definition: complex.cc:498
ConstComplexMatrixView::operator=
ConstComplexMatrixView & operator=(const ConstComplexMatrixView &)=default
operator+
std::complex< float > operator+(const double &d, const std::complex< float > &c)
Definition: complex.h:35
ConstComplexVectorView::imag
ConstVectorView imag() const
Get a view of the imaginary part of the vector.
Definition: complex.h:310
ConstComplexMatrixView::get
Complex get(Index r, Index c) const
Get element implementation without assertions.
Definition: complex.h:645
ConstComplexIterator2D::mstride
Index mstride
Row stride.
Definition: complex.h:560
ConstComplexMatrixView::mdata
Complex * mdata
Pointer to the plain C array that holds the data.
Definition: complex.h:719
ConstComplexMatrixView
A constant view of a ComplexMatrix.
Definition: complex.h:618
ConstComplexVectorView::begin
ConstComplexIterator1D begin() const
Return const iterator to first element.
Definition: complex.cc:78
ComplexMatrixView::iterator
ComplexIterator2D iterator
Definition: complex.h:747
ConstComplexVectorView::sum
Complex sum() const
Returns true if variable size is zero.
Definition: complex.cc:59
ComplexVectorView::real
VectorView real()
Get a view of the real part of the vector.
Definition: complex.h:409
ConstComplexIterator1D::copy
friend void copy(ConstComplexIterator1D origin, const ConstComplexIterator1D &end, ComplexIterator1D target)
Copy data between begin and end to target.
Definition: complex.cc:478
ComplexMatrixView::get
Complex & get(Index r, Index c)
Get element implementation without assertions.
Definition: complex.h:761
ComplexMatrixView::operator*=
ComplexMatrixView & operator*=(const ConstComplexVectorView &x)
ArrayOfComplexVector
Array< ComplexVector > ArrayOfComplexVector
Definition: complex.h:948
ComplexMatrixType
Eigen::Matrix< Complex, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > ComplexMatrixType
Definition: complex.h:163
ConstComplexVectorView::MapToEigenCol
friend ComplexConstMatrixViewMap MapToEigenCol(const ConstComplexVectorView &)
Definition: complex.cc:1677
a2
#define a2
Definition: complex.h:58
ARTS::Var::x
Vector x(Workspace &ws) noexcept
Definition: autoarts.h:7346
Index
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
ConstComplexMatrixView::real
ConstMatrixView real() const
Get a view of the real part of the matrix.
Definition: complex.h:657
ConstComplexIterator2D::operator!=
bool operator!=(const ConstComplexIterator2D &other) const
Not equal operator, needed for algorithms like copy.
Definition: complex.h:541
ConstComplexMatrixView::ConstComplexMatrixView
constexpr ConstComplexMatrixView(const ConstComplexMatrixView &)=default
operator-
constexpr Complex operator-(Complex c, Numeric n)
Definition: complex.h:73
ComplexIterator1D::mx
Complex * mx
Current position.
Definition: complex.h:211
M
#define M
Definition: rng.cc:165
ConstComplexVectorView::operator=
ConstComplexVectorView & operator=(ConstComplexVectorView &&)=default
ConstComplexIterator2D::msv
ConstComplexVectorView msv
Current position.
Definition: complex.h:558
Vector
The Vector class.
Definition: matpackI.h:860
MapToEigen
ComplexConstMatrixViewMap MapToEigen(const ConstComplexMatrixView &A)
Definition: complex.cc:1655
MapToEigenRow
ComplexConstMatrixViewMap MapToEigenRow(const ConstComplexVectorView &A)
Definition: complex.cc:1672
ConstComplexIterator1D::mx
const Complex * mx
Current position.
Definition: complex.h:252
Range::mstride
Index mstride
The stride.
Definition: matpackI.h:355
ConstVectorView
A constant view of a Vector.
Definition: matpackI.h:476
ConstComplexMatrixView::get_real
Numeric get_real(Index r, Index c) const
Get element implementation without assertions.
Definition: complex.h:651
ComplexVectorView::iterator
ComplexIterator1D iterator
Definition: complex.h:384
ConstComplexMatrixView::imag
ConstMatrixView imag() const
Get a view of the imaginary part of the matrix.
Definition: complex.h:661
ComplexVectorView
The ComplexVectorView class.
Definition: complex.h:367
b1
#define b1
Definition: complex.h:57
ComplexVectorView::operator/=
ComplexVectorView operator/=(Complex x)
Division by scalar.
Definition: complex.cc:256
ConstComplexVectorView::get
const Complex & get(Index n) const
Get element implementation without assertions.
Definition: complex.h:292
ComplexMatrixView::operator/=
ComplexMatrixView & operator/=(Complex x)
Division by scalar.
Definition: complex.cc:1047
ComplexMatrixView::get_imag
Numeric & get_imag(Index r, Index c)
Get element implementation without assertions.
Definition: complex.h:772
ComplexIterator1D::mstride
Index mstride
Stride.
Definition: complex.h:213
ComplexMatrix::resize
void resize(Index r, Index c)
Resize function.
Definition: complex.cc:1455
MapToEigenCol
ComplexConstMatrixViewMap MapToEigenCol(const ConstComplexVectorView &A)
Definition: complex.cc:1677
ComplexMatrixView::operator-=
ComplexMatrixView & operator-=(Complex x)
Subtraction of scalar.
Definition: complex.cc:1087
_complex_operations_
#define _complex_operations_(T)
Definition: complex.h:118
ConstComplexMatrixView::operator()
Complex operator()(Index r, Index c) const
Plain const index operator.
Definition: complex.h:635
mult
void mult(ComplexVectorView y, const ConstComplexMatrixView &M, const ConstComplexVectorView &x)
Matrix-Vector Multiplication.
Definition: complex.cc:1579
lapack_help::Inverse
Struct cannot be const, but can be passed as const to allow defaults.
Definition: lapack.h:23
operator/
constexpr Complex operator/(Complex c, Numeric n)
Definition: complex.h:79
ComplexIterator1D
The iterator class for sub vectors.
Definition: complex.h:176
ComplexIterator2D::operator->
ComplexVectorView * operator->()
The -> operator is needed, so that we can write i->begin() to get the 1D iterators.
Definition: complex.h:507
ComplexMatrix::inv
ComplexMatrix & inv(const lapack_help::Inverse< Complex > &help=lapack_help::Inverse< Complex >{0})
Definition: complex.cc:1488
ConstComplexMatrixView::empty
bool empty() const
Definition: complex.h:629