File tree Expand file tree Collapse file tree 2 files changed +10
-5
lines changed
dpctl/tensor/libtensor/include/kernels/elementwise_functions Expand file tree Collapse file tree 2 files changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -69,6 +69,8 @@ template <typename argT, typename resT> struct TanFunctor
69
69
if constexpr (is_complex<argT>::value) {
70
70
71
71
using realT = typename argT::value_type;
72
+
73
+ constexpr realT q_nan = std::numeric_limits<realT>::quiet_NaN ();
72
74
/*
73
75
* since tan(in) = -I * tanh(I * in), for special cases,
74
76
* we calculate real and imaginary parts of z = tanh(I * in) and
@@ -111,9 +113,9 @@ template <typename argT, typename resT> struct TanFunctor
111
113
*/
112
114
if (!std::isfinite (y)) {
113
115
if (x == realT (0 )) {
114
- return resT{y - y , x};
116
+ return resT{q_nan , x};
115
117
}
116
- return resT{y - y, y - y };
118
+ return resT{q_nan, q_nan };
117
119
}
118
120
/* ordinary cases */
119
121
return std::tan (in);
Original file line number Diff line number Diff line change @@ -69,6 +69,9 @@ template <typename argT, typename resT> struct TanhFunctor
69
69
{
70
70
if constexpr (is_complex<argT>::value) {
71
71
using realT = typename argT::value_type;
72
+
73
+ constexpr realT q_nan = std::numeric_limits<realT>::quiet_NaN ();
74
+
72
75
const realT x = std::real (in);
73
76
const realT y = std::imag (in);
74
77
/*
@@ -89,7 +92,7 @@ template <typename argT, typename resT> struct TanhFunctor
89
92
*/
90
93
if (!std::isfinite (x)) {
91
94
if (std::isnan (x)) {
92
- return resT{x , (y == realT (0 ) ? y : x * y )};
95
+ return resT{q_nan , (y == realT (0 ) ? y : q_nan )};
93
96
}
94
97
const realT res_re = std::copysign (realT (1 ), x);
95
98
const realT res_im = std::copysign (
@@ -104,9 +107,9 @@ template <typename argT, typename resT> struct TanhFunctor
104
107
*/
105
108
if (!std::isfinite (y)) {
106
109
if (x == realT (0 )) {
107
- return resT{x, y - y };
110
+ return resT{x, q_nan };
108
111
}
109
- return resT{y - y, y - y };
112
+ return resT{q_nan, q_nan };
110
113
}
111
114
/* ordinary cases */
112
115
return std::tanh (in);
You can’t perform that action at this time.
0 commit comments