Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
added np.size() overload and added tests
  • Loading branch information
shourya5 committed Mar 19, 2024
commit 6aea86fcac126ff4a8285a88ec08150c316e4433
9 changes: 9 additions & 0 deletions numba/np/arrayobj.py
Original file line number Diff line number Diff line change
Expand Up @@ -2555,6 +2555,15 @@ def impl(a):
return np.asarray(a).shape
return impl

@overload(np.size)
def np_size(a):
if not type_can_asarray(a):
raise errors.TypingError("The argument to np.size must be array-like")

def impl(a):
return np.asarray(a).size
return impl

# ------------------------------------------------------------------------------


Expand Down
3 changes: 3 additions & 0 deletions numba/tests/test_array_manipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ def numpy_fill_diagonal(arr, val, wrap=False):
def numpy_shape(arr):
return np.shape(arr)

def numpy_size(arr):
Comment thread
shourya5 marked this conversation as resolved.
Resolved
return np.size(arr)


def numpy_flatnonzero(a):
return np.flatnonzero(a)
Expand Down
4 changes: 4 additions & 0 deletions numba/tests/test_record_dtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,10 @@ def get_shape(rec):
return np.shape(rec.j)


def get_size(rec):
return np.size(rec.j)
Comment thread
shourya5 marked this conversation as resolved.
Resolved


def get_charseq(ary, i):
return ary[i].n

Expand Down