Skip to content

Commit

Permalink
Merge pull request #9416 from guilhermeleobas/guilhermeleobas/cpu_mat…
Browse files Browse the repository at this point in the history
…h_log2

Add math.log2 support
  • Loading branch information
sklam committed Mar 15, 2024
2 parents 581a893 + a819f10 commit 147c641
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/source/reference/pysupported.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1074,6 +1074,7 @@ The following functions from the :mod:`math` module are supported:
* :func:`math.ldexp`
* :func:`math.lgamma`
* :func:`math.log`
* :func:`math.log2`
* :func:`math.log10`
* :func:`math.log1p`
* :func:`math.pow`
Expand Down
4 changes: 4 additions & 0 deletions docs/upcoming_changes/9416.new_feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Add support for ``math.log2``.
------------------------------

Support for ``math.log2`` is added.
1 change: 1 addition & 0 deletions numba/core/typing/mathdecl.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
@infer_global(math.log)
@infer_global(math.log1p)
@infer_global(math.log10)
@infer_global(math.log2)
@infer_global(math.sin)
@infer_global(math.cos)
@infer_global(math.tan)
Expand Down
1 change: 1 addition & 0 deletions numba/cpython/mathimpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ def float_impl(context, builder, sig, args):
exp_impl = unary_math_intr(math.exp, 'llvm.exp')
log_impl = unary_math_intr(math.log, 'llvm.log')
log10_impl = unary_math_intr(math.log10, 'llvm.log10')
log2_impl = unary_math_intr(math.log2, 'llvm.log2')
sin_impl = unary_math_intr(math.sin, 'llvm.sin')
cos_impl = unary_math_intr(math.cos, 'llvm.cos')

Expand Down
12 changes: 12 additions & 0 deletions numba/tests/test_mathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ def log10(x):
return math.log10(x)


def log2(x):
return math.log2(x)


def floor(x):
return math.floor(x)

Expand Down Expand Up @@ -285,6 +289,14 @@ def test_log10(self):
x_values = [1, 10, 100, 1000, 100000, 1000000, 0.1, 1.1]
self.run_unary(pyfunc, x_types, x_values)

def test_log2(self):
pyfunc = log2
x_types = [types.int16, types.int32, types.int64,
types.uint16, types.uint32, types.uint64,
types.float32, types.float64]
x_values = [1, 10, 100, 1000, 100000, 1000000, 0.1, 1.1]
self.run_unary(pyfunc, x_types, x_values)

def test_asin(self):
pyfunc = asin
x_types = [types.int16, types.int32, types.int64,
Expand Down

0 comments on commit 147c641

Please sign in to comment.