Skip to content

Commit f402a56

Browse files
Replace overlooked std::log, std::sinh, std::exp for complex types
Replaced them with uses of sycl::ext::oneapi::experimental namespace functions instead.
1 parent 5e3f3c5 commit f402a56

File tree

7 files changed

+34
-25
lines changed

7 files changed

+34
-25
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,11 @@ template <typename argT, typename resT> struct AcosFunctor
105105
constexpr realT r_eps =
106106
realT(1) / std::numeric_limits<realT>::epsilon();
107107
if (std::abs(x) > r_eps || std::abs(y) > r_eps) {
108-
argT log_in = std::log(in);
108+
using sycl_complexT = exprm_ns::complex<realT>;
109+
sycl_complexT log_in = exprm_ns::log(exprm_ns::complex<realT>(in));
109110

110-
const realT wx = std::real(log_in);
111-
const realT wy = std::imag(log_in);
111+
const realT wx = log_in.real();
112+
const realT wy = log_in.imag();
112113
const realT rx = std::abs(wy);
113114

114115
realT ry = wx + std::log(realT(2));

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ namespace acosh
4848

4949
namespace py = pybind11;
5050
namespace td_ns = dpctl::tensor::type_dispatch;
51-
namespace cmplx_ns = sycl::ext::oneapi::experimental;
51+
namespace exprm_ns = sycl::ext::oneapi::experimental;
5252

5353
using dpctl::tensor::type_utils::is_complex;
5454

@@ -112,16 +112,18 @@ template <typename argT, typename resT> struct AcoshFunctor
112112
* For large x or y including acos(+-Inf + I*+-Inf)
113113
*/
114114
if (std::abs(x) > r_eps || std::abs(y) > r_eps) {
115-
const realT wx = std::real(std::log(in));
116-
const realT wy = std::imag(std::log(in));
115+
using sycl_complexT = typename exprm_ns::complex<realT>;
116+
const sycl_complexT log_in = exprm_ns::log(sycl_complexT(in));
117+
const realT wx = log_in.real();
118+
const realT wy = log_in.imag();
117119
const realT rx = std::abs(wy);
118120
realT ry = wx + std::log(realT(2));
119121
acos_in = resT{rx, (std::signbit(y)) ? ry : -ry};
120122
}
121123
else {
122124
/* ordinary cases */
123-
acos_in = cmplx_ns::acos(
124-
cmplx_ns::complex<realT>(in)); // std::acos(in);
125+
acos_in = exprm_ns::acos(
126+
exprm_ns::complex<realT>(in)); // std::acos(in);
125127
}
126128

127129
/* Now we calculate acosh(z) */

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,17 +119,18 @@ template <typename argT, typename resT> struct AsinFunctor
119119
constexpr realT r_eps =
120120
realT(1) / std::numeric_limits<realT>::epsilon();
121121
if (std::abs(x) > r_eps || std::abs(y) > r_eps) {
122-
const resT z = {x, y};
122+
using sycl_complexT = exprm_ns::complex<realT>;
123+
const sycl_complexT z {x, y};
123124
realT wx, wy;
124125
if (!std::signbit(x)) {
125-
auto log_z = std::log(z);
126-
wx = std::real(log_z) + std::log(realT(2));
127-
wy = std::imag(log_z);
126+
auto log_z = exprm_ns::log(z);
127+
wx = log_z.real() + std::log(realT(2));
128+
wy = log_z.imag();
128129
}
129130
else {
130-
auto log_mz = std::log(-z);
131-
wx = std::real(log_mz) + std::log(realT(2));
132-
wy = std::imag(log_mz);
131+
auto log_mz = exprm_ns::log(-z);
132+
wx = log_mz.real() + std::log(realT(2));
133+
wy = log_mz.imag();
133134
}
134135
const realT asinh_re = std::copysign(wx, x);
135136
const realT asinh_im = std::copysign(wy, y);

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,12 @@ template <typename argT, typename resT> struct AsinhFunctor
108108
realT(1) / std::numeric_limits<realT>::epsilon();
109109

110110
if (std::abs(x) > r_eps || std::abs(y) > r_eps) {
111-
resT log_in = (std::signbit(x)) ? std::log(-in) : std::log(in);
112-
realT wx = std::real(log_in) + std::log(realT(2));
113-
realT wy = std::imag(log_in);
111+
using sycl_complexT = exprm_ns::complex<realT>;
112+
sycl_complexT log_in = (std::signbit(x)) ?
113+
exprm_ns::log(sycl_complexT(-in)) :
114+
exprm_ns::log(sycl_complexT(in));
115+
realT wx = log_in.real() + std::log(realT(2));
116+
realT wy = log_in.imag();
114117
const realT res_re = std::copysign(wx, x);
115118
const realT res_im = std::copysign(wy, y);
116119
return resT{res_re, res_im};

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@
2424
//===---------------------------------------------------------------------===//
2525

2626
#pragma once
27-
#include <CL/sycl.hpp>
2827
#include <cmath>
2928
#include <cstddef>
3029
#include <cstdint>
30+
#include <sycl/ext/oneapi/experimental/sycl_complex.hpp>
31+
#include <sycl/sycl.hpp>
3132
#include <type_traits>
3233

3334
#include "kernels/elementwise_functions/common.hpp"
@@ -48,6 +49,7 @@ namespace exp2
4849

4950
namespace py = pybind11;
5051
namespace td_ns = dpctl::tensor::type_dispatch;
52+
namespace exprm_ns = sycl::ext::oneapi::experimental;
5153

5254
using dpctl::tensor::type_utils::is_complex;
5355

@@ -76,7 +78,7 @@ template <typename argT, typename resT> struct Exp2Functor
7678
const realT y = std::imag(tmp);
7779
if (std::isfinite(x)) {
7880
if (std::isfinite(y)) {
79-
return std::exp(tmp);
81+
return exprm_ns::exp(exprm_ns::complex<realT>(tmp));
8082
}
8183
else {
8284
return resT{q_nan, q_nan};

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ namespace sin
4848

4949
namespace py = pybind11;
5050
namespace td_ns = dpctl::tensor::type_dispatch;
51-
namespace cmplx_ns = sycl::ext::oneapi::experimental;
51+
namespace exprm_ns = sycl::ext::oneapi::experimental;
5252

5353
using dpctl::tensor::type_utils::is_complex;
5454

@@ -81,8 +81,8 @@ template <typename argT, typename resT> struct SinFunctor
8181
* real and imaginary parts of input are finite.
8282
*/
8383
if (in_re_finite && in_im_finite) {
84-
return cmplx_ns::sin(
85-
cmplx_ns::complex<realT>(in)); // std::sin(in);
84+
return exprm_ns::sin(
85+
exprm_ns::complex<realT>(in)); // std::sin(in);
8686
}
8787

8888
/*

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ namespace sinh
4848

4949
namespace py = pybind11;
5050
namespace td_ns = dpctl::tensor::type_dispatch;
51-
namespace cmplx_ns = sycl::ext::oneapi::experimental;
51+
namespace exprm_ns = sycl::ext::oneapi::experimental;
5252

5353
using dpctl::tensor::type_utils::is_complex;
5454

@@ -81,7 +81,7 @@ template <typename argT, typename resT> struct SinhFunctor
8181
* real and imaginary parts of input are finite.
8282
*/
8383
if (xfinite && yfinite) {
84-
return std::sinh(in);
84+
return exprm_ns::sinh(exprm_ns::complex<realT>(in));
8585
}
8686
/*
8787
* sinh(+-0 +- I Inf) = sign(d(+-0, dNaN))0 + I dNaN.

0 commit comments

Comments
 (0)