diff --git a/dace/frontend/python/replacements.py b/dace/frontend/python/replacements.py index 3e0ff554d5..3586d40374 100644 --- a/dace/frontend/python/replacements.py +++ b/dace/frontend/python/replacements.py @@ -692,6 +692,13 @@ def _log(pv: ProgramVisitor, sdfg: SDFG, state: SDFGState, input: str): return _simple_call(sdfg, state, input, 'log') +@oprepo.replaces('log10') +@oprepo.replaces('dace.log10') +@oprepo.replaces('math.log10') +def _log10(pv: ProgramVisitor, sdfg: SDFG, state: SDFGState, input: str): + return _simple_call(sdfg, state, input, 'log10') + + @oprepo.replaces('math.floor') def _floor(pv: ProgramVisitor, sdfg: SDFG, state: SDFGState, input: str): return _simple_call(sdfg, state, input, 'floor', restype=dtypes.typeclass(int)) diff --git a/dace/runtime/include/dace/cuda/cudacommon.cuh b/dace/runtime/include/dace/cuda/cudacommon.cuh index ae34da918b..3c050f9d75 100644 --- a/dace/runtime/include/dace/cuda/cudacommon.cuh +++ b/dace/runtime/include/dace/cuda/cudacommon.cuh @@ -151,6 +151,15 @@ DACE_DFI dace::vec log(dace::vec v) { return result; } +DACE_DFI dace::vec log10(dace::vec v) { + dace::vec result; + result.x = log10(v.x); + result.y = log10(v.y); + result.z = log10(v.z); + result.w = log10(v.w); + return result; +} + DACE_DFI dace::vec tanh(dace::vec v) { dace::vec result; result.x = tanh(v.x); @@ -171,6 +180,7 @@ DACE_DFI dace::vec heaviside(const dace::vec& a) { } } // namespace dace::math using dace::math::exp; using dace::math::log; +using dace::math::log10; using dace::math::tanh; using dace::math::heaviside; #endif diff --git a/dace/runtime/include/dace/math.h b/dace/runtime/include/dace/math.h index a1f501e4da..aa4dcb358d 100644 --- a/dace/runtime/include/dace/math.h +++ b/dace/runtime/include/dace/math.h @@ -569,6 +569,11 @@ namespace dace { return std::log(a); } + template + DACE_CONSTEXPR DACE_HDFI T log10(const T& a) + { + return std::log10(a); + } } namespace cmath diff --git a/tests/numpy/math_test.py b/tests/numpy/math_test.py index e96e1dbeae..5e241ebb48 100644 --- a/tests/numpy/math_test.py +++ b/tests/numpy/math_test.py @@ -3,7 +3,7 @@ import dace from common import compare_numpy_output import math -from numpy import exp, sin, cos, sqrt, log, conj, real, imag +from numpy import exp, sin, cos, sqrt, log, log10, conj, real, imag import pytest M, N = 24, 24 @@ -34,6 +34,11 @@ def test_logarithm(A: dace.complex64[M, N]): return log(A) +@compare_numpy_output(non_zero=True, positive=True) +def test_log10(A: dace.complex64[M, N]): + return log10(A) + + @compare_numpy_output() def test_conjugate(A: dace.complex64[M, N]): return conj(A) @@ -159,6 +164,7 @@ def func(): test_cosine() test_square_root() test_logarithm() + test_log10() test_conjugate() test_real_part() test_imag_part()