Skip to content

Commit

Permalink
Construct NumPy arrays correctly from 0D deferred arrays backed by re…
Browse files Browse the repository at this point in the history
…gion fields (nv-legate#551)

* Handle inline allocations from 0D stores correctly (spoiler: they are not 0D)

* Add a test case for 0D region-backed stores
  • Loading branch information
magnatelee authored and jjwilke committed Sep 2, 2022
1 parent b38a1a4 commit a1633a2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 4 additions & 1 deletion cunumeric/deferred.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,10 @@ def construct_ndarray(
initializer = _CuNumericNDarray(
shape, self.dtype, address, strides, False
)
return np.asarray(initializer)
result = np.asarray(initializer)
if self.shape == ():
result = result.reshape(())
return result

result = cast("npt.NDArray[Any]", alloc.consume(construct_ndarray))

Expand Down
12 changes: 12 additions & 0 deletions tests/integration/test_slicing.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ def test_3d():
assert np.array_equal(firstslice, firstslicegold)


def test_0d():
in_np = np.array([1, 2])
in_num = num.array([1, 2])

sl_np = in_np[1:].reshape(())
sl_num = in_num[1:].reshape(())

# Test inline mapping for a 0-d array
print(sl_num)
assert np.array_equal(sl_np, sl_num)


# TODO: Legate needs 4-D arrays for this to work correctly
@pytest.mark.skip
def test_4d():
Expand Down

0 comments on commit a1633a2

Please sign in to comment.