Skip to content

Commit 345fdaa

Browse files
Closes gh-1278
Provides an alternative implementation of std::abs for complex types via std::hypot which is used on Windows.
1 parent 50f1074 commit 345fdaa

File tree

1 file changed

+18
-1
lines changed
  • dpctl/tensor/libtensor/include/kernels/elementwise_functions

1 file changed

+18
-1
lines changed

dpctl/tensor/libtensor/include/kernels/elementwise_functions/abs.hpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#pragma once
2626
#include <CL/sycl.hpp>
2727
#include <cmath>
28+
#include <complex>
2829
#include <cstddef>
2930
#include <cstdint>
3031
#include <type_traits>
@@ -72,9 +73,25 @@ template <typename argT, typename resT> struct AbsFunctor
7273
return x;
7374
}
7475
else {
75-
return std::abs(x);
76+
if constexpr (is_complex<argT>::value) {
77+
return cabs(x);
78+
}
79+
else {
80+
return std::abs(x);
81+
}
7682
}
7783
}
84+
85+
private:
86+
template <typename realT> realT cabs(std::complex<realT> const &z)
87+
{
88+
#ifdef _WINDOWS
89+
// work-around for gh-1279
90+
return std::hypot(std::real(z), std::imag(z));
91+
#else
92+
return std::abs(z);
93+
#endif
94+
}
7895
};
7996

8097
template <typename argT,

0 commit comments

Comments
 (0)