ARTS  2.3.1285(git:92a29ea9-dirty)
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:
221  ConstComplexIterator1D() = default;
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;
271  constexpr ConstComplexVectorView(ConstComplexVectorView&&) = default;
272  ConstComplexVectorView& operator=(const ConstComplexVectorView&) = default;
273  ConstComplexVectorView& operator=(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:
317  ConstComplexIterator1D begin() const;
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:
344  ConstComplexVectorView() = default;
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 
394  Complex& get(Index n) {
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 
414  ComplexVectorView operator[](const Range& r);
415 
416  // ComplexIterators:
417  ComplexIterator1D begin();
419 
420  // Assignment operators:
421  ComplexVectorView& operator=(const ConstComplexVectorView& v);
422  ComplexVectorView& operator=(const ComplexVectorView& v);
423  ComplexVectorView& operator=(const ComplexVector& v);
424  ComplexVectorView& operator=(const Array<Complex>& v);
425  ComplexVectorView& operator=(Complex x);
426  ComplexVectorView& operator=(const ConstVectorView& v);
427  ComplexVectorView& operator=(const VectorView& v);
428  ComplexVectorView& operator=(const Vector& v);
429  ComplexVectorView& operator=(const Array<Numeric>& v);
430  ComplexVectorView& operator=(Numeric x);
431 
432  // Other operators:
433  ComplexVectorView operator*=(Complex x);
434  ComplexVectorView operator/=(Complex x);
436  ComplexVectorView operator-=(Complex x);
437  ComplexVectorView operator*=(Numeric x);
438  ComplexVectorView operator/=(Numeric x);
440  ComplexVectorView operator-=(Numeric x);
441 
442  ComplexVectorView operator*=(const ConstComplexVectorView& x);
443  ComplexVectorView operator/=(const ConstComplexVectorView& x);
445  ComplexVectorView operator-=(const ConstComplexVectorView& x);
446  ComplexVectorView operator*=(const ConstVectorView& x);
447  ComplexVectorView operator/=(const ConstVectorView& x);
449  ComplexVectorView operator-=(const ConstVectorView& x);
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 
507  ComplexVectorView* operator->() { return &msv; }
508 
510  ComplexVectorView& operator*() { return msv; }
511 
512  private:
517 };
518 
523  public:
524  // Constructors:
526  ConstComplexIterator2D() = default;
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);
586  ComplexVector(const Vector& v);
587  ComplexVector(const std::vector<Complex>&);
588  ComplexVector(const std::vector<Numeric>&);
589 
590  // Assignment operators:
591  ComplexVector& operator=(ComplexVector v);
592  ComplexVector& operator=(const Array<Complex>& v);
593  ComplexVector& operator=(Complex x);
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;
621  constexpr ConstComplexMatrixView(ConstComplexMatrixView&&) = default;
622  ConstComplexMatrixView& operator=(const ConstComplexMatrixView&) = default;
623  ConstComplexMatrixView& operator=(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:
672  ConstComplexIterator2D begin() const;
673  ConstComplexIterator2D end() const;
674 
675  // View on diagonal complex vector
676  ConstComplexVectorView diagonal() const;
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:
704  ConstComplexMatrixView() = default;
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 
761  Complex& get(Index r, Index c) {
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);
785  ComplexVectorView operator()(const Range& r, Index c);
786  ComplexVectorView operator()(Index r, const Range& c);
787 
788  // Functions returning iterators:
789  ComplexIterator2D begin();
791 
792  // View on diagonal complex vector
793  ComplexVectorView diagonal();
794 
795  // Assignment operators:
796  ComplexMatrixView& operator=(const ConstComplexMatrixView& v);
797  ComplexMatrixView& operator=(const ComplexMatrixView& v);
798  ComplexMatrixView& operator=(const ComplexMatrix& v);
799  ComplexMatrixView& operator=(const ConstComplexVectorView& v);
800  ComplexMatrixView& operator=(Complex x);
801 
802  // Other operators:
803  ComplexMatrixView& operator*=(Complex x);
804  ComplexMatrixView& operator/=(Complex x);
806  ComplexMatrixView& operator-=(Complex x);
807  ComplexMatrixView& operator*=(Numeric x);
808  ComplexMatrixView& operator/=(Numeric x);
810  ComplexMatrixView& operator-=(Numeric x);
811 
812  ComplexMatrixView& operator*=(const ConstComplexMatrixView& x);
813  ComplexMatrixView& operator/=(const ConstComplexMatrixView& x);
815  ComplexMatrixView& operator-=(const ConstComplexMatrixView& x);
816 
817  ComplexMatrixView& operator*=(const ConstMatrixView& x);
818  ComplexMatrixView& operator/=(const ConstMatrixView& x);
820  ComplexMatrixView& operator-=(const ConstMatrixView& x);
821 
822  ComplexMatrixView& operator*=(const ConstComplexVectorView& x);
823  ComplexMatrixView& operator/=(const ConstComplexVectorView& x);
825  ComplexMatrixView& operator-=(const ConstComplexVectorView& x);
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;
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:
869  ComplexMatrix& operator=(ComplexMatrix x);
870  ComplexMatrix& operator=(Complex x);
871  ComplexMatrix& operator=(const ConstComplexVectorView& v);
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,
902  const ConstComplexIterator2D& end,
903  ComplexIterator2D target);
904 
905 void copy(Complex x, ComplexIterator2D target, const ComplexIterator2D& end);
906 
907 void mult(ComplexVectorView y,
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
Array< ComplexVector > ArrayOfComplexVector
Definition: complex.h:948
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
friend class ComplexMatrixView
Definition: complex.h:463
The VectorView class.
Definition: matpackI.h:610
Complex * mdata
Pointer to the plain C array that holds the data.
Definition: complex.h:353
constexpr Complex operator/(Complex c, Numeric n)
Definition: complex.h:79
Range mrange
The range of mdata that is actually used.
Definition: complex.h:351
const Complex & operator*() const
Dereferencing.
Definition: complex.h:236
ConstComplexIterator1D & operator++()
Prefix increment operator.
Definition: complex.h:230
bool empty() const
Definition: complex.h:279
ComplexIterator2D iterator
Definition: complex.h:747
Numeric & get_imag(Index r, Index c)
Get element implementation without assertions.
Definition: complex.h:772
Index nrows() const
Definition: complex.h:630
ComplexConstMatrixViewMap MapToEigenCol(const ConstComplexVectorView &A)
Definition: complex.cc:1677
Index mstart
The start index.
Definition: matpackI.h:346
ConstMatrixView real() const
Get a view of the real part of the matrix.
Definition: complex.h:657
The Vector class.
Definition: matpackI.h:860
Complex * mx
Current position.
Definition: complex.h:211
The MatrixView class.
Definition: matpackI.h:1093
ComplexVectorView msv
Current position.
Definition: complex.h:514
The constant iterator class for sub vectors.
Definition: complex.h:218
MatrixView real()
Get a view of the real part of the matrix.
Definition: complex.h:777
The range class.
Definition: matpackI.h:160
Complex & operator()(Index r, Index c)
Plain index operator.
Definition: complex.h:751
The ComplexVectorView class.
Definition: complex.h:367
constexpr Complex conj(Complex c)
the conjugate of c
Definition: complex.h:65
ConstComplexIterator1D const_iterator
Definition: complex.h:276
ComplexVectorView * operator->()
The -> operator is needed, so that we can write i->begin() to get the 1D iterators.
Definition: complex.h:507
Eigen::Stride< Eigen::Dynamic, Eigen::Dynamic > ComplexStrideType
Definition: complex.h:168
ComplexIterator1D(Complex *x, Index stride)
Explicit constructor.
Definition: complex.h:182
Numeric & get_imag(Index n)
Get element implementation without assertions.
Definition: complex.h:404
Numeric get_real(Index r, Index c) const
Get element implementation without assertions.
Definition: complex.h:651
friend void copy(ConstComplexIterator1D origin, const ConstComplexIterator1D &end, ComplexIterator1D target)
Copy data between begin and end to target.
Definition: complex.cc:478
G0 G2 FVC Y DV Numeric Numeric Numeric Zeeman LowerQuantumNumbers void * data
bool operator!=(const ConstComplexIterator2D &other) const
Not equal operator, needed for algorithms like copy.
Definition: complex.h:541
ConstMatrixView imag() const
Get a view of the imaginary part of the matrix.
Definition: complex.h:661
const Numeric & get_real(Index n) const
Get element implementation without assertions.
Definition: complex.h:297
constexpr Numeric abs2(Complex c)
squared magnitude of c
Definition: complex.h:62
Complex operator()(Index r, Index c) const
Plain const index operator.
Definition: complex.h:635
#define b2
Definition: complex.h:59
bool operator!=(const ComplexIterator2D &other) const
Not equal operator, needed for algorithms like copy.
Definition: complex.h:497
friend class ConstComplexMatrixView
Definition: complex.h:329
MatrixView imag()
Get a view of the imaginary parts of the matrix.
Definition: complex.h:781
friend class ConstComplexVectorView
Definition: complex.h:683
Array< ComplexMatrix > ArrayOfComplexMatrix
Definition: complex.h:949
void swap(ComplexVector &v1, ComplexVector &v2)
Swaps two objects.
Definition: complex.cc:731
The ComplexMatrix class.
Definition: complex.h:858
bool operator!=(const ComplexIterator1D &other) const
Not equal operator, needed for algorithms like copy.
Definition: complex.h:198
Complex * get_raw_data()
Definition: complex.h:885
friend class ComplexVectorView
Definition: complex.h:835
VectorView imag()
Get a view of the imaginary part of the vector.
Definition: complex.h:412
ConstVectorView imag() const
Get a view of the imaginary part of the vector.
Definition: complex.h:310
The Joker class.
Definition: matpackI.h:126
ConstComplexVectorView diagonal() const
ComplexMatrix diagonal as vector.
Definition: complex.cc:820
Eigen::Map< const ComplexMatrixType, 0, ComplexStrideType > ComplexConstMatrixViewMap
Definition: complex.h:172
ConstComplexVectorView msv
Current position.
Definition: complex.h:558
std::complex< Numeric > Complex
Definition: complex.h:33
const Complex * mx
Current position.
Definition: complex.h:252
Complex & operator*() const
Dereferencing.
Definition: complex.h:195
Struct cannot be const, but can be passed as const to allow defaults.
Definition: lapack.h:23
The iterator class for sub vectors.
Definition: complex.h:176
Index nelem() const
Definition: complex.h:280
Complex & operator[](Index n)
Plain Index operator.
Definition: complex.h:387
Complex * mdata
Pointer to the plain C array that holds the data.
Definition: complex.h:719
ConstComplexMatrixView transpose(ConstComplexMatrixView m)
Const version of transpose.
Definition: complex.cc:1509
The const row iterator class for sub matrices.
Definition: complex.h:522
Complex get(Index r, Index c) const
Get element implementation without assertions.
Definition: complex.h:645
VectorView real()
Get a view of the real part of the vector.
Definition: complex.h:409
Eigen::Map< ComplexMatrixType, 0, ComplexStrideType > ComplexMatrixViewMap
Definition: complex.h:170
#define a1
Definition: complex.h:56
const Complex & get(Index n) const
Get element implementation without assertions.
Definition: complex.h:292
const Joker joker
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:33
Numeric & get_real(Index r, Index c)
Get element implementation without assertions.
Definition: complex.h:767
ConstComplexIterator1D end() const
Return const iterator behind last element.
Definition: complex.cc:83
ConstComplexIterator1D(Complex *x, Index stride)
Explicit constructor.
Definition: complex.h:224
bool empty() const
Definition: complex.h:629
const Complex & operator[](Index n) const
Plain const index operator.
Definition: complex.h:285
Implementation of Matrix, Vector, and such stuff.
The ComplexVector class.
Definition: complex.h:573
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
ComplexIterator1D iterator
Definition: complex.h:384
std::ostream & operator<<(std::ostream &os, const ConstComplexVectorView &v)
Output operator.
Definition: complex.cc:134
This can be used to make arrays out of anything.
Definition: array.h:40
Index mstride
Stride.
Definition: complex.h:213
Index get_column_extent() const
Get the extent of the underlying data.
Definition: complex.h:665
Numeric get_imag(Index r, Index c) const
Get element implementation without assertions.
Definition: complex.h:654
bool operator!=(const ConstComplexIterator1D &other) const
Not equal operator, needed for algorithms like copy.
Definition: complex.h:239
ConstComplexIterator2D end() const
Return const iterator behind last row.
Definition: complex.cc:804
void inv(MatrixView Ainv, ConstMatrixView A)
Matrix Inverse.
Definition: lin_alg.cc:167
ComplexIterator1D & operator++()
Prefix increment operator.
Definition: complex.h:189
ComplexConstMatrixViewMap MapToEigenRow(const ConstComplexVectorView &A)
Definition: complex.cc:1672
ComplexConstMatrixViewMap MapToEigen(const ConstComplexMatrixView &A)
Definition: complex.cc:1655
ConstVectorView real() const
Get a view of the real part of the vector.
Definition: complex.h:307
A constant view of a Vector.
Definition: matpackI.h:476
Index nelem(const Lines &l)
Number of lines.
Eigen::Matrix< Complex, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > ComplexMatrixType
Definition: complex.h:163
#define a2
Definition: complex.h:58
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
std::complex< float > operator*(const double &d, const std::complex< float > &c)
Definition: complex.h:39
ConstComplexIterator2D & operator++()
Prefix increment operator.
Definition: complex.h:535
A constant view of a Matrix.
Definition: matpackI.h:982
ConstComplexIterator2D begin() const
Return const iterator to first row.
Definition: complex.cc:798
A constant view of a ComplexMatrix.
Definition: complex.h:618
Index ncols() const
Definition: complex.h:631
ComplexIterator1D()=default
Default constructor.
A constant view of a ComplexVector.
Definition: complex.h:268
ComplexVectorView & operator*()
Dereferencing.
Definition: complex.h:510
Numeric & get_real(Index n)
Get element implementation without assertions.
Definition: complex.h:399
#define b1
Definition: complex.h:57
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
ComplexIterator2D(const ComplexVectorView &x, Index stride)
Explicit constructor.
Definition: complex.h:485
ComplexIterator2D & operator++()
Prefix increment operator.
Definition: complex.h:491
Interface for the LAPACK library.
#define _complex_operations_(T)
Definition: complex.h:118
void mult(ComplexVectorView y, const ConstComplexMatrixView &M, const ConstComplexVectorView &x)
Matrix-Vector Multiplication.
Definition: complex.cc:1579
ConstComplexIterator2D(const ConstComplexVectorView &x, Index stride)
Explicit constructor.
Definition: complex.h:529
const ConstComplexVectorView & operator*() const
Dereferencing.
Definition: complex.h:554
constexpr Complex operator-(Complex c, Numeric n)
Definition: complex.h:73
ConstComplexIterator1D begin() const
Return const iterator to first element.
Definition: complex.cc:78
ConstComplexIterator2D const_iterator
Definition: complex.h:626
std::complex< float > operator+(const double &d, const std::complex< float > &c)
Definition: complex.h:35
MatrixView & operator+=(MatrixView &A, const Block &B)
The row iterator class for sub matrices.
Definition: complex.h:478
The ComplexMatrixView class.
Definition: complex.h:731
const Numeric & get_imag(Index n) const
Get element implementation without assertions.
Definition: complex.h:302