Skip to content

Commit

Permalink
Feature/log10 (#1265)
Browse files Browse the repository at this point in the history
  • Loading branch information
oelbert authored Jun 1, 2023
1 parent ab06f1e commit 68b6449
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
7 changes: 7 additions & 0 deletions dace/frontend/python/replacements.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
10 changes: 10 additions & 0 deletions dace/runtime/include/dace/cuda/cudacommon.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,15 @@ DACE_DFI dace::vec<float, 4> log(dace::vec<float, 4> v) {
return result;
}

DACE_DFI dace::vec<float, 4> log10(dace::vec<float, 4> v) {
dace::vec<float, 4> 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<float, 4> tanh(dace::vec<float, 4> v) {
dace::vec<float, 4> result;
result.x = tanh(v.x);
Expand All @@ -171,6 +180,7 @@ DACE_DFI dace::vec<float, 4> heaviside(const dace::vec<float, 4>& 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
Expand Down
5 changes: 5 additions & 0 deletions dace/runtime/include/dace/math.h
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,11 @@ namespace dace
{
return std::log(a);
}
template<typename T>
DACE_CONSTEXPR DACE_HDFI T log10(const T& a)
{
return std::log10(a);
}
}

namespace cmath
Expand Down
8 changes: 7 additions & 1 deletion tests/numpy/math_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -159,6 +164,7 @@ def func():
test_cosine()
test_square_root()
test_logarithm()
test_log10()
test_conjugate()
test_real_part()
test_imag_part()
Expand Down

0 comments on commit 68b6449

Please sign in to comment.