alpaka
Abstraction Library for Parallel Kernel Acceleration
alpaka::internal::Complex< T > Class Template Reference

Implementation of a complex number useable on host and device. More...

#include <Complex.hpp>

Public Types

using value_type = T
 Type of the real and imaginary parts. More...
 

Public Member Functions

constexpr Complex (Complex const &other)=default
 Copy constructor. More...
 
template<typename U >
constexpr ALPAKA_FN_HOST_ACC Complex (Complex< U > const &other)
 Constructor from Complex of another type. More...
 
constexpr ALPAKA_FN_HOST_ACC Complex (std::complex< T > const &other)
 Constructor from std::complex. More...
 
constexpr ALPAKA_FN_HOST_ACC Complex (T const &real=T{}, T const &imag=T{})
 Constructor from the given real and imaginary parts. More...
 
constexpr ALPAKA_FN_HOST_ACCimag () const
 Get the imaginary part. More...
 
constexpr ALPAKA_FN_HOST_ACC void imag (T value)
 Set the imaginary part. More...
 
constexpr ALPAKA_FN_HOST_ACC operator std::complex< T > () const
 Conversion to std::complex. More...
 
template<typename U >
ALPAKA_FN_HOST_ACC Complexoperator*= (Complex< U > const &other)
 Multiplication assignment with a complex number. More...
 
ALPAKA_FN_HOST_ACC Complexoperator*= (T const &other)
 Multiplication assignment with a real number. More...
 
template<typename U >
ALPAKA_FN_HOST_ACC Complexoperator+= (Complex< U > const &other)
 Addition assignment with a complex number. More...
 
ALPAKA_FN_HOST_ACC Complexoperator+= (T const &other)
 Addition assignment with a real number. More...
 
template<typename U >
ALPAKA_FN_HOST_ACC Complexoperator-= (Complex< U > const &other)
 Subtraction assignment with a complex number. More...
 
ALPAKA_FN_HOST_ACC Complexoperator-= (T const &other)
 Subtraction assignment with a real number. More...
 
template<typename U >
ALPAKA_FN_HOST_ACC Complexoperator/= (Complex< U > const &other)
 Division assignment with a complex number. More...
 
ALPAKA_FN_HOST_ACC Complexoperator/= (T const &other)
 Division assignment with a real number. More...
 
Complexoperator= (Complex const &)=default
 Assignment. More...
 
constexpr ALPAKA_FN_HOST_ACCreal () const
 Get the real part. More...
 
constexpr ALPAKA_FN_HOST_ACC void real (T value)
 Set the real part. More...
 

Detailed Description

template<typename T>
class alpaka::internal::Complex< T >

Implementation of a complex number useable on host and device.

It follows the layout of std::complex and so array-oriented access. The class template implements all methods and operators as std::complex<T>. Additionally, it provides an implicit conversion to and from std::complex<T>. All methods besides operators << and >> are host-device. It does not provide non-member functions of std::complex besides the operators. Those are provided the same way as alpaka math functions for real numbers.

Note that unlike most of alpaka, this is a concrete type template, and not merely a concept.

Naming and order of the methods match https://en.cppreference.com/w/cpp/numeric/complex in C++17. Implementation chose to not extend it e.g. by adding constexpr to some places that would get it in C++20. The motivation is that with internal conversion to std::complex<T> for CPU backends, it would define the common interface for generic code anyways. So it is more clear to have alpaka's interface exactly matching when possible, and not "improving".

Template Parameters
Ttype of the real and imaginary part: float, double, or long double.

Definition at line 38 of file Complex.hpp.

Member Typedef Documentation

◆ value_type

template<typename T >
using alpaka::internal::Complex< T >::value_type = T

Type of the real and imaginary parts.

Definition at line 45 of file Complex.hpp.

Constructor & Destructor Documentation

◆ Complex() [1/4]

template<typename T >
constexpr ALPAKA_FN_HOST_ACC alpaka::internal::Complex< T >::Complex ( T const &  real = T{},
T const &  imag = T{} 
)
inlineconstexpr

Constructor from the given real and imaginary parts.

Definition at line 48 of file Complex.hpp.

◆ Complex() [2/4]

template<typename T >
constexpr alpaka::internal::Complex< T >::Complex ( Complex< T > const &  other)
constexprdefault

Copy constructor.

◆ Complex() [3/4]

template<typename T >
template<typename U >
constexpr ALPAKA_FN_HOST_ACC alpaka::internal::Complex< T >::Complex ( Complex< U > const &  other)
inlineconstexpr

Constructor from Complex of another type.

Definition at line 57 of file Complex.hpp.

◆ Complex() [4/4]

template<typename T >
constexpr ALPAKA_FN_HOST_ACC alpaka::internal::Complex< T >::Complex ( std::complex< T > const &  other)
inlineconstexpr

Constructor from std::complex.

Definition at line 64 of file Complex.hpp.

Member Function Documentation

◆ imag() [1/2]

template<typename T >
constexpr ALPAKA_FN_HOST_ACC T alpaka::internal::Complex< T >::imag ( ) const
inlineconstexpr

Get the imaginary part.

Definition at line 92 of file Complex.hpp.

◆ imag() [2/2]

template<typename T >
constexpr ALPAKA_FN_HOST_ACC void alpaka::internal::Complex< T >::imag ( value)
inlineconstexpr

Set the imaginary part.

Definition at line 98 of file Complex.hpp.

◆ operator std::complex< T >()

template<typename T >
constexpr ALPAKA_FN_HOST_ACC alpaka::internal::Complex< T >::operator std::complex< T > ( ) const
inlineconstexpr

Conversion to std::complex.

Definition at line 71 of file Complex.hpp.

◆ operator*=() [1/2]

template<typename T >
template<typename U >
ALPAKA_FN_HOST_ACC Complex& alpaka::internal::Complex< T >::operator*= ( Complex< U > const &  other)
inline

Multiplication assignment with a complex number.

Definition at line 145 of file Complex.hpp.

◆ operator*=() [2/2]

template<typename T >
ALPAKA_FN_HOST_ACC Complex& alpaka::internal::Complex< T >::operator*= ( T const &  other)
inline

Multiplication assignment with a real number.

Definition at line 136 of file Complex.hpp.

◆ operator+=() [1/2]

template<typename T >
template<typename U >
ALPAKA_FN_HOST_ACC Complex& alpaka::internal::Complex< T >::operator+= ( Complex< U > const &  other)
inline

Addition assignment with a complex number.

Definition at line 112 of file Complex.hpp.

◆ operator+=() [2/2]

template<typename T >
ALPAKA_FN_HOST_ACC Complex& alpaka::internal::Complex< T >::operator+= ( T const &  other)
inline

Addition assignment with a real number.

Definition at line 104 of file Complex.hpp.

◆ operator-=() [1/2]

template<typename T >
template<typename U >
ALPAKA_FN_HOST_ACC Complex& alpaka::internal::Complex< T >::operator-= ( Complex< U > const &  other)
inline

Subtraction assignment with a complex number.

Definition at line 128 of file Complex.hpp.

◆ operator-=() [2/2]

template<typename T >
ALPAKA_FN_HOST_ACC Complex& alpaka::internal::Complex< T >::operator-= ( T const &  other)
inline

Subtraction assignment with a real number.

Definition at line 120 of file Complex.hpp.

◆ operator/=() [1/2]

template<typename T >
template<typename U >
ALPAKA_FN_HOST_ACC Complex& alpaka::internal::Complex< T >::operator/= ( Complex< U > const &  other)
inline

Division assignment with a complex number.

Definition at line 164 of file Complex.hpp.

◆ operator/=() [2/2]

template<typename T >
ALPAKA_FN_HOST_ACC Complex& alpaka::internal::Complex< T >::operator/= ( T const &  other)
inline

Division assignment with a real number.

Definition at line 155 of file Complex.hpp.

◆ operator=()

template<typename T >
Complex& alpaka::internal::Complex< T >::operator= ( Complex< T > const &  )
default

Assignment.

◆ real() [1/2]

template<typename T >
constexpr ALPAKA_FN_HOST_ACC T alpaka::internal::Complex< T >::real ( ) const
inlineconstexpr

Get the real part.

Definition at line 80 of file Complex.hpp.

◆ real() [2/2]

template<typename T >
constexpr ALPAKA_FN_HOST_ACC void alpaka::internal::Complex< T >::real ( value)
inlineconstexpr

Set the real part.

Definition at line 86 of file Complex.hpp.


The documentation for this class was generated from the following file: