43 #ifndef KOKKOS_COMPLEX_HPP 44 #define KOKKOS_COMPLEX_HPP 59 template<
class RealType>
75 re_ (src.re_), im_ (src.im_)
80 re_ (src.re_), im_ (src.im_)
88 template<
class InputRealType>
89 complex (
const std::complex<InputRealType>& src) :
90 re_ (std::
real (src)), im_ (std::
imag (src))
98 operator std::complex<RealType> ()
const {
99 return std::complex<RealType> (re_, im_);
104 template<
class InputRealType>
105 KOKKOS_INLINE_FUNCTION
complex (
const InputRealType& val) :
110 template<
class RealType1,
class RealType2>
111 KOKKOS_INLINE_FUNCTION
complex (
const RealType1& re,
const RealType2& im) :
116 template<
class InputRealType>
117 KOKKOS_INLINE_FUNCTION
125 template<
class InputRealType>
126 KOKKOS_INLINE_FUNCTION
134 template<
class InputRealType>
135 KOKKOS_INLINE_FUNCTION
143 template<
class InputRealType>
144 KOKKOS_INLINE_FUNCTION
152 template<
class InputRealType>
153 KOKKOS_INLINE_FUNCTION
156 im_ =
static_cast<RealType
> (0.0);
161 template<
class InputRealType>
162 KOKKOS_INLINE_FUNCTION
165 im_ =
static_cast<RealType
> (0.0);
173 template<
class InputRealType>
175 re_ = std::real (src);
176 im_ = std::imag (src);
181 KOKKOS_INLINE_FUNCTION RealType&
imag () {
186 KOKKOS_INLINE_FUNCTION RealType&
real () {
191 KOKKOS_INLINE_FUNCTION
const RealType
imag ()
const {
196 KOKKOS_INLINE_FUNCTION
const RealType
real ()
const {
201 KOKKOS_INLINE_FUNCTION
volatile RealType&
imag ()
volatile {
206 KOKKOS_INLINE_FUNCTION
volatile RealType&
real ()
volatile {
211 KOKKOS_INLINE_FUNCTION
const RealType
imag ()
const volatile {
216 KOKKOS_INLINE_FUNCTION
const RealType
real ()
const volatile {
220 KOKKOS_INLINE_FUNCTION
227 KOKKOS_INLINE_FUNCTION
233 KOKKOS_INLINE_FUNCTION
239 KOKKOS_INLINE_FUNCTION
240 void operator += (
const volatile RealType& src)
volatile {
244 KOKKOS_INLINE_FUNCTION
251 KOKKOS_INLINE_FUNCTION
257 KOKKOS_INLINE_FUNCTION
259 const RealType realPart = re_ * src.re_ - im_ * src.im_;
260 const RealType imagPart = re_ * src.im_ + im_ * src.re_;
266 KOKKOS_INLINE_FUNCTION
268 const RealType realPart = re_ * src.re_ - im_ * src.im_;
269 const RealType imagPart = re_ * src.im_ + im_ * src.re_;
274 KOKKOS_INLINE_FUNCTION
281 KOKKOS_INLINE_FUNCTION
282 void operator *= (
const volatile RealType& src)
volatile {
287 KOKKOS_INLINE_FUNCTION
292 const RealType s = ::fabs (y.
real ()) + ::fabs (y.
imag ());
304 const RealType y_scaled_abs = y_conj_scaled.re_ * y_conj_scaled.re_ +
305 y_conj_scaled.im_ * y_conj_scaled.im_;
306 *
this = x_scaled * y_conj_scaled;
307 *
this /= y_scaled_abs;
312 KOKKOS_INLINE_FUNCTION
321 template<
class RealType>
322 KOKKOS_INLINE_FUNCTION
329 template<
class RealType>
330 KOKKOS_INLINE_FUNCTION
337 template<
class RealType>
338 KOKKOS_INLINE_FUNCTION
345 template<
class RealType>
346 KOKKOS_INLINE_FUNCTION
353 template<
class RealType>
354 KOKKOS_INLINE_FUNCTION
371 template<
class RealType>
375 x.real () * y.
imag () + x.imag () * y.
real ());
382 template<
class RealType>
383 KOKKOS_INLINE_FUNCTION
391 template<
class RealType>
392 KOKKOS_INLINE_FUNCTION
398 template<
class RealType>
399 KOKKOS_INLINE_FUNCTION
405 template<
class RealType>
406 KOKKOS_INLINE_FUNCTION
413 template<
class RealType>
414 KOKKOS_INLINE_FUNCTION
421 template<
class RealType1,
class RealType2>
422 KOKKOS_INLINE_FUNCTION
429 template<
class RealType>
430 KOKKOS_INLINE_FUNCTION
436 const RealType s = ::fabs (
real (y)) + ::fabs (
imag (y));
447 const RealType y_scaled_abs =
real (y_conj_scaled) *
real (y_conj_scaled) +
448 imag (y_conj_scaled) *
imag (y_conj_scaled);
450 result /= y_scaled_abs;
456 template<
class RealType>
457 KOKKOS_INLINE_FUNCTION
463 template<
class RealType>
464 KOKKOS_INLINE_FUNCTION
466 return std::real (x) ==
real (y) && std::imag (x) ==
imag (y);
470 template<
class RealType1,
class RealType2>
471 KOKKOS_INLINE_FUNCTION
473 return real (x) == y &&
imag (x) ==
static_cast<RealType1
> (0.0);
477 template<
class RealType>
478 KOKKOS_INLINE_FUNCTION
484 template<
class RealType>
485 KOKKOS_INLINE_FUNCTION
491 template<
class RealType>
492 KOKKOS_INLINE_FUNCTION
494 return std::real (x) !=
real (y) || std::imag (x) !=
imag (y);
498 template<
class RealType1,
class RealType2>
499 KOKKOS_INLINE_FUNCTION
501 return real (x) != y ||
imag (x) !=
static_cast<RealType1
> (0.0);
505 template<
class RealType>
506 KOKKOS_INLINE_FUNCTION
511 template<
class RealType>
512 std::ostream& operator << (std::ostream& os, const complex<RealType>& x) {
518 template<
class RealType>
520 std::complex<RealType> x_std;
529 #endif // KOKKOS_COMPLEX_HPP KOKKOS_INLINE_FUNCTION RealType & imag()
The imaginary part of this complex number.
KOKKOS_INLINE_FUNCTION complex(const RealType1 &re, const RealType2 &im)
Constructor that takes the real and imaginary parts.
KOKKOS_INLINE_FUNCTION complex< RealType > operator*(const complex< RealType > &x, const complex< RealType > &y)
Binary * operator for complex.
Partial reimplementation of std::complex that works as the result of a Kokkos::parallel_reduce.
KOKKOS_INLINE_FUNCTION complex(const InputRealType &val)
Constructor that takes just the real part, and sets the imaginary part to zero.
KOKKOS_INLINE_FUNCTION bool operator!=(const complex< RealType > &x, const complex< RealType > &y)
Inequality operator for two complex numbers.
KOKKOS_INLINE_FUNCTION complex(const volatile complex< RealType > &src)
Copy constructor from volatile.
KOKKOS_INLINE_FUNCTION const RealType real() const
The real part of this complex number.
KOKKOS_INLINE_FUNCTION complex(const complex< RealType > &src)
Copy constructor.
KOKKOS_INLINE_FUNCTION complex()
Default constructor (initializes both real and imaginary parts to zero).
KOKKOS_INLINE_FUNCTION RealType abs(const complex< RealType > &x)
Absolute value (magnitude) of a complex number.
KOKKOS_INLINE_FUNCTION RealType & real()
The real part of this complex number.
complex(const std::complex< InputRealType > &src)
Conversion constructor from std::complex.
KOKKOS_INLINE_FUNCTION volatile RealType & imag() volatile
The imaginary part of this complex number (volatile overload).
KOKKOS_INLINE_FUNCTION const RealType imag() const
The imaginary part of this complex number.
KOKKOS_INLINE_FUNCTION complex< RealType > & operator=(const complex< InputRealType > &src)
Assignment operator.
KOKKOS_INLINE_FUNCTION complex< RealType > operator+(const complex< RealType > &x, const complex< RealType > &y)
Binary + operator for complex.
KOKKOS_INLINE_FUNCTION complex< RealType > operator-(const complex< RealType > &x, const complex< RealType > &y)
Binary - operator for complex.
RealType value_type
The type of the real or imaginary parts of this complex number.
KOKKOS_INLINE_FUNCTION RealType real(const complex< RealType > &x)
Real part of a complex number.
KOKKOS_INLINE_FUNCTION volatile RealType & real() volatile
The real part of this complex number (volatile overload).
KOKKOS_INLINE_FUNCTION const RealType imag() const volatile
The imaginary part of this complex number (volatile overload).
KOKKOS_INLINE_FUNCTION const RealType real() const volatile
The real part of this complex number (volatile overload).
KOKKOS_INLINE_FUNCTION complex< RealType > conj(const complex< RealType > &x)
Conjugate of a complex number.
KOKKOS_INLINE_FUNCTION bool operator==(const complex< RealType > &x, const complex< RealType > &y)
Equality operator for two complex numbers.
KOKKOS_INLINE_FUNCTION complex< RealType1 > operator/(const complex< RealType1 > &x, const RealType2 &y)
Binary operator / for complex and real numbers.
KOKKOS_INLINE_FUNCTION RealType imag(const complex< RealType > &x)
Imaginary part of a complex number.