Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
bf1e335
Move utility method out, so it can be used by other modules.
itamarst Jun 21, 2021
4582bc8
A sketch of sorts.
itamarst Jun 30, 2021
b82dd24
A bit closer to working, maybe.
itamarst Jul 2, 2021
0cc9d7c
Even closer, maybe.
itamarst Jul 2, 2021
ada5b42
Actually works for some values.
itamarst Jul 7, 2021
372e34c
Fix off by one bug that caused segfaults for some axis.
itamarst Jul 7, 2021
d7c7985
Some documentation and comments for np.take_along_axis.
itamarst Jul 9, 2021
df2f29a
Tests for error cases of np.take_along_axis.
itamarst Jul 9, 2021
fe60ca9
Fix axis=None case.
itamarst Jul 9, 2021
d95a4bd
More test cases for np.take_along_axis().
itamarst Jul 9, 2021
0fcfb09
Tests (and corresponding bug fix) for take_along_axis() semantics.
itamarst Jul 12, 2021
dcab297
Fix flakes.
itamarst Jul 27, 2021
0dc3b76
Merge branch 'master' into np-take_along_axis
itamarst Aug 10, 2021
e759d98
Sometimes we take NumPy code from examples or other parts of the docu…
itamarst Aug 10, 2021
75ded55
Function was renamed.
itamarst Aug 10, 2021
da3b6e4
More succinct testing strategy
itamarst Aug 18, 2021
cfc28ed
Better explanation
itamarst Aug 18, 2021
7a70596
Point to stable location, in source code.
itamarst Aug 18, 2021
1ae5f53
Get rid of additional, erroneous outer loop.
itamarst Aug 18, 2021
b676024
Bounds check is up to user.
itamarst Aug 18, 2021
dbcf274
These functions will only ever be used from JITed code.
itamarst Aug 18, 2021
9ec64da
Minor optimization.
itamarst Aug 18, 2021
bd64769
Bit nicer testing.
itamarst Aug 18, 2021
7e65814
More input validation.
itamarst Aug 18, 2021
ede8d01
Flakes.
itamarst Aug 18, 2021
c86836a
A failing test.
itamarst Aug 18, 2021
f7b94d9
Get rid of combinatoric code repetition by doing a little song and da…
itamarst Aug 30, 2021
4ee6bb2
Better explanation.
itamarst Aug 30, 2021
b951a63
Merge remote-tracking branch 'origin/master' into np-take_along_axis
itamarst Aug 30, 2021
fd3c73d
Support for pre-broadcasting.
itamarst Aug 30, 2021
1d180d5
Additional tests for new broadcasting support.
itamarst Aug 30, 2021
47a32e9
Flake fixes.
itamarst Aug 30, 2021
dbedd9c
Apply suggestions from code review
itamarst Sep 13, 2021
01f9c9f
Fix flake.
itamarst Sep 13, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Move utility method out, so it can be used by other modules.
  • Loading branch information
itamarst committed Jun 21, 2021
commit bf1e3358fb1e0f22528fe93950ebc792adb31731
33 changes: 14 additions & 19 deletions numba/np/arraymath.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from numba.core.extending import overload, overload_method, register_jitable
from numba.np.numpy_support import as_dtype, type_can_asarray
from numba.np.numpy_support import numpy_version
from numba.np.numpy_support import is_nonelike
from numba.np.numpy_support import is_nonelike, check_is_integer
from numba.core.imputils import (lower_builtin, impl_ret_borrowed,
impl_ret_new_ref, impl_ret_untracked)
from numba.core.typing import signature
Expand Down Expand Up @@ -785,7 +785,7 @@ def array_argmax(arr, axis=None):
def array_argmax_impl(arr, axis=None):
return flatten_impl(arr)
else:
_check_is_integer(axis, "axis")
check_is_integer(axis, "axis")
retty = arr.dtype

tuple_buffer = tuple(range(arr.ndim))
Expand Down Expand Up @@ -957,11 +957,6 @@ def check_array(a):
raise ValueError('zero-size array to reduction operation not possible')


def _check_is_integer(v, name):
if not isinstance(v, (int, types.Integer)):
raise TypingError('{} must be an integer'.format(name))


def nan_min_max_factory(comparison_op, is_complex_dtype):
if is_complex_dtype:
def impl(a):
Expand Down Expand Up @@ -1695,7 +1690,7 @@ def _tri_impl(N, M, k):
def np_tri(N, M=None, k=0):

# we require k to be integer, unlike numpy
_check_is_integer(k, 'k')
check_is_integer(k, 'k')

def tri_impl(N, M=None, k=0):
if M is None:
Expand Down Expand Up @@ -1732,7 +1727,7 @@ def np_tril_impl_2d(m, k=0):
def my_tril(m, k=0):

# we require k to be integer, unlike numpy
_check_is_integer(k, 'k')
check_is_integer(k, 'k')

def np_tril_impl_1d(m, k=0):
m_2d = _make_square(m)
Expand All @@ -1759,10 +1754,10 @@ def np_tril_impl_multi(m, k=0):
def np_tril_indices(n, k=0, m=None):

# we require integer arguments, unlike numpy
_check_is_integer(n, 'n')
_check_is_integer(k, 'k')
check_is_integer(n, 'n')
check_is_integer(k, 'k')
if not is_nonelike(m):
_check_is_integer(m, 'm')
check_is_integer(m, 'm')

def np_tril_indices_impl(n, k=0, m=None):
return np.nonzero(np.tri(n, m, k=k))
Expand All @@ -1773,7 +1768,7 @@ def np_tril_indices_impl(n, k=0, m=None):
def np_tril_indices_from(arr, k=0):

# we require k to be integer, unlike numpy
_check_is_integer(k, 'k')
check_is_integer(k, 'k')

if arr.ndim != 2:
raise TypingError("input array must be 2-d")
Expand All @@ -1792,7 +1787,7 @@ def np_triu_impl_2d(m, k=0):
@overload(np.triu)
def my_triu(m, k=0):
# we require k to be integer, unlike numpy
_check_is_integer(k, 'k')
check_is_integer(k, 'k')

def np_triu_impl_1d(m, k=0):
m_2d = _make_square(m)
Expand All @@ -1819,10 +1814,10 @@ def np_triu_impl_multi(m, k=0):
def np_triu_indices(n, k=0, m=None):

# we require integer arguments, unlike numpy
_check_is_integer(n, 'n')
_check_is_integer(k, 'k')
check_is_integer(n, 'n')
check_is_integer(k, 'k')
if not is_nonelike(m):
_check_is_integer(m, 'm')
check_is_integer(m, 'm')

def np_triu_indices_impl(n, k=0, m=None):
return np.nonzero(1 - np.tri(n, m, k=k - 1))
Expand All @@ -1833,7 +1828,7 @@ def np_triu_indices_impl(n, k=0, m=None):
def np_triu_indices_from(arr, k=0):

# we require k to be integer, unlike numpy
_check_is_integer(k, 'k')
check_is_integer(k, 'k')

if arr.ndim != 2:
raise TypingError("input array must be 2-d")
Expand Down Expand Up @@ -3627,7 +3622,7 @@ def np_bincount(a, weights=None, minlength=0):
if not isinstance(a.dtype, types.Integer):
return

_check_is_integer(minlength, 'minlength')
check_is_integer(minlength, 'minlength')

if weights not in (None, types.none):
validate_1d_array_like("bincount", weights)
Expand Down
8 changes: 7 additions & 1 deletion numba/np/numpy_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from numba.core import errors, types
from numba.core.typing.templates import signature

from numba.core.errors import TypingError

# re-export
from numba.core.cgutils import is_nonelike # noqa: F401
Expand Down Expand Up @@ -673,3 +673,9 @@ def type_can_asarray(arr):
types.Number, types.Boolean, types.containers.ListType)

return isinstance(arr, ok)


def check_is_integer(v, name):
"""Raise TypeError if the value is not an integer."""
Comment thread
itamarst marked this conversation as resolved.
Resolved
if not isinstance(v, (int, types.Integer)):
raise TypingError('{} must be an integer'.format(name))