Skip to content

Commit

Permalink
Add np.ndarray.ptp() support.
Browse files Browse the repository at this point in the history
As title, just wiring.

Fixes numba#6257
  • Loading branch information
stuartarchibald committed Sep 21, 2020
1 parent 3b3eab8 commit 9127582
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions numba/np/arraymath.py
Original file line number Diff line number Diff line change
Expand Up @@ -1106,6 +1106,7 @@ def impl(val):
return impl


@overload_method(types.Array, 'ptp')
@overload(np.ptp)
def np_ptp(a):

Expand Down
14 changes: 14 additions & 0 deletions numba/tests/test_array_reductions.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ def array_nanpercentile_global(arr, q):
def array_ptp_global(a):
return np.ptp(a)

def array_ptp(a):
return a.ptp()

def array_quantile_global(arr, q):
return np.quantile(arr, q)

Expand Down Expand Up @@ -797,6 +800,17 @@ def a_variations():
for a in a_variations():
check(a)

def test_ptp_method(self):
# checks wiring of np.ndarray.ptp() only, `np.ptp` test above checks
# the actual alg
pyfunc = array_ptp
cfunc = jit(nopython=True)(pyfunc)

a = np.arange(10)
expected = pyfunc(a)
got = cfunc(a)
self.assertPreciseEqual(expected, got)

def test_ptp_complex(self):
pyfunc = array_ptp_global
cfunc = jit(nopython=True)(pyfunc)
Expand Down

0 comments on commit 9127582

Please sign in to comment.