-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1023 from IntelPython/fix/rambo-dpnp-impl
Fixes stride calculation when unboxing a dpnp ndarray
- Loading branch information
Showing
5 changed files
with
130 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,6 @@ | |
""" | ||
|
||
import dpctl | ||
import pytest | ||
|
||
from numba_dpex import dpjit | ||
|
||
|
This file was deleted.
Oops, something went wrong.
47 changes: 47 additions & 0 deletions
47
numba_dpex/tests/core/types/DpnpNdArray/test_boxing_unboxing.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# SPDX-FileCopyrightText: 2020 - 2023 Intel Corporation | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
""" | ||
Tests for boxing for dpnp.ndarray | ||
""" | ||
|
||
import dpnp | ||
|
||
from numba_dpex import dpjit | ||
|
||
|
||
def test_boxing_unboxing(): | ||
"""Tests basic boxing and unboxing of a dpnp.ndarray object. | ||
Checks if we can pass in and return a dpctl.ndarray object to and | ||
from a dpjit decorated function. | ||
""" | ||
|
||
@dpjit | ||
def func(a): | ||
return a | ||
|
||
a = dpnp.empty(10) | ||
try: | ||
b = func(a) | ||
except: | ||
assert False, "Failure during unbox/box of dpnp.ndarray" | ||
|
||
assert a.shape == b.shape | ||
assert a.device == b.device | ||
assert a.strides == b.strides | ||
assert a.dtype == b.dtype | ||
|
||
|
||
def test_stride_calc_at_unboxing(): | ||
"""Tests if strides were correctly computed during unboxing.""" | ||
|
||
def _tester(a): | ||
return a.strides | ||
|
||
b = dpnp.empty((4, 16, 4)) | ||
strides = dpjit(_tester)(b) | ||
|
||
# Numba computes strides as bytes | ||
assert list(strides) == [512, 32, 8] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# SPDX-FileCopyrightText: 2020 - 2023 Intel Corporation | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
""" | ||
Tests for boxing for dpnp.ndarray | ||
""" | ||
|
||
import dpnp | ||
import numpy | ||
|
||
from numba_dpex import dpjit | ||
|
||
|
||
def test_1d_slicing(): | ||
"""Tests if dpjit properly computes strides and returns them to Python.""" | ||
|
||
def _tester(a): | ||
return a[1:5] | ||
|
||
a = dpnp.arange(10) | ||
b = dpnp.asnumpy(dpjit(_tester)(a)) | ||
|
||
na = numpy.arange(10) | ||
nb = _tester(na) | ||
|
||
assert (b == nb).all() | ||
|
||
|
||
def test_1d_slicing2(): | ||
"""Tests if dpjit properly computes strides and returns them to Python.""" | ||
|
||
def _tester(a): | ||
b = a[1:4] | ||
a[6:9] = b | ||
|
||
a = dpnp.arange(10) | ||
b = dpnp.asnumpy(dpjit(_tester)(a)) | ||
|
||
na = numpy.arange(10) | ||
nb = _tester(na) | ||
|
||
assert (b == nb).all() | ||
|
||
|
||
def test_multidim_slicing(): | ||
"""Tests if dpjit properly slices strides and returns them to Python.""" | ||
|
||
def _tester(a, b): | ||
b[:, :, 0] = a | ||
|
||
a = dpnp.arange(64, dtype=numpy.int64) | ||
a = a.reshape(4, 16) | ||
b = dpnp.empty((4, 16, 4), dtype=numpy.int64) | ||
dpjit(_tester)(a, b) | ||
|
||
na = numpy.arange(64, dtype=numpy.int64) | ||
na = na.reshape(4, 16) | ||
nb = numpy.empty((4, 16, 4), dtype=numpy.int64) | ||
_tester(na, nb) | ||
|
||
assert (nb[:, :, 0] == dpnp.asnumpy(b)[:, :, 0]).all() |