7#include <autodiff/common/numbertraits.hpp>
11 using ::Kokkos::complex;
20 using ::Kokkos::complex;
21 template <
typename T>
struct ArithmeticTraits<::Kokkos::complex<T>> : ArithmeticTraits<T> {
28 template <
typename T1,
typename T2>
29 requires(!std::is_same_v<T1, T2>) && std::is_arithmetic_v<T1> && std::is_arithmetic_v<T2>
30 KOKKOS_FORCEINLINE_FUNCTION
auto operator*(
const T1 x,
const complex<T2> y)
32 return complex<
decltype(T1(1.) * T2(1.))>(x * y.real(), x * y.imag());
34 template <
typename T1,
typename T2>
35 requires(!std::is_same_v<T1, T2>) && std::is_arithmetic_v<T1> && std::is_arithmetic_v<T2>
36 KOKKOS_FORCEINLINE_FUNCTION
auto operator*(
const complex<T1> &x,
const T2 &y)
38 return complex<
decltype(T1(1.) * T2(1.))>(y * x.real(), y * x.imag());
41 template <
typename T1,
typename T2>
42 requires(!std::is_same_v<T1, T2>) && std::is_arithmetic_v<T1> && std::is_arithmetic_v<T2>
43 KOKKOS_FORCEINLINE_FUNCTION
auto operator+(
const T1 &x,
const complex<T2> &y)
45 return complex<
decltype(T1(1.) + T2(1.))>(x + y.real(), y.imag());
47 template <
typename T1,
typename T2>
48 requires(!std::is_same_v<T1, T2>) && std::is_arithmetic_v<T1> && std::is_arithmetic_v<T2>
49 KOKKOS_FORCEINLINE_FUNCTION
auto operator+(
const complex<T1> &x,
const T2 &y)
51 return complex<
decltype(T1(1.) + T2(1.))>(x.real() + y, x.imag());
54 template <
typename T1,
typename T2>
55 requires(!std::is_same_v<T1, T2>) && std::is_arithmetic_v<T1> && std::is_arithmetic_v<T2>
56 KOKKOS_FORCEINLINE_FUNCTION
auto operator-(
const T1 &x,
const complex<T2> &y)
58 return complex<
decltype(T1(1.) - T2(1.))>(x - y.real(), -y.imag());
60 template <
typename T1,
typename T2>
61 requires(!std::is_same_v<T1, T2>) && std::is_arithmetic_v<T1> && std::is_arithmetic_v<T2>
62 KOKKOS_FORCEINLINE_FUNCTION
auto operator-(
const complex<T1> &x,
const T2 &y)
64 return complex<
decltype(T1(1.) - T2(1.))>(x.real() - y, x.imag());
67 template <
typename T1,
typename T2>
68 requires(!std::is_same_v<T1, T2>) && std::is_arithmetic_v<T1> && std::is_arithmetic_v<T2>
69 KOKKOS_FORCEINLINE_FUNCTION
auto operator/(
const T1 &x,
const complex<T2> &y)
71 return complex<
decltype(T1(1.) / T2(1.))>(x * y.real(), -x * y.imag()) / (powr<2>(y.real()) + powr<2>(y.imag()));
73 template <
typename T1,
typename T2>
74 requires(!std::is_same_v<T1, T2>) && std::is_arithmetic_v<T1> && std::is_arithmetic_v<T2>
75 KOKKOS_FORCEINLINE_FUNCTION
auto operator/(
const complex<T1> x,
const T2 &y)
77 return complex<
decltype(T1(1.) / T2(1.))>(x.real() / y, x.imag() / y);
82#include <autodiff/forward/real.hpp>
86 template <
size_t N,
typename T>
using cxReal = autodiff::Real<N, complex<T>>;
87 using cxreal = autodiff::Real<1, complex<double>>;
89 template <
typename T>
struct is_complex :
public std::false_type {
91 template <
typename T>
struct is_complex<complex<T>> :
public std::true_type {
93 template <
size_t N,
typename T>
struct is_complex<
cxReal<N, T>> :
public std::true_type {
96 template <
size_t N,
typename T> KOKKOS_FORCEINLINE_FUNCTION
auto real(
const autodiff::Real<N, T> &a) {
return a; }
97 template <
size_t N,
typename T>
constexpr KOKKOS_FORCEINLINE_FUNCTION
auto imag(
const autodiff::Real<N, T> &)
102 template <
size_t N,
typename T> KOKKOS_FORCEINLINE_FUNCTION
auto real(
const cxReal<N, T> &x)
104 autodiff::Real<N, T> res;
105 autodiff::detail::For<0, N + 1>([&](
auto i)
constexpr { res[i] =
real(x[i]); });
108 template <
size_t N,
typename T> KOKKOS_FORCEINLINE_FUNCTION
auto imag(
const cxReal<N, T> &x)
110 autodiff::Real<N, T> res;
111 autodiff::detail::For<0, N + 1>([&](
auto i)
constexpr { res[i] =
imag(x[i]); });
116 template <
size_t N,
typename T>
117 KOKKOS_FORCEINLINE_FUNCTION
auto operator*(
const autodiff::Real<N, T> &x,
const complex<double> &y)
120 autodiff::detail::For<0, N + 1>([&](
auto i)
constexpr { res[i] = x[i] * y; });
123 template <
size_t N,
typename T>
124 KOKKOS_FORCEINLINE_FUNCTION
auto operator*(
const complex<double> &x,
const autodiff::Real<N, T> &y)
127 autodiff::detail::For<0, N + 1>([&](
auto i)
constexpr { res[i] = x * y[i]; });
131 template <
size_t N,
typename T>
132 KOKKOS_FORCEINLINE_FUNCTION
auto operator+(
const autodiff::Real<N, T> &x,
const complex<double> &y)
136 autodiff::detail::For<1, N + 1>([&](
auto i)
constexpr { res[i] = x[i]; });
139 template <
size_t N,
typename T>
140 KOKKOS_FORCEINLINE_FUNCTION
auto operator+(
const complex<double> &x,
const autodiff::Real<N, T> &y)
144 autodiff::detail::For<1, N + 1>([&](
auto i)
constexpr { res[i] = y[i]; });
148 template <
size_t N,
typename T>
149 KOKKOS_FORCEINLINE_FUNCTION
auto operator-(
const autodiff::Real<N, T> &x,
const complex<double> &y)
153 autodiff::detail::For<1, N + 1>([&](
auto i)
constexpr { res[i] = x[i]; });
156 template <
size_t N,
typename T>
157 KOKKOS_FORCEINLINE_FUNCTION
auto operator-(
const complex<double> &x,
const autodiff::Real<N, T> &y)
161 autodiff::detail::For<1, N + 1>([&](
auto i)
constexpr { res[i] = -y[i]; });
165 template <
size_t N,
typename T>
166 KOKKOS_FORCEINLINE_FUNCTION
auto operator/(
const autodiff::Real<N, T> &x,
const complex<double> &y)
169 autodiff::detail::For<0, N + 1>([&](
auto i)
constexpr { res[i] = x[i] / y; });
172 template <
size_t N,
typename T>
173 KOKKOS_FORCEINLINE_FUNCTION
auto operator/(
const complex<double> &x,
const autodiff::Real<N, T> &y)
181 template <
size_t N,
typename T>
187 template <
size_t N,
typename T>
194 template <
size_t N,
typename T>
200 template <
size_t N,
typename T>
207 template <
size_t N,
typename T>
213 template <
size_t N,
typename T>
221 template <
size_t N,
typename T>
227 template <
size_t N,
typename T>
235 template <
size_t N,
typename T>
239 autodiff::detail::For<0, N + 1>([&](
auto i)
constexpr { res[i] = y[i] * x; });
242 template <
size_t N,
typename T>
246 autodiff::detail::For<0, N + 1>([&](
auto i)
constexpr { res[i] = x[i] * y; });
250 template <
size_t N,
typename T>
257 template <
size_t N,
typename T>
265 template <
size_t N,
typename T>
271 template <
size_t N,
typename T>
279 template <
size_t N,
typename T>
283 autodiff::detail::For<0, N + 1>([&](
auto i)
constexpr { res[i] = x[i] / y; });
286 template <
size_t N,
typename T>
299 autodiff::detail::For<N + 1>([&](
auto i)
constexpr {
300 res[i] -= autodiff::detail::Sum<0, i>([&](
auto j)
constexpr {
301 constexpr auto c = autodiff::detail::BinomialCoefficient<i.index, j.index>;
302 return c * res[j] * y[i - j];
Definition complex_math.hh:10
KOKKOS_FORCEINLINE_FUNCTION auto operator/(const autodiff::Real< N, T > &x, const complex< double > &y)
Definition complex_math.hh:166
KOKKOS_FORCEINLINE_FUNCTION auto operator+(const autodiff::Real< N, T > &x, const complex< double > &y)
Definition complex_math.hh:132
autodiff::Real< 1, complex< double > > cxreal
Definition complex_math.hh:87
constexpr KOKKOS_FORCEINLINE_FUNCTION auto imag(const autodiff::Real< N, T > &)
Definition complex_math.hh:97
KOKKOS_FORCEINLINE_FUNCTION auto operator-(const autodiff::Real< N, T > &x, const complex< double > &y)
Definition complex_math.hh:149
KOKKOS_FORCEINLINE_FUNCTION auto operator*(const autodiff::Real< N, T > &x, const complex< double > &y)
Definition complex_math.hh:117
KOKKOS_FORCEINLINE_FUNCTION auto real(const autodiff::Real< N, T > &a)
Definition complex_math.hh:96
autodiff::Real< N, complex< T > > cxReal
Definition complex_math.hh:86
Definition complex_math.hh:19
Definition complex_math.hh:89