Skip to content

Commit 4df66fb

Browse files
authored
Merge pull request #9417 from guilhermeleobas/guilhermeleobas/cuda_np_log
Add np.log* bindings for CUDA
2 parents 03f2722 + fdc423f commit 4df66fb

5 files changed

Lines changed: 55 additions & 0 deletions

File tree

‎docs/source/cuda/cudapysupported.rst‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,9 @@ Supported NumPy features:
319319
* :func:`numpy.less_equal`
320320
* :func:`numpy.not_equal`
321321
* :func:`numpy.equal`
322+
* :func:`numpy.log`
323+
* :func:`numpy.log2`
324+
* :func:`numpy.log10`
322325
* :func:`numpy.logical_and`
323326
* :func:`numpy.logical_or`
324327
* :func:`numpy.logical_xor`
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Support math.log, math.log2 and math.log10 in CUDA
2+
--------------------------------------------------
3+
4+
CUDA target now supports ``np.log``, ``np.log2`` and ``np.log10``.

‎numba/cuda/cudadecl.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
register_numpy_ufunc,
66
trigonometric_functions,
77
comparison_functions,
8+
math_operations,
89
bit_twiddling_functions)
910
from numba.core.typing.templates import (AttributeTemplate, ConcreteTemplate,
1011
AbstractTemplate, CallableTemplate,
@@ -799,3 +800,7 @@ def resolve_local(self, mod):
799800

800801
for func in bit_twiddling_functions:
801802
register_numpy_ufunc(func, register_global)
803+
804+
for func in math_operations:
805+
if func in ('log', 'log2', 'log10'):
806+
register_numpy_ufunc(func, register_global)

‎numba/cuda/tests/cudapy/test_ufuncs.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,18 @@ def test_bitwise_not_ufunc(self):
260260
# when the second argument is a negative. See the comment in
261261
# numba/tests/test_ufuncs.py for more details.
262262

263+
############################################################################
264+
# Mathematical Functions
265+
266+
def test_log_ufunc(self):
267+
self.basic_ufunc_test(np.log, kinds='cf')
268+
269+
def test_log2_ufunc(self):
270+
self.basic_ufunc_test(np.log2, kinds='cf')
271+
272+
def test_log10_ufunc(self):
273+
self.basic_ufunc_test(np.log10, kinds='cf')
274+
263275

264276
if __name__ == '__main__':
265277
unittest.main()

‎numba/cuda/ufuncs.py‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ def np_binary_impl(fn, context, builder, sig, args):
3535
impl = get_binary_impl_for_fn_and_ty(fn, sig.args[0])
3636
return impl(context, builder, sig, args)
3737

38+
def np_real_log_impl(context, builder, sig, args):
39+
return np_unary_impl(math.log, context, builder, sig, args)
40+
41+
def np_real_log2_impl(context, builder, sig, args):
42+
return np_unary_impl(math.log2, context, builder, sig, args)
43+
44+
def np_real_log10_impl(context, builder, sig, args):
45+
return np_unary_impl(math.log10, context, builder, sig, args)
46+
3847
def np_real_sin_impl(context, builder, sig, args):
3948
return np_unary_impl(math.sin, context, builder, sig, args)
4049

@@ -628,4 +637,26 @@ def np_real_atanh_impl(context, builder, sig, args):
628637
'qq->q': numbers.int_shr_impl,
629638
'QQ->Q': numbers.int_shr_impl,
630639
}
640+
641+
db[np.log] = {
642+
'f->f': np_real_log_impl,
643+
'd->d': np_real_log_impl,
644+
'F->F': npyfuncs.np_complex_log_impl,
645+
'D->D': npyfuncs.np_complex_log_impl,
646+
}
647+
648+
db[np.log2] = {
649+
'f->f': np_real_log2_impl,
650+
'd->d': np_real_log2_impl,
651+
'F->F': npyfuncs.np_complex_log2_impl,
652+
'D->D': npyfuncs.np_complex_log2_impl,
653+
}
654+
655+
db[np.log10] = {
656+
'f->f': np_real_log10_impl,
657+
'd->d': np_real_log10_impl,
658+
'F->F': npyfuncs.np_complex_log10_impl,
659+
'D->D': npyfuncs.np_complex_log10_impl,
660+
}
661+
631662
return db

0 commit comments

Comments
 (0)