File tree Expand file tree Collapse file tree 2 files changed +12
-14
lines changed
dpctl/tensor/libtensor/include/kernels/elementwise_functions Expand file tree Collapse file tree 2 files changed +12
-14
lines changed Original file line number Diff line number Diff line change @@ -70,18 +70,16 @@ template <typename argT, typename resT> struct Expm1Functor
70
70
using realT = typename argT::value_type;
71
71
// expm1(x + I*y) = expm1(x)*cos(y) - 2*sin(y / 2)^2 +
72
72
// I*exp(x)*sin(y)
73
- auto x = std::real (in);
74
- const realT expm1X_val = std::expm1 (x);
75
- const realT expX_val = std::exp (x);
73
+ const realT x = std::real (in);
74
+ const realT y = std::imag (in);
76
75
77
- x = std::imag (in);
78
76
realT cosY_val;
79
- const realT sinY_val = sycl::sincos (x , &cosY_val);
80
- const realT sinhalfY_val = std::sin (x / realT{ 2 } );
77
+ const realT sinY_val = sycl::sincos (y , &cosY_val);
78
+ const realT sinhalfY_val = std::sin (y / 2 );
81
79
82
80
const realT res_re =
83
- expm1X_val * cosY_val - realT{ 2 } * sinhalfY_val * sinhalfY_val;
84
- const realT res_im = expX_val * sinY_val;
81
+ std::expm1 (x) * cosY_val - 2 * sinhalfY_val * sinhalfY_val;
82
+ const realT res_im = std::exp (x) * sinY_val;
85
83
return resT{res_re, res_im};
86
84
}
87
85
else {
Original file line number Diff line number Diff line change @@ -80,17 +80,17 @@ template <typename argT, typename resT> struct Log1pFunctor
80
80
const realT y = std::imag (in);
81
81
82
82
// imaginary part of result
83
- const realT imagRes = std::atan2 (y, x + 1 );
83
+ const realT res_im = std::atan2 (y, x + 1 );
84
84
85
- if (std::abs (in) < realT (.5 )) {
86
- const realT realRes = x * (2 + x) + y * y;
87
- return {std::log1p (realRes ) / 2 , imagRes };
85
+ if (std::max ( std:: abs (x), std::abs (y)) < realT (.1 )) {
86
+ const realT v = x * (2 + x) + y * y;
87
+ return {std::log1p (v ) / 2 , res_im };
88
88
}
89
89
else {
90
90
// when not close to zero,
91
91
// prevent overflow
92
- const realT realRes = std::hypot (x + 1 , y);
93
- return {std::log (realRes ), imagRes };
92
+ const realT m = std::hypot (x + 1 , y);
93
+ return {std::log (m ), res_im };
94
94
}
95
95
}
96
96
else {
You can’t perform that action at this time.
0 commit comments