11#ifndef EIGEN_COMPLEX_CUDA_H
12#define EIGEN_COMPLEX_CUDA_H
33#if defined(EIGEN_CUDACC) && defined(EIGEN_GPU_COMPILE_PHASE)
42#if !(defined(EIGEN_COMP_ICC) && defined(_USE_COMPLEX_SPECIALIZATION_))
45#define EIGEN_USING_STD_COMPLEX_OPERATORS \
46 using Eigen::complex_operator_detail::operator+; \
47 using Eigen::complex_operator_detail::operator-; \
48 using Eigen::complex_operator_detail::operator*; \
49 using Eigen::complex_operator_detail::operator/; \
50 using Eigen::complex_operator_detail::operator+=; \
51 using Eigen::complex_operator_detail::operator-=; \
52 using Eigen::complex_operator_detail::operator*=; \
53 using Eigen::complex_operator_detail::operator/=; \
54 using Eigen::complex_operator_detail::operator==; \
55 using Eigen::complex_operator_detail::operator!=;
60namespace complex_operator_detail {
63EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
64std::complex<T> complex_multiply(
const std::complex<T>& a,
const std::complex<T>& b) {
65 const T a_real = numext::real(a);
66 const T a_imag = numext::imag(a);
67 const T b_real = numext::real(b);
68 const T b_imag = numext::imag(b);
69 return std::complex<T>(
70 a_real * b_real - a_imag * b_imag,
71 a_imag * b_real + a_real * b_imag);
75EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
76std::complex<T> complex_divide_fast(
const std::complex<T>& a,
const std::complex<T>& b) {
77 const T a_real = numext::real(a);
78 const T a_imag = numext::imag(a);
79 const T b_real = numext::real(b);
80 const T b_imag = numext::imag(b);
81 const T
norm = (b_real * b_real + b_imag * b_imag);
82 return std::complex<T>((a_real * b_real + a_imag * b_imag) /
norm,
83 (a_imag * b_real - a_real * b_imag) /
norm);
87EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
88std::complex<T> complex_divide_stable(
const std::complex<T>& a,
const std::complex<T>& b) {
89 const T a_real = numext::real(a);
90 const T a_imag = numext::imag(a);
91 const T b_real = numext::real(b);
92 const T b_imag = numext::imag(b);
95 const bool scale_imag = numext::abs(b_imag) <= numext::abs(b_real);
96 const T rscale = scale_imag ? T(1) : b_real / b_imag;
97 const T iscale = scale_imag ? b_imag / b_real : T(1);
98 const T denominator = b_real * rscale + b_imag * iscale;
99 return std::complex<T>((a_real * rscale + a_imag * iscale) / denominator,
100 (a_imag * rscale - a_real * iscale) / denominator);
104EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE
105std::complex<T> complex_divide(
const std::complex<T>& a,
const std::complex<T>& b) {
107 return complex_divide_fast(a, b);
109 return complex_divide_stable(a, b);
118#define EIGEN_CREATE_STD_COMPLEX_OPERATOR_SPECIALIZATIONS(T) \
120EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
121std::complex<T> operator+(const std::complex<T>& a) { return a; } \
123EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
124std::complex<T> operator-(const std::complex<T>& a) { \
125 return std::complex<T>(-numext::real(a), -numext::imag(a)); \
128EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
129std::complex<T> operator+(const std::complex<T>& a, const std::complex<T>& b) { \
130 return std::complex<T>(numext::real(a) + numext::real(b), numext::imag(a) + numext::imag(b)); \
133EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
134std::complex<T> operator+(const std::complex<T>& a, const T& b) { \
135 return std::complex<T>(numext::real(a) + b, numext::imag(a)); \
138EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
139std::complex<T> operator+(const T& a, const std::complex<T>& b) { \
140 return std::complex<T>(a + numext::real(b), numext::imag(b)); \
143EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
144std::complex<T> operator-(const std::complex<T>& a, const std::complex<T>& b) { \
145 return std::complex<T>(numext::real(a) - numext::real(b), numext::imag(a) - numext::imag(b)); \
148EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
149std::complex<T> operator-(const std::complex<T>& a, const T& b) { \
150 return std::complex<T>(numext::real(a) - b, numext::imag(a)); \
153EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
154std::complex<T> operator-(const T& a, const std::complex<T>& b) { \
155 return std::complex<T>(a - numext::real(b), -numext::imag(b)); \
158EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
159std::complex<T> operator*(const std::complex<T>& a, const std::complex<T>& b) { \
160 return complex_multiply(a, b); \
163EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
164std::complex<T> operator*(const std::complex<T>& a, const T& b) { \
165 return std::complex<T>(numext::real(a) * b, numext::imag(a) * b); \
168EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
169std::complex<T> operator*(const T& a, const std::complex<T>& b) { \
170 return std::complex<T>(a * numext::real(b), a * numext::imag(b)); \
173EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
174std::complex<T> operator/(const std::complex<T>& a, const std::complex<T>& b) { \
175 return complex_divide(a, b); \
178EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
179std::complex<T> operator/(const std::complex<T>& a, const T& b) { \
180 return std::complex<T>(numext::real(a) / b, numext::imag(a) / b); \
183EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
184std::complex<T> operator/(const T& a, const std::complex<T>& b) { \
185 return complex_divide(std::complex<T>(a, 0), b); \
188EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
189std::complex<T>& operator+=(std::complex<T>& a, const std::complex<T>& b) { \
190 numext::real_ref(a) += numext::real(b); \
191 numext::imag_ref(a) += numext::imag(b); \
195EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
196std::complex<T>& operator-=(std::complex<T>& a, const std::complex<T>& b) { \
197 numext::real_ref(a) -= numext::real(b); \
198 numext::imag_ref(a) -= numext::imag(b); \
202EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
203std::complex<T>& operator*=(std::complex<T>& a, const std::complex<T>& b) { \
204 a = complex_multiply(a, b); \
208EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
209std::complex<T>& operator/=(std::complex<T>& a, const std::complex<T>& b) { \
210 a = complex_divide(a, b); \
214EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
215bool operator==(const std::complex<T>& a, const std::complex<T>& b) { \
216 return numext::real(a) == numext::real(b) && numext::imag(a) == numext::imag(b); \
219EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
220bool operator==(const std::complex<T>& a, const T& b) { \
221 return numext::real(a) == b && numext::imag(a) == 0; \
224EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
225bool operator==(const T& a, const std::complex<T>& b) { \
226 return a == numext::real(b) && 0 == numext::imag(b); \
229EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
230bool operator!=(const std::complex<T>& a, const std::complex<T>& b) { \
234EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
235bool operator!=(const std::complex<T>& a, const T& b) { \
239EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE \
240bool operator!=(const T& a, const std::complex<T>& b) { \
245EIGEN_CREATE_STD_COMPLEX_OPERATOR_SPECIALIZATIONS(
float)
246EIGEN_CREATE_STD_COMPLEX_OPERATOR_SPECIALIZATIONS(
double)
248#undef EIGEN_CREATE_STD_COMPLEX_OPERATOR_SPECIALIZATIONS
253EIGEN_USING_STD_COMPLEX_OPERATORS
256EIGEN_USING_STD_COMPLEX_OPERATORS
260EIGEN_USING_STD_COMPLEX_OPERATORS
EIGEN_DEVICE_FUNC RealScalar norm() const
Definition Dot.h:103
Namespace containing all symbols from the Eigen library.
Definition LDLT.h:16