26#ifndef matpack_complex_h
27#define matpack_complex_h
51 const std::complex<float>&
c) {
52 return (
float(
d) +
c);
55 const std::complex<float>&
c) {
56 return (
float(
d) *
c);
59inline std::complex<float>
operator+(
const std::complex<float>&
c,
61 return (
c +
float(
d));
63inline std::complex<float>
operator*(
const std::complex<float>&
c,
65 return (
c *
float(
d));
140#define _complex_operations_(T) \
141 constexpr Complex operator+(Complex c, T x) noexcept { \
142 return operator+(c, static_cast<Numeric>(x)); \
144 constexpr Complex operator-(Complex c, T x) noexcept { \
145 return operator-(c, static_cast<Numeric>(x)); \
147 constexpr Complex operator*(Complex c, T x) noexcept { \
148 return operator*(c, static_cast<Numeric>(x)); \
150 constexpr Complex operator/(Complex c, T x) noexcept { \
151 return operator/(c, static_cast<Numeric>(x)); \
154 constexpr Complex operator+(T x, Complex c) noexcept { \
155 return operator+(static_cast<Numeric>(x), c); \
157 constexpr Complex operator-(T x, Complex c) noexcept { \
158 return operator-(static_cast<Numeric>(x), c); \
160 constexpr Complex operator*(T x, Complex c) noexcept { \
161 return operator*(static_cast<Numeric>(x), c); \
163 constexpr Complex operator/(T x, Complex c) noexcept { \
164 return operator/(static_cast<Numeric>(x), c); \
171#undef _complex_operations_
193using ComplexMatrixType = Eigen::Matrix<Complex, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>;
300 [[nodiscard]]
bool empty() const noexcept {
return (
nelem() == 0); }
393 using ConstComplexVectorView::operator[];
507 : msv(x), mstride(stride) {
513 msv.mdata += mstride;
519 if (msv.mdata + msv.mrange.mstart !=
550 : msv(
std::move(x)), mstride(stride) {
556 msv.mdata += mstride;
562 if (msv.mdata + msv.mrange.mstart !=
613 ARTS_ASSERT(
r0.get_extent() >= 0,
"Must have size. Has: ",
r0.get_extent());
633 void resize(
Index n);
669 [[nodiscard]]
Index nrows() const noexcept {
return mrr.mextent; }
670 [[nodiscard]]
Index ncols() const noexcept {
return mcr.mextent; }
671 [[nodiscard]]
bool empty() const noexcept {
return not nrows() or not ncols(); }
686 return *(
mdata + mrr.mstart + r * mrr.mstride + mcr.mstart +
698 Range(2*mcr.mstart, mcr.mextent, mcr.mstride*2));}
702 Range(2*mcr.mstart + 1, mcr.mextent, mcr.mstride*2));}
776 using ConstComplexMatrixView::operator();
802 return *(
mdata + mrr.mstart + r * mrr.mstride + mcr.mstart +
818 Range(2*mcr.mstart, mcr.mextent, mcr.mstride*2));}
822 Range(2*mcr.mstart + 1, mcr.mextent, mcr.mstride*2));}
926 [[nodiscard]]
Index size() const noexcept {
return nrows() * ncols();}
This can be used to make arrays out of anything.
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.
Complex & operator*() const
Dereferencing.
Complex * mx
Current position.
friend void copy(ConstComplexIterator1D origin, const ConstComplexIterator1D &end, ComplexIterator1D target)
Copy data between begin and end to target.
The row iterator class for sub matrices.
ComplexIterator2D & operator++()
Prefix increment operator.
ComplexVectorView & operator*()
Dereferencing.
ComplexVectorView msv
Current position.
ComplexVectorView * operator->()
The -> operator is needed, so that we can write i->begin() to get the 1D iterators.
bool operator!=(const ComplexIterator2D &other) const
Not equal operator, needed for algorithms like copy.
ComplexIterator2D(const ComplexVectorView &x, Index stride)
Explicit constructor.
ComplexIterator2D()=default
Default constructor.
The ComplexMatrixView class.
ComplexMatrixView & operator-=(const ConstComplexVectorView &x)
ComplexMatrixView & operator*=(const ConstComplexVectorView &x)
Complex & operator()(Index r, Index c)
Plain index operator.
MatrixView imag()
Get a view of the imaginary parts of the matrix.
MatrixView real()
Get a view of the real part of the matrix.
ComplexMatrixView & operator+=(const ConstComplexVectorView &x)
Numeric & get_imag(Index r, Index c)
Get element implementation without assertions.
Complex & get(Index r, Index c)
Get element implementation without assertions.
constexpr ComplexMatrixView(const ComplexMatrixView &)=default
Numeric & get_real(Index r, Index c)
Get element implementation without assertions.
ComplexMatrixView & operator/=(const ConstComplexVectorView &x)
Index size() const noexcept
The ComplexVectorView class.
ComplexVectorView & operator=(const Vector &v)
VectorView real()
Get a view of the real part of the vector.
ComplexVectorView & operator=(const Array< Numeric > &v)
ComplexVectorView operator-=(Complex x)
Subtraction of scalar.
ComplexVectorView & operator=(const VectorView &v)
Numeric & get_real(Index n)
Get element implementation without assertions.
friend class ConstComplexIterator2D
constexpr ComplexVectorView(const ComplexVectorView &)=default
ComplexVectorView operator+=(Complex x)
Addition of scalar.
VectorView imag()
Get a view of the imaginary part of the vector.
ComplexVectorView operator*=(Complex x)
Multiplication by scalar.
ComplexVectorView & operator=(const ConstComplexVectorView &v)
Assignment operator.
ComplexVectorView()=default
ComplexIterator1D end()
Return iterator behind last element.
ComplexVectorView & operator=(const ConstVectorView &v)
Complex & operator[](Index n)
Plain Index operator.
friend class ComplexIterator2D
ComplexVectorView operator/=(Complex x)
Division by scalar.
const Complex * get_c_array() const ARTS_NOEXCEPT
Conversion to plain C-array.
Complex & get(Index n)
Get element implementation without assertions.
Numeric & get_imag(Index n)
Get element implementation without assertions.
ComplexIterator1D begin()
Return iterator to first element.
friend class ComplexMatrixView
ComplexVector(ComplexVector &&cv) noexcept
ComplexVector & operator=(ComplexVector &&v) noexcept
Index size() const noexcept
ComplexVector(Complex *c, const Range &r0) ARTS_NOEXCEPT
The constant iterator class for sub vectors.
ConstComplexIterator1D()=default
Default constructor.
const Complex & operator*() const
Dereferencing.
ConstComplexIterator1D & operator++()
Prefix increment operator.
const Complex * mx
Current position.
bool operator!=(const ConstComplexIterator1D &other) const
Not equal operator, needed for algorithms like copy.
friend void copy(ConstComplexIterator1D origin, const ConstComplexIterator1D &end, ComplexIterator1D target)
Copy data between begin and end to target.
ConstComplexIterator1D(Complex *x, Index stride)
Explicit constructor.
The const row iterator class for sub matrices.
bool operator!=(const ConstComplexIterator2D &other) const
Not equal operator, needed for algorithms like copy.
ConstComplexIterator2D(ConstComplexVectorView x, Index stride)
Explicit constructor.
ConstComplexIterator2D & operator++()
Prefix increment operator.
const ConstComplexVectorView & operator*() const
Dereferencing.
ConstComplexIterator2D()=default
Default constructor.
const ConstComplexVectorView * operator->() const
The -> operator is needed, so that we can write i->begin() to get t he 1D iterators.
ConstComplexVectorView msv
Current position.
A constant view of a ComplexMatrix.
Complex get(Index r, Index c) const
Get element implementation without assertions.
ConstComplexIterator2D begin() const
Return const iterator to first row.
constexpr ConstComplexMatrixView(const ConstComplexMatrixView &)=default
ConstComplexVectorView diagonal() const
ComplexMatrix diagonal as vector.
bool empty() const noexcept
Complex operator()(Index r, Index c) const
Plain const index operator.
Numeric get_imag(Index r, Index c) const
Get element implementation without assertions.
Index ncols() const noexcept
ConstComplexMatrixView()=default
ConstComplexMatrixView & operator=(ConstComplexMatrixView &&)=default
Index nrows() const noexcept
Index get_column_extent() const
Get the extent of the underlying data.
ConstMatrixView imag() const
Get a view of the imaginary part of the matrix.
ConstComplexMatrixView & operator=(const ConstComplexMatrixView &)=default
constexpr ConstComplexMatrixView(ConstComplexMatrixView &&)=default
ConstComplexIterator2D end() const
Return const iterator behind last row.
virtual ~ConstComplexMatrixView()=default
Destructor.
Numeric get_real(Index r, Index c) const
Get element implementation without assertions.
ConstMatrixView real() const
Get a view of the real part of the matrix.
A constant view of a ComplexVector.
Complex sum() const
Returns true if variable size is zero.
ConstVectorView imag() const
Get a view of the imaginary part of the vector.
bool empty() const noexcept
const Numeric & get_imag(Index n) const
Get element implementation without assertions.
ConstComplexIterator1D end() const
Return const iterator behind last element.
friend class ConstComplexMatrixView
ConstComplexVectorView & operator=(ConstComplexVectorView &&)=default
ConstVectorView real() const
Get a view of the real part of the vector.
friend ConstComplexMatrixViewMap MapToEigen(const ConstComplexVectorView &)
Range mrange
The range of mdata that is actually used.
ConstComplexVectorView()=default
constexpr ConstComplexVectorView(ConstComplexVectorView &&)=default
Complex * mdata
Pointer to the plain C array that holds the data.
ConstComplexIterator1D begin() const
Return const iterator to first element.
friend Complex operator*(const ConstComplexVectorView &a, const ConstComplexVectorView &b)
Scalar product.
const Numeric & get_real(Index n) const
Get element implementation without assertions.
const Complex & get(Index n) const
Get element implementation without assertions.
constexpr ConstComplexVectorView(const ConstComplexVectorView &)=default
Index nelem() const noexcept
friend ConstComplexMatrixViewMap MapToEigenCol(const ConstComplexVectorView &)
const Complex & operator[](Index n) const
Plain const index operator.
virtual ~ConstComplexVectorView()=default
Destructor.
ConstComplexVectorView & operator=(const ConstComplexVectorView &)=default
friend void mult(ComplexVectorView, const ConstComplexMatrixView &, const ConstComplexVectorView &)
Matrix-Vector Multiplication.
A constant view of a Matrix.
A constant view of a Vector.
Index mstart
The start index.
Index mextent
The number of elements.
#define ARTS_ASSERT(condition,...)
Interface for the LAPACK library.
void inv(MatrixView Ainv, ConstMatrixView A)
Matrix Inverse.
Implementation of Matrix, Vector, and such stuff.
NUMERIC Numeric
The type to use for all floating point numbers.
INDEX Index
The type to use for all integer numbers and indices.
void swap(ComplexVector &v1, ComplexVector &v2)
Swaps two objects.
#define _complex_operations_(T)
ConstComplexMatrixView transpose(ConstComplexMatrixView m)
Const version of transpose.
std::complex< float > operator+(const double &d, const std::complex< float > &c)
std::complex< float > operator*(const double &d, const std::complex< float > &c)
Numeric & real_val(Complex &c) noexcept
Return a reference to the real value of c.
constexpr Numeric imag(Complex c) noexcept
imag
Eigen::Matrix< Complex, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > ComplexMatrixType
constexpr Complex conj(Complex c) noexcept
the conjugate of c
Numeric & imag_val(Complex &c) noexcept
Return a reference to the imaginary value of c.
constexpr Numeric abs2(Complex c) noexcept
squared magnitude of c
std::ostream & operator<<(std::ostream &os, const ConstComplexVectorView &v)
Output operator.
ConstComplexMatrixViewMap MapToEigenRow(const ConstComplexVectorView &A)
std::complex< Numeric > Complex
constexpr Complex operator/(Complex c, Numeric n) noexcept
constexpr Complex operator-(Complex c, Numeric n) noexcept
constexpr Numeric real(Complex c) noexcept
real
void copy(ConstComplexIterator1D origin, const ConstComplexIterator1D &end, ComplexIterator1D target)
Copy data between begin and end to target.
Eigen::Map< const ComplexMatrixType, 0, StrideType > ConstComplexMatrixViewMap
Eigen::Map< ComplexMatrixType, 0, StrideType > ComplexMatrixViewMap
constexpr Numeric r0
The reference radius in IGRF13.
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.
constexpr Rational start(Rational Ju, Rational Jl, Polarization type) noexcept
Gives the lowest M for a polarization type of this transition.
constexpr Rational end(Rational Ju, Rational Jl, Polarization type) noexcept
Gives the largest M for a polarization type of this transition.
constexpr bool isnan(double d) noexcept
Struct cannot be const, but can be passed as const to allow defaults.