diff --git a/pycuda/cuda/pycuda-complex-impl.hpp b/pycuda/cuda/pycuda-complex-impl.hpp index d2e67605a3b00c10416b89793ed7858fa47098ee..68e6f01a9d283b0d7a09fe71cbe64eb02db7067c 100644 --- a/pycuda/cuda/pycuda-complex-impl.hpp +++ b/pycuda/cuda/pycuda-complex-impl.hpp @@ -173,9 +173,12 @@ __device__ complex exp(const complex& z) __device__ complex exp(const complex& z) { return expT(z); } -#if 0 //---------------------------------------------------------------------- // log10 + +__device__ constexpr float log10_invf() { return 1.f / ::log(10.f); } +__device__ constexpr double log10_inv() { return 1.0 / ::log(10.); } + template static __device__ complex<_Tp> log10T(const complex<_Tp>& z, const _Tp& ln10_inv) { complex<_Tp> r; @@ -185,15 +188,11 @@ static __device__ complex<_Tp> log10T(const complex<_Tp>& z, const _Tp& ln10_inv return r; } -static const float LN10_INVF = 1.f / ::log(10.f); __device__ complex log10(const complex& z) -{ return log10T(z, LN10_INVF); } +{ return log10T(z, log10_invf()); } -static const double LN10_INV = 1. / ::log10(10.); __device__ complex log10(const complex& z) -{ return log10T(z, LN10_INV); } - -#endif +{ return log10T(z, log10_inv()); } //---------------------------------------------------------------------- // log diff --git a/test/test_gpuarray.py b/test/test_gpuarray.py index cce2de92f93bcc31d508b226655b06ca3a5b9cde..d4e03f7d154021cfdeb5adf327c0469185d554e2 100644 --- a/test/test_gpuarray.py +++ b/test/test_gpuarray.py @@ -1380,6 +1380,17 @@ class TestGPUArray: a[...] = 1729 np.testing.assert_allclose(a.get(), 1729) + @pytest.mark.parametrize("dtype,rtol", [(np.complex64, 1e-6), + (np.complex128, 1e-14)]) + def test_log10(self, dtype, rtol): + from pycuda import cumath + + rng = np.random.default_rng(seed=0) + x_np = rng.random((10, 4)) + dtype(1j)*rng.random((10, 4)) + x_cu = gpuarray.to_gpu(x_np) + np.testing.assert_allclose(cumath.log10(x_cu).get(), np.log10(x_np), + rtol=rtol) + if __name__ == "__main__": # make sure that import failures get reported, instead of skipping the tests.