26#ifndef matpack_complex_h
27#define matpack_complex_h
52 const std::complex<float>&
c) {
53 return (
float(
d) +
c);
56 const std::complex<float>&
c) {
57 return (
float(
d) *
c);
60inline std::complex<float>
operator+(
const std::complex<float>&
c,
62 return (
c +
float(
d));
64inline std::complex<float>
operator*(
const std::complex<float>&
c,
66 return (
c *
float(
d));
99 return {
a1 * n,
b1 * n};
102 return {
a1 / n,
b1 / n};
109 return {n -
a1, -
b1};
112 return {n *
a1, n *
b1};
141#define _complex_operations_(T) \
142 constexpr Complex operator+(Complex c, T x) noexcept { \
143 return operator+(c, static_cast<Numeric>(x)); \
145 constexpr Complex operator-(Complex c, T x) noexcept { \
146 return operator-(c, static_cast<Numeric>(x)); \
148 constexpr Complex operator*(Complex c, T x) noexcept { \
149 return operator*(c, static_cast<Numeric>(x)); \
151 constexpr Complex operator/(Complex c, T x) noexcept { \
152 return operator/(c, static_cast<Numeric>(x)); \
155 constexpr Complex operator+(T x, Complex c) noexcept { \
156 return operator+(static_cast<Numeric>(x), c); \
158 constexpr Complex operator-(T x, Complex c) noexcept { \
159 return operator-(static_cast<Numeric>(x), c); \
161 constexpr Complex operator*(T x, Complex c) noexcept { \
162 return operator*(static_cast<Numeric>(x), c); \
164 constexpr Complex operator/(T x, Complex c) noexcept { \
165 return operator/(static_cast<Numeric>(x), c); \
172#undef _complex_operations_
174constexpr bool isnan(
Complex c)
noexcept {
298 [[nodiscard]]
bool empty() const noexcept {
return (
nelem() == 0); }
397 using ConstComplexVectorView::operator[];
614 ARTS_ASSERT(r0.get_extent() >= 0,
"Must have size. Has: ", r0.get_extent());
632 if (
const auto s = matpack::shape<Index, 1>(init);
shape().data not_eq s)
636 operator[](i) = init[i];
688 [[nodiscard]]
Index selem() const noexcept {
return mrr.mstart + mcr.mstart; }
689 [[nodiscard]]
Index nrows() const noexcept {
return mrr.mextent; }
690 [[nodiscard]]
Index ncols() const noexcept {
return mcr.mextent; }
691 [[nodiscard]]
Index drows() const noexcept {
return mrr.mstride; }
692 [[nodiscard]]
Index dcols() const noexcept {
return mcr.mstride; }
695 [[nodiscard]]
Index size() const noexcept {
return nrows() * ncols();}
696 [[nodiscard]]
bool empty() const noexcept {
return not nrows() or not ncols(); }
711 return *(
mdata + mrr.mstart + r * mrr.mstride + mcr.mstart +
799 using ConstComplexMatrixView::operator();
812#define GETFUN(r, c) \
813 *(mdata + mrr.mstart + r * mrr.mstride + mcr.mstart + c * mcr.mstride)
940 if (
const auto s = matpack::shape<Index, 2>(init); shape().data not_eq s)
943 auto [I, J] = shape().data;
944 for (
Index i = 0; i < I; i++)
945 for (
Index j = 0; j < J; j++)
946 operator()(i, j) = init(i, j);
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.
~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.
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()
Default constructor.
ComplexIterator2D begin()
Return iterator to first row.
ComplexMatrix(const matpack::matrix_like_not_matrix auto &init)
Initialization from a vector type.
ComplexMatrix & operator=(const matpack::matrix_like_not_matrix auto &init)
Set from a matrix type.
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.
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.
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
ComplexVector(ComplexVector &&cv) noexcept
ComplexVector(const matpack::vector_like_not_vector auto &init)
Initialization from a vector type.
ComplexVector & operator=(ComplexVector &&v) ARTS_NOEXCEPT
friend void swap(ComplexVector &v1, ComplexVector &v2) noexcept
Swaps two objects.
~ComplexVector() noexcept override
Destructor for ComplexVector.
ComplexVector(Complex *c, const Range &r0) ARTS_NOEXCEPT
void resize(Index n)
Resize function.
ComplexVector & operator=(const ComplexVector &v)
Assignment from another Vector.
ComplexVector & operator=(const matpack::vector_like_not_vector auto &init)
Set from a vector type.
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.
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
Index dcols() 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
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.
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
static constexpr bool matpack_type
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.
A constant view of a Vector.
Index mstart
The start index.
Index mextent
The number of elements.
A concept precluding Arts matrix objects but allowing things similar to matrices.
A concept precluding Arts vector objects but allowing things similar to vectors.
#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) noexcept
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
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::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.
constexpr bool isnan(double d) noexcept
Struct cannot be const, but can be passed as const to allow defaults.