43 #ifndef KOKKOS_COMPLEX_HPP 44 #define KOKKOS_COMPLEX_HPP 47 #include <Kokkos_NumericTraits.hpp> 60 template<
class RealType>
76 re_ (src.re_), im_ (src.im_)
81 re_ (src.re_), im_ (src.im_)
89 template<
class InputRealType>
90 complex (
const std::complex<InputRealType>& src) :
91 re_ (std::
real (src)), im_ (std::
imag (src))
99 operator std::complex<RealType> ()
const {
100 return std::complex<RealType> (re_, im_);
105 template<
class InputRealType>
106 KOKKOS_INLINE_FUNCTION
complex (
const InputRealType& val) :
111 template<
class RealType1,
class RealType2>
112 KOKKOS_INLINE_FUNCTION
complex (
const RealType1& re,
const RealType2& im) :
117 template<
class InputRealType>
118 KOKKOS_INLINE_FUNCTION
134 template<
class InputRealType>
135 KOKKOS_INLINE_FUNCTION
144 template<
class InputRealType>
145 KOKKOS_INLINE_FUNCTION
153 template<
class InputRealType>
154 KOKKOS_INLINE_FUNCTION
162 template<
class InputRealType>
163 KOKKOS_INLINE_FUNCTION
166 im_ =
static_cast<RealType
> (0.0);
171 template<
class InputRealType>
172 KOKKOS_INLINE_FUNCTION
175 im_ =
static_cast<RealType
> (0.0);
183 template<
class InputRealType>
185 re_ = std::real (src);
186 im_ = std::imag (src);
191 KOKKOS_INLINE_FUNCTION RealType&
imag () {
196 KOKKOS_INLINE_FUNCTION RealType&
real () {
201 KOKKOS_INLINE_FUNCTION
const RealType
imag ()
const {
206 KOKKOS_INLINE_FUNCTION
const RealType
real ()
const {
211 KOKKOS_INLINE_FUNCTION
volatile RealType&
imag ()
volatile {
216 KOKKOS_INLINE_FUNCTION
volatile RealType&
real ()
volatile {
221 KOKKOS_INLINE_FUNCTION
const RealType
imag ()
const volatile {
226 KOKKOS_INLINE_FUNCTION
const RealType
real ()
const volatile {
230 KOKKOS_INLINE_FUNCTION
237 KOKKOS_INLINE_FUNCTION
243 KOKKOS_INLINE_FUNCTION
249 KOKKOS_INLINE_FUNCTION
250 void operator += (
const volatile RealType& src)
volatile {
254 KOKKOS_INLINE_FUNCTION
261 KOKKOS_INLINE_FUNCTION
267 KOKKOS_INLINE_FUNCTION
269 const RealType realPart = re_ * src.re_ - im_ * src.im_;
270 const RealType imagPart = re_ * src.im_ + im_ * src.re_;
276 KOKKOS_INLINE_FUNCTION
278 const RealType realPart = re_ * src.re_ - im_ * src.im_;
279 const RealType imagPart = re_ * src.im_ + im_ * src.re_;
284 KOKKOS_INLINE_FUNCTION
291 KOKKOS_INLINE_FUNCTION
292 void operator *= (
const volatile RealType& src)
volatile {
297 KOKKOS_INLINE_FUNCTION
302 const RealType s = ::fabs (y.
real ()) + ::fabs (y.
imag ());
314 const RealType y_scaled_abs = y_conj_scaled.re_ * y_conj_scaled.re_ +
315 y_conj_scaled.im_ * y_conj_scaled.im_;
316 *
this = x_scaled * y_conj_scaled;
317 *
this /= y_scaled_abs;
322 KOKKOS_INLINE_FUNCTION
329 KOKKOS_INLINE_FUNCTION
331 return (re_ == src.re_) && (im_ == src.im_);
334 KOKKOS_INLINE_FUNCTION
335 bool operator == (
const RealType src) {
336 return (re_ == src) && (im_ == RealType(0));
339 KOKKOS_INLINE_FUNCTION
341 return (re_ != src.re_) || (im_ != src.im_);
344 KOKKOS_INLINE_FUNCTION
345 bool operator != (
const RealType src) {
346 return (re_ != src) || (im_ != RealType(0));
352 template<
class RealType>
353 KOKKOS_INLINE_FUNCTION
360 template<
class RealType>
361 KOKKOS_INLINE_FUNCTION
368 template<
class RealType>
369 KOKKOS_INLINE_FUNCTION
376 template<
class RealType>
377 KOKKOS_INLINE_FUNCTION
384 template<
class RealType>
385 KOKKOS_INLINE_FUNCTION
392 template<
class RealType>
393 KOKKOS_INLINE_FUNCTION
400 template<
class RealType>
401 KOKKOS_INLINE_FUNCTION
408 template<
class RealType>
409 KOKKOS_INLINE_FUNCTION
416 template<
class RealType>
417 KOKKOS_INLINE_FUNCTION
434 template<
class RealType>
438 x.real () * y.
imag () + x.imag () * y.
real ());
445 template<
class RealType>
446 KOKKOS_INLINE_FUNCTION
456 template<
class RealType>
457 KOKKOS_INLINE_FUNCTION
464 template<
class RealType>
465 KOKKOS_INLINE_FUNCTION
471 template<
class RealType>
472 KOKKOS_INLINE_FUNCTION
478 template<
class RealType>
479 KOKKOS_INLINE_FUNCTION
486 template<
class RealType>
487 KOKKOS_INLINE_FUNCTION
490 RealType phi = std::atan(x.
imag()/x.
real());
495 template<
class RealType>
496 KOKKOS_INLINE_FUNCTION
499 RealType phi = std::atan(x.
imag()/x.
real());
504 template<
class RealType>
505 KOKKOS_INLINE_FUNCTION
511 template<
class RealType>
512 KOKKOS_INLINE_FUNCTION
518 template<
class RealType>
519 KOKKOS_INLINE_FUNCTION
525 template<
class RealType1,
class RealType2>
526 KOKKOS_INLINE_FUNCTION
533 template<
class RealType>
534 KOKKOS_INLINE_FUNCTION
540 const RealType s = ::fabs (
real (y)) + ::fabs (
imag (y));
551 const RealType y_scaled_abs =
real (y_conj_scaled) *
real (y_conj_scaled) +
552 imag (y_conj_scaled) *
imag (y_conj_scaled);
554 result /= y_scaled_abs;
560 template<
class RealType1,
class RealType2>
561 KOKKOS_INLINE_FUNCTION
568 template<
class RealType>
569 KOKKOS_INLINE_FUNCTION
580 template<
class RealType>
582 return std::real (x) ==
real (y) && std::imag (x) ==
imag (y);
586 template<
class RealType1,
class RealType2>
587 KOKKOS_INLINE_FUNCTION
589 return real (x) == y &&
imag (x) ==
static_cast<RealType1
> (0.0);
593 template<
class RealType>
594 KOKKOS_INLINE_FUNCTION
600 template<
class RealType>
601 KOKKOS_INLINE_FUNCTION
607 template<
class RealType>
608 KOKKOS_INLINE_FUNCTION
610 return std::real (x) !=
real (y) || std::imag (x) !=
imag (y);
614 template<
class RealType1,
class RealType2>
615 KOKKOS_INLINE_FUNCTION
617 return real (x) != y ||
imag (x) !=
static_cast<RealType1
> (0.0);
621 template<
class RealType>
622 KOKKOS_INLINE_FUNCTION
627 template<
class RealType>
628 std::ostream& operator << (std::ostream& os, const complex<RealType>& x) {
634 template<
class RealType>
636 std::complex<RealType> x_std;
644 struct reduction_identity<Kokkos::
complex<T> > {
645 typedef reduction_identity<T> t_red_ident;
654 #endif // KOKKOS_COMPLEX_HPP KOKKOS_INLINE_FUNCTION const RealType imag() const
The imaginary part of this complex number.
KOKKOS_INLINE_FUNCTION const RealType real() const
The real part of this complex number.
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 Kokkos::complex< RealType > pow(const complex< RealType > &x, const RealType &e)
Power of a complex number.
KOKKOS_INLINE_FUNCTION complex(const volatile complex< RealType > &src)
Copy constructor from volatile.
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 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 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 Kokkos::complex< RealType > sqrt(const complex< RealType > &x)
Square root of a complex number.
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 complex< RealType > exp(const complex< RealType > &x)
Exponential of a complex number.
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.