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
Prev Previous commit
Next Next commit
added runners
  • Loading branch information
shourya5 committed Mar 26, 2024
commit 8e4fed1922f9cf148097b00f6676568c878766c4
4 changes: 4 additions & 0 deletions docs/upcoming_changes/9504.np_support.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
added support for ``np.size()``
====================================================

added ``np.size()`` support for numpy,which was previously unsupported.
Comment thread
shourya5 marked this conversation as resolved.
Resolved
23 changes: 23 additions & 0 deletions numba/tests/test_array_manipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1221,6 +1221,29 @@ def check(x):

self.assertIn("The argument to np.shape must be array-like",
str(raises.exception))

def test_size(self):
pyfunc = numpy_size
cfunc = jit(nopython=True)(pyfunc)
Comment thread
shourya5 marked this conversation as resolved.
Resolved

def check(x):
expected = pyfunc(x)
got = cfunc(x)
self.assertPreciseEqual(got, expected)

# check arrays
for t in [(), (1,), (2, 3,), (4, 5, 6)]:
arr = np.empty(t)
check(arr)

# check some types that go via asarray
for t in [1, False, [1,], [[1, 2,],[3, 4]], (1,), (1, 2, 3)]:
check(t)

with self.assertRaises(TypingError) as raises:
cfunc('a')
self.assertIn("The argument to np.size must be array-like",
str(raises.exception))

def test_flatnonzero_basic(self):
pyfunc = numpy_flatnonzero
Expand Down
14 changes: 14 additions & 0 deletions numba/tests/test_record_dtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -1619,6 +1619,20 @@ def test_shape(self):
cfunc = self.get_cfunc(pyfunc, (ty,))
arr_res = cfunc(arg)
np.testing.assert_equal(arr_res, arr_expected)

def test_size(self):
# test getting the size of a nestedarray inside a record
nbarr = np.recarray(2, dtype=recordwith2darray)
nbarr[0] = np.array([(1, ((1, 2), (4, 5), (2, 3)))],
dtype=recordwith2darray)[0]

arg = nbarr[0]
pyfunc = get_size
ty = typeof(arg)
arr_expected = pyfunc(arg)
cfunc = self.get_cfunc(pyfunc, (ty,))
arr_res = cfunc(arg)
np.testing.assert_equal(arr_res, arr_expected)

def test_corner_slice(self):
# testing corner cases while slicing nested arrays
Expand Down