16 #ifndef KOKKOS_COMPLEX_HPP
17 #define KOKKOS_COMPLEX_HPP
18 #ifndef KOKKOS_IMPL_PUBLIC_INCLUDE
19 #define KOKKOS_IMPL_PUBLIC_INCLUDE
20 #define KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_COMPLEX
24 #include <Kokkos_MathematicalFunctions.hpp>
25 #include <Kokkos_NumericTraits.hpp>
26 #include <Kokkos_ReductionIdentity.hpp>
27 #include <impl/Kokkos_Error.hpp>
29 #include <type_traits>
41 template <
class RealType>
43 #ifdef KOKKOS_ENABLE_COMPLEX_ALIGN
44 alignas(2 *
sizeof(RealType))
47 static_assert(std::is_floating_point_v<RealType> &&
48 std::is_same_v<RealType, std::remove_cv_t<RealType>>,
49 "Kokkos::complex can only be instantiated for a cv-unqualified "
50 "floating point type");
61 KOKKOS_DEFAULTED_FUNCTION
65 KOKKOS_DEFAULTED_FUNCTION
68 KOKKOS_DEFAULTED_FUNCTION
74 std::enable_if_t<std::is_convertible<RType, RealType>::value,
int> = 0>
79 : re_(other.real()), im_(other.imag()) {}
86 KOKKOS_INLINE_FUNCTION
87 complex(
const std::complex<RealType>& src) noexcept
94 : re_(
reinterpret_cast<const RealType (&)[2]
>(src)[0]),
95 im_(
reinterpret_cast<const RealType (&)[2]
>(src)[1]) {}
103 operator std::complex<RealType>()
const noexcept {
104 return std::complex<RealType>(re_, im_);
109 KOKKOS_INLINE_FUNCTION
complex(
const RealType& val) noexcept
110 : re_(val), im_(static_cast<RealType>(0)) {}
113 KOKKOS_INLINE_FUNCTION
114 complex(
const RealType& re,
const RealType& im) noexcept : re_(re), im_(im) {}
134 KOKKOS_INLINE_FUNCTION
135 constexpr RealType&
imag() noexcept {
return im_; }
138 KOKKOS_INLINE_FUNCTION
139 constexpr RealType&
real() noexcept {
return re_; }
142 KOKKOS_INLINE_FUNCTION
143 constexpr RealType
imag() const noexcept {
return im_; }
146 KOKKOS_INLINE_FUNCTION
147 constexpr RealType
real() const noexcept {
return re_; }
150 KOKKOS_INLINE_FUNCTION
151 constexpr
void imag(RealType v) noexcept { im_ = v; }
154 KOKKOS_INLINE_FUNCTION
155 constexpr
void real(RealType v) noexcept { re_ = v; }
157 constexpr KOKKOS_INLINE_FUNCTION
complex& operator+=(
164 constexpr KOKKOS_INLINE_FUNCTION complex& operator+=(
165 const RealType& src) noexcept {
170 constexpr KOKKOS_INLINE_FUNCTION complex& operator-=(
171 const complex<RealType>& src) noexcept {
177 constexpr KOKKOS_INLINE_FUNCTION complex& operator-=(
178 const RealType& src) noexcept {
183 constexpr KOKKOS_INLINE_FUNCTION complex& operator*=(
184 const complex<RealType>& src) noexcept {
185 const RealType realPart = re_ * src.re_ - im_ * src.im_;
186 const RealType imagPart = re_ * src.im_ + im_ * src.re_;
192 constexpr KOKKOS_INLINE_FUNCTION complex& operator*=(
193 const RealType& src) noexcept {
200 constexpr KOKKOS_INLINE_FUNCTION complex& operator/=(
201 const complex<RealType>& y) noexcept(noexcept(RealType{} / RealType{})) {
205 const RealType s = fabs(y.real()) + fabs(y.imag());
211 if (s == RealType(0)) {
215 const complex x_scaled(this->re_ / s, this->im_ / s);
216 const complex y_conj_scaled(y.re_ / s, -(y.im_) / s);
217 const RealType y_scaled_abs =
218 y_conj_scaled.re_ * y_conj_scaled.re_ +
219 y_conj_scaled.im_ * y_conj_scaled.im_;
220 *
this = x_scaled * y_conj_scaled;
221 *
this /= y_scaled_abs;
226 constexpr KOKKOS_INLINE_FUNCTION complex& operator/=(
227 const std::complex<RealType>& y) noexcept(noexcept(RealType{} /
232 const RealType s = fabs(y.real()) + fabs(y.imag());
237 if (s == RealType(0)) {
241 const complex x_scaled(this->re_ / s, this->im_ / s);
242 const complex y_conj_scaled(y.re_ / s, -(y.im_) / s);
243 const RealType y_scaled_abs =
244 y_conj_scaled.re_ * y_conj_scaled.re_ +
245 y_conj_scaled.im_ * y_conj_scaled.im_;
246 *
this = x_scaled * y_conj_scaled;
247 *
this /= y_scaled_abs;
252 constexpr KOKKOS_INLINE_FUNCTION complex& operator/=(
253 const RealType& src) noexcept(noexcept(RealType{} / RealType{})) {
259 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE_4
263 std::enable_if_t<std::is_convertible<RType, RealType>::value,
int> = 0>
264 KOKKOS_DEPRECATED KOKKOS_INLINE_FUNCTION
265 complex(
const volatile complex<RType>& src) noexcept
269 : re_(src.re_), im_(src.im_) {}
291 template <
class Complex,
292 std::enable_if_t<std::is_same<Complex, complex>::value,
int> = 0>
293 KOKKOS_DEPRECATED KOKKOS_INLINE_FUNCTION
void operator=(
294 const Complex& src)
volatile noexcept {
314 template <
class Complex,
315 std::enable_if_t<std::is_same<Complex, complex>::value,
int> = 0>
316 KOKKOS_DEPRECATED KOKKOS_INLINE_FUNCTION
volatile complex& operator=(
317 const volatile Complex& src)
volatile noexcept {
336 template <
class Complex,
337 std::enable_if_t<std::is_same<Complex, complex>::value,
int> = 0>
338 KOKKOS_DEPRECATED KOKKOS_INLINE_FUNCTION complex& operator=(
339 const volatile Complex& src) noexcept {
349 KOKKOS_DEPRECATED KOKKOS_INLINE_FUNCTION
void operator=(
350 const volatile RealType& val) noexcept {
358 KOKKOS_DEPRECATED KOKKOS_INLINE_FUNCTION complex& operator=(
359 const RealType& val)
volatile noexcept {
367 KOKKOS_DEPRECATED KOKKOS_INLINE_FUNCTION complex& operator=(
368 const volatile RealType& val)
volatile noexcept {
375 KOKKOS_DEPRECATED KOKKOS_INLINE_FUNCTION
volatile RealType&
376 imag() volatile noexcept {
381 KOKKOS_DEPRECATED KOKKOS_INLINE_FUNCTION
volatile RealType&
382 real() volatile noexcept {
387 KOKKOS_DEPRECATED KOKKOS_INLINE_FUNCTION RealType imag() const
393 KOKKOS_DEPRECATED KOKKOS_INLINE_FUNCTION RealType real() const
398 KOKKOS_DEPRECATED KOKKOS_INLINE_FUNCTION
void operator+=(
399 const volatile complex<RealType>& src)
volatile noexcept {
404 KOKKOS_DEPRECATED KOKKOS_INLINE_FUNCTION
void operator+=(
405 const volatile RealType& src)
volatile noexcept {
409 KOKKOS_DEPRECATED KOKKOS_INLINE_FUNCTION
void operator*=(
410 const volatile complex<RealType>& src)
volatile noexcept {
411 const RealType realPart = re_ * src.re_ - im_ * src.im_;
412 const RealType imagPart = re_ * src.im_ + im_ * src.re_;
418 KOKKOS_DEPRECATED KOKKOS_INLINE_FUNCTION
void operator*=(
419 const volatile RealType& src)
volatile noexcept {
423 #endif // KOKKOS_ENABLE_DEPRECATED_CODE_4
434 template <
class RealType1,
class RealType2>
435 KOKKOS_INLINE_FUNCTION
bool operator==(complex<RealType1>
const& x,
436 complex<RealType2>
const& y) noexcept {
437 using common_type = std::common_type_t<RealType1, RealType2>;
438 return common_type(x.real()) == common_type(y.real()) &&
439 common_type(x.imag()) == common_type(y.imag());
445 template <
class RealType1,
class RealType2>
446 inline bool operator==(std::complex<RealType1>
const& x,
447 complex<RealType2>
const& y) noexcept {
448 using common_type = std::common_type_t<RealType1, RealType2>;
449 return common_type(x.real()) == common_type(y.real()) &&
450 common_type(x.imag()) == common_type(y.imag());
454 template <
class RealType1,
class RealType2>
455 inline bool operator==(complex<RealType1>
const& x,
456 std::complex<RealType2>
const& y) noexcept {
457 using common_type = std::common_type_t<RealType1, RealType2>;
458 return common_type(x.real()) == common_type(y.real()) &&
459 common_type(x.imag()) == common_type(y.imag());
464 class RealType1,
class RealType2,
466 std::enable_if_t<std::is_convertible<RealType2, RealType1>::value,
int> = 0>
467 KOKKOS_INLINE_FUNCTION
bool operator==(complex<RealType1>
const& x,
468 RealType2
const& y) noexcept {
469 using common_type = std::common_type_t<RealType1, RealType2>;
470 return common_type(x.real()) == common_type(y) &&
471 common_type(x.imag()) == common_type(0);
476 class RealType1,
class RealType2,
478 std::enable_if_t<std::is_convertible<RealType1, RealType2>::value,
int> = 0>
479 KOKKOS_INLINE_FUNCTION
bool operator==(RealType1
const& x,
480 complex<RealType2>
const& y) noexcept {
481 using common_type = std::common_type_t<RealType1, RealType2>;
482 return common_type(x) == common_type(y.real()) &&
483 common_type(0) == common_type(y.imag());
487 template <
class RealType1,
class RealType2>
488 KOKKOS_INLINE_FUNCTION
bool operator!=(complex<RealType1>
const& x,
489 complex<RealType2>
const& y) noexcept {
490 using common_type = std::common_type_t<RealType1, RealType2>;
491 return common_type(x.real()) != common_type(y.real()) ||
492 common_type(x.imag()) != common_type(y.imag());
496 template <
class RealType1,
class RealType2>
497 inline bool operator!=(std::complex<RealType1>
const& x,
498 complex<RealType2>
const& y) noexcept {
499 using common_type = std::common_type_t<RealType1, RealType2>;
500 return common_type(x.real()) != common_type(y.real()) ||
501 common_type(x.imag()) != common_type(y.imag());
505 template <
class RealType1,
class RealType2>
506 inline bool operator!=(complex<RealType1>
const& x,
507 std::complex<RealType2>
const& y) noexcept {
508 using common_type = std::common_type_t<RealType1, RealType2>;
509 return common_type(x.real()) != common_type(y.real()) ||
510 common_type(x.imag()) != common_type(y.imag());
515 class RealType1,
class RealType2,
517 std::enable_if_t<std::is_convertible<RealType2, RealType1>::value,
int> = 0>
518 KOKKOS_INLINE_FUNCTION
bool operator!=(complex<RealType1>
const& x,
519 RealType2
const& y) noexcept {
520 using common_type = std::common_type_t<RealType1, RealType2>;
521 return common_type(x.real()) != common_type(y) ||
522 common_type(x.imag()) != common_type(0);
527 class RealType1,
class RealType2,
529 std::enable_if_t<std::is_convertible<RealType1, RealType2>::value,
int> = 0>
530 KOKKOS_INLINE_FUNCTION
bool operator!=(RealType1
const& x,
531 complex<RealType2>
const& y) noexcept {
532 using common_type = std::common_type_t<RealType1, RealType2>;
533 return common_type(x) != common_type(y.real()) ||
534 common_type(0) != common_type(y.imag());
541 template <
class RealType1,
class RealType2>
542 KOKKOS_INLINE_FUNCTION complex<std::common_type_t<RealType1, RealType2>>
543 operator+(
const complex<RealType1>& x,
const complex<RealType2>& y) noexcept {
544 return complex<std::common_type_t<RealType1, RealType2>>(x.real() + y.real(),
545 x.imag() + y.imag());
549 template <
class RealType1,
class RealType2>
550 KOKKOS_INLINE_FUNCTION complex<std::common_type_t<RealType1, RealType2>>
551 operator+(
const complex<RealType1>& x,
const RealType2& y) noexcept {
552 return complex<std::common_type_t<RealType1, RealType2>>(x.real() + y,
557 template <
class RealType1,
class RealType2>
558 KOKKOS_INLINE_FUNCTION complex<std::common_type_t<RealType1, RealType2>>
559 operator+(
const RealType1& x,
const complex<RealType2>& y) noexcept {
560 return complex<std::common_type_t<RealType1, RealType2>>(x + y.real(),
565 template <
class RealType>
566 KOKKOS_INLINE_FUNCTION complex<RealType> operator+(
567 const complex<RealType>& x) noexcept {
568 return complex<RealType>{+x.real(), +x.imag()};
572 template <
class RealType1,
class RealType2>
573 KOKKOS_INLINE_FUNCTION complex<std::common_type_t<RealType1, RealType2>>
574 operator-(
const complex<RealType1>& x,
const complex<RealType2>& y) noexcept {
575 return complex<std::common_type_t<RealType1, RealType2>>(x.real() - y.real(),
576 x.imag() - y.imag());
580 template <
class RealType1,
class RealType2>
581 KOKKOS_INLINE_FUNCTION complex<std::common_type_t<RealType1, RealType2>>
582 operator-(
const complex<RealType1>& x,
const RealType2& y) noexcept {
583 return complex<std::common_type_t<RealType1, RealType2>>(x.real() - y,
588 template <
class RealType1,
class RealType2>
589 KOKKOS_INLINE_FUNCTION complex<std::common_type_t<RealType1, RealType2>>
590 operator-(
const RealType1& x,
const complex<RealType2>& y) noexcept {
591 return complex<std::common_type_t<RealType1, RealType2>>(x - y.real(),
596 template <
class RealType>
597 KOKKOS_INLINE_FUNCTION complex<RealType> operator-(
598 const complex<RealType>& x) noexcept {
599 return complex<RealType>(-x.real(), -x.imag());
603 template <
class RealType1,
class RealType2>
604 KOKKOS_INLINE_FUNCTION complex<std::common_type_t<RealType1, RealType2>>
605 operator*(
const complex<RealType1>& x,
const complex<RealType2>& y) noexcept {
606 return complex<std::common_type_t<RealType1, RealType2>>(
607 x.real() * y.real() - x.imag() * y.imag(),
608 x.real() * y.imag() + x.imag() * y.real());
619 template <
class RealType1,
class RealType2>
620 inline complex<std::common_type_t<RealType1, RealType2>> operator*(
621 const std::complex<RealType1>& x,
const complex<RealType2>& y) {
622 return complex<std::common_type_t<RealType1, RealType2>>(
623 x.real() * y.real() - x.imag() * y.imag(),
624 x.real() * y.imag() + x.imag() * y.real());
631 template <
class RealType1,
class RealType2>
632 KOKKOS_INLINE_FUNCTION complex<std::common_type_t<RealType1, RealType2>>
633 operator*(
const RealType1& x,
const complex<RealType2>& y) noexcept {
634 return complex<std::common_type_t<RealType1, RealType2>>(x * y.real(),
642 template <
class RealType1,
class RealType2>
643 KOKKOS_INLINE_FUNCTION complex<std::common_type_t<RealType1, RealType2>>
644 operator*(
const complex<RealType1>& y,
const RealType2& x) noexcept {
645 return complex<std::common_type_t<RealType1, RealType2>>(x * y.real(),
650 template <
class RealType>
651 KOKKOS_INLINE_FUNCTION RealType imag(
const complex<RealType>& x) noexcept {
655 template <
class ArithmeticType>
656 KOKKOS_INLINE_FUNCTION constexpr Impl::promote_t<ArithmeticType> imag(
658 return ArithmeticType();
662 template <
class RealType>
663 KOKKOS_INLINE_FUNCTION RealType real(
const complex<RealType>& x) noexcept {
667 template <
class ArithmeticType>
668 KOKKOS_INLINE_FUNCTION constexpr Impl::promote_t<ArithmeticType> real(
675 KOKKOS_INLINE_FUNCTION complex<T> polar(
const T& r,
const T& theta = T()) {
676 KOKKOS_EXPECTS(r >= 0);
677 return complex<T>(r * cos(theta), r * sin(theta));
681 template <
class RealType>
682 KOKKOS_INLINE_FUNCTION RealType abs(
const complex<RealType>& x) {
683 return hypot(x.real(), x.imag());
688 KOKKOS_INLINE_FUNCTION complex<T> pow(
const complex<T>& x,
const T& y) {
690 T theta = atan2(x.imag(), x.real());
691 return polar(pow(r, y), y * theta);
695 KOKKOS_INLINE_FUNCTION complex<T> pow(
const T& x,
const complex<T>& y) {
696 return pow(complex<T>(x), y);
700 KOKKOS_INLINE_FUNCTION complex<T> pow(
const complex<T>& x,
701 const complex<T>& y) {
702 return x == T() ? T() : exp(y * log(x));
705 template <
class T,
class U,
706 class = std::enable_if_t<std::is_arithmetic<T>::value>>
707 KOKKOS_INLINE_FUNCTION complex<Impl::promote_2_t<T, U>> pow(
708 const T& x,
const complex<U>& y) {
709 using type = Impl::promote_2_t<T, U>;
710 return pow(type(x), complex<type>(y));
713 template <
class T,
class U,
714 class = std::enable_if_t<std::is_arithmetic<U>::value>>
715 KOKKOS_INLINE_FUNCTION complex<Impl::promote_2_t<T, U>> pow(
const complex<T>& x,
717 using type = Impl::promote_2_t<T, U>;
718 return pow(complex<type>(x), type(y));
721 template <
class T,
class U>
722 KOKKOS_INLINE_FUNCTION complex<Impl::promote_2_t<T, U>> pow(
723 const complex<T>& x,
const complex<U>& y) {
724 using type = Impl::promote_2_t<T, U>;
725 return pow(complex<type>(x), complex<type>(y));
730 template <
class RealType>
732 const complex<RealType>& x) {
733 RealType r = x.real();
734 RealType i = x.imag();
736 if (r == RealType()) {
737 RealType t = sqrt(fabs(i) / 2);
740 RealType t = sqrt(2 * (abs(x) + fabs(r)));
744 i < RealType() ? -u : u);
749 template <
class RealType>
750 KOKKOS_INLINE_FUNCTION complex<RealType> conj(
751 const complex<RealType>& x) noexcept {
752 return complex<RealType>(real(x), -imag(x));
755 template <
class ArithmeticType>
756 KOKKOS_INLINE_FUNCTION constexpr complex<Impl::promote_t<ArithmeticType>> conj(
758 using type = Impl::promote_t<ArithmeticType>;
759 return complex<type>(x, -type());
763 template <
class RealType>
764 KOKKOS_INLINE_FUNCTION complex<RealType> exp(
const complex<RealType>& x) {
765 return exp(x.real()) * complex<RealType>(cos(x.imag()), sin(x.imag()));
769 template <
class RealType>
771 const complex<RealType>& x) {
772 RealType phi = atan2(x.imag(), x.real());
777 template <
class RealType>
779 const complex<RealType>& x) {
780 return log(x) / log(RealType(10));
784 template <
class RealType>
786 const complex<RealType>& x) {
788 cos(x.real()) * sinh(x.imag()));
792 template <
class RealType>
794 const complex<RealType>& x) {
796 -sin(x.real()) * sinh(x.imag()));
800 template <
class RealType>
802 const complex<RealType>& x) {
803 return sin(x) / cos(x);
807 template <
class RealType>
809 const complex<RealType>& x) {
811 cosh(x.real()) * sin(x.imag()));
815 template <
class RealType>
817 const complex<RealType>& x) {
819 sinh(x.real()) * sin(x.imag()));
823 template <
class RealType>
825 const complex<RealType>& x) {
826 return sinh(x) / cosh(x);
830 template <
class RealType>
832 const complex<RealType>& x) {
833 return log(x + sqrt(x * x + RealType(1.0)));
837 template <
class RealType>
839 const complex<RealType>& x) {
840 return RealType(2.0) * log(sqrt(RealType(0.5) * (x + RealType(1.0))) +
841 sqrt(RealType(0.5) * (x - RealType(1.0))));
845 template <
class RealType>
847 const complex<RealType>& x) {
848 const RealType i2 = x.imag() * x.imag();
849 const RealType r = RealType(1.0) - i2 - x.real() * x.real();
851 RealType p = RealType(1.0) + x.real();
852 RealType m = RealType(1.0) - x.real();
857 RealType phi = atan2(RealType(2.0) * x.imag(), r);
859 RealType(0.5) * phi);
863 template <
class RealType>
865 const complex<RealType>& x) {
872 template <
class RealType>
874 const complex<RealType>& x) {
876 RealType pi_2 = acos(RealType(0.0));
881 template <
class RealType>
883 const complex<RealType>& x) {
884 const RealType r2 = x.real() * x.real();
885 const RealType i = RealType(1.0) - r2 - x.imag() * x.imag();
887 RealType p = x.imag() + RealType(1.0);
888 RealType m = x.imag() - RealType(1.0);
894 RealType(0.5) * atan2(RealType(2.0) * x.real(), i),
895 RealType(0.25) * log(p / m));
901 template <
class RealType>
902 inline complex<RealType> exp(
const std::complex<RealType>& c) {
903 return complex<RealType>(std::exp(c.real()) * std::cos(c.imag()),
904 std::exp(c.real()) * std::sin(c.imag()));
908 template <
class RealType1,
class RealType2>
909 KOKKOS_INLINE_FUNCTION complex<std::common_type_t<RealType1, RealType2>>
910 operator/(
const complex<RealType1>& x,
911 const RealType2& y) noexcept(noexcept(RealType1{} / RealType2{})) {
912 return complex<std::common_type_t<RealType1, RealType2>>(real(x) / y,
917 template <
class RealType1,
class RealType2>
918 KOKKOS_INLINE_FUNCTION complex<std::common_type_t<RealType1, RealType2>>
919 operator/(
const complex<RealType1>& x,
920 const complex<RealType2>& y) noexcept(noexcept(RealType1{} /
925 using common_real_type = std::common_type_t<RealType1, RealType2>;
926 const common_real_type s = fabs(real(y)) + fabs(imag(y));
932 return complex<common_real_type>(real(x) / s, imag(x) / s);
934 const complex<common_real_type> x_scaled(real(x) / s, imag(x) / s);
935 const complex<common_real_type> y_conj_scaled(real(y) / s, -imag(y) / s);
936 const RealType1 y_scaled_abs =
937 real(y_conj_scaled) * real(y_conj_scaled) +
938 imag(y_conj_scaled) * imag(y_conj_scaled);
939 complex<common_real_type> result = x_scaled * y_conj_scaled;
940 result /= y_scaled_abs;
946 template <
class RealType1,
class RealType2>
947 KOKKOS_INLINE_FUNCTION complex<std::common_type_t<RealType1, RealType2>>
948 operator/(
const RealType1& x,
949 const complex<RealType2>& y) noexcept(noexcept(RealType1{} /
951 return complex<std::common_type_t<RealType1, RealType2>>(x) / y;
954 template <
class RealType>
955 std::ostream& operator<<(std::ostream& os, const complex<RealType>& x) {
956 const std::complex<RealType> x_std(Kokkos::real(x), Kokkos::imag(x));
961 template <
class RealType>
962 std::istream& operator>>(std::istream& is, complex<RealType>& x) {
963 std::complex<RealType> x_std;
970 struct reduction_identity<Kokkos::complex<T>> {
971 using t_red_ident = reduction_identity<T>;
984 #ifdef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_COMPLEX
985 #undef KOKKOS_IMPL_PUBLIC_INCLUDE
986 #undef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_COMPLEX
988 #endif // KOKKOS_COMPLEX_HPP
KOKKOS_INLINE_FUNCTION constexpr void real(RealType v) noexcept
Set the real part of this complex number.
KOKKOS_INLINE_FUNCTION constexpr RealType & imag() noexcept
The imaginary part of this complex number.
Partial reimplementation of std::complex that works as the result of a Kokkos::parallel_reduce.
KOKKOS_INLINE_FUNCTION constexpr RealType real() const noexcept
The real part of this complex number.
KOKKOS_INLINE_FUNCTION complex & operator=(const RealType &val) noexcept
Assignment operator (from a real number).
KOKKOS_INLINE_FUNCTION complex(const RealType &val) noexcept
Constructor that takes just the real part, and sets the imaginary part to zero.
complex & operator=(const std::complex< RealType > &src) noexcept
Assignment operator from std::complex.
KOKKOS_INLINE_FUNCTION constexpr RealType & real() noexcept
The real part of this complex number.
KOKKOS_INLINE_FUNCTION complex(const RealType &re, const RealType &im) noexcept
Constructor that takes the real and imaginary parts.
KOKKOS_INLINE_FUNCTION constexpr RealType imag() const noexcept
The imaginary part of this complex number.
KOKKOS_INLINE_FUNCTION constexpr void imag(RealType v) noexcept
Set the imaginary part of this complex number.
KOKKOS_INLINE_FUNCTION complex(const std::complex< RealType > &src) noexcept
Conversion constructor from std::complex.
RealType value_type
The type of the real or imaginary parts of this complex number.