|
| constexpr | Complex ()=default |
| | Default constructor. More...
|
| |
| constexpr | Complex (const T &re, const T &im=T()) |
| | Construct from real/imaginary parts. More...
|
| |
| template<typename Q > |
| constexpr | Complex (const Complex< Q > &s) |
| | Construct from a different type of Complex. More...
|
| |
| template<typename Q > |
| constexpr | Complex (const std::complex< Q > &s) |
| | Construct from an std::complex (and permit type-conversion). More...
|
| |
| constexpr | Complex (const Complex< T > &s)=default |
| | Copy constructor (must be explicitly specified because an explicit volatile operator = exists). More...
|
| |
| constexpr T | real () const |
| | Get the real part. More...
|
| |
| constexpr T & | real () |
| | Access the real part. More...
|
| |
| constexpr void | real (T value) |
| | Update the real part. More...
|
| |
| constexpr T | imag () const |
| | Get the imaginary part. More...
|
| |
| constexpr T & | imag () |
| | Access the imaginary part. More...
|
| |
| constexpr void | imag (T value) |
| | Update the imaginary part. More...
|
| |
| constexpr auto | norm () const |
| | Squared magnitude (consistent with std::norm()) More...
|
| |
|
constexpr auto | norm_l1 () const |
| |
| constexpr auto | abs () const |
| | Magnitude (consistent with std::abs()) More...
|
| |
| constexpr auto | conjugate () const |
| | Complex conjugate. More...
|
| |
| template<typename Q > |
| constexpr bool | operator== (const Complex< Q > &other) const |
| | Comparison to other complex numbers. More...
|
| |
| template<typename Q > |
| constexpr bool | operator== (const Q &other) const |
| | Comparison to scalar, which is interpreted as a Complex(x, 0). More...
|
| |
| template<typename Q > |
| constexpr bool | operator!= (const Q &other) const |
| | General purpose inequality operator. More...
|
| |
| volatile Complex< T > & | operator= (const volatile Complex< T > &other) volatile |
| | Volatile assignment operators. More...
|
| |
|
volatile Complex< T > & | operator= (const Complex< T > &other) volatile |
| |
|
Complex< T > & | operator= (const volatile Complex< T > &other) |
| |
| Complex< T > & | operator= (const Complex< T > &other)=default |
| | Assignment. More...
|
| |
|
constexpr Complex< T > | operator+ () const |
| |
|
constexpr Complex< T > | operator- () const |
| |
template<typename T>
class sp::Complex< T >
A complex number of type T.
The API is very similar to std::complex, but it allows T to be any type which has the right arithmetic operators. Notably, this means you can have half-float complex numbers.
Other notable properties:
- Far more fluent API than
cuComplex. You can actually use arithmetic operators!
- Fully
constexpr, so it can be used for metaprogramming.
- Uses the Cayley-Dickson construction, so can be composed to form quaternions etc.
Example
This example is a very uninteresting device function that computes (a * x) + y for three complex numbers, a, x, and y.
Vanilla CUDA
__device__ cuComplex complexAxpy(cuComplex a, cuComplex x, cuComplex y) {
return cuCaddf(cuCmulf(a, x), y);
}
Using Speclib
return (a * x) + y;
}
A complex number of type T.
Definition: Complex.hpp:89
The speclib version also:
- Is constexpr, so will work at compile time, as well as on both CPU and GPU.
- Compiles to the same machine code.
- Easily adapts to work for double precision, half-precision, integers, etc, by adding a template parameter