Skip to content

Test iris xe part2 #862

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 3 additions & 1 deletion dpctl/tests/test_tensor_asarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@ def test_asarray_copy_false():
q = dpctl.SyclQueue()
except dpctl.SyclQueueCreationError:
pytest.skip("Could not create a queue")
X = dpt.from_numpy(np.random.randn(10, 4), usm_type="device", sycl_queue=q)
rng = np.random.default_rng()
Xnp = rng.integers(low=-255, high=255, size=(10, 4), dtype=np.int64)
X = dpt.from_numpy(Xnp, usm_type="device", sycl_queue=q)
Y1 = dpt.asarray(X, copy=False, order="K")
assert Y1 is X
Y1c = dpt.asarray(X, copy=True, order="K")
Expand Down
70 changes: 61 additions & 9 deletions dpctl/tests/test_usm_ndarray_ctor.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,14 @@ def test_tofrom_numpy(shape, dtype, usm_type):
@pytest.mark.parametrize("src_usm_type", ["device", "shared", "host"])
@pytest.mark.parametrize("dst_usm_type", ["device", "shared", "host"])
def test_setitem_same_dtype(dtype, src_usm_type, dst_usm_type):
try:
q = dpctl.SyclQueue()
except dpctl.SyclQueueCreationError:
pytest.skip("Could not create default SyclQueue.")
if q.sycl_device.has_aspect_fp64 is False and dtype in ["f8", "c16"]:
pytest.skip(
"Device does not support double precision floating point types."
)
Xnp = (
np.random.randint(-10, 10, size=2 * 3 * 4)
.astype(dtype)
Expand Down Expand Up @@ -649,6 +657,12 @@ def test_setitem_same_dtype(dtype, src_usm_type, dst_usm_type):
)
@pytest.mark.parametrize("usm_type", ["device", "shared", "host"])
def test_setitem_scalar(dtype, usm_type):
try:
q = dpctl.SyclQueue()
except dpctl.SyclQueueCreationError:
pytest.skip("Could not create default SyclQueue")
if q.sycl_device.has_aspect_fp64 is False and dtype in ["f8", "c16"]:
pytest.skip("Device does not support double precision floating type")
X = dpt.usm_ndarray((6, 6), dtype=dtype, buffer=usm_type)
for i in range(X.size):
X[np.unravel_index(i, X.shape)] = np.asarray(i, dtype=dtype)
Expand All @@ -673,13 +687,22 @@ def test_setitem_errors():
X[:] = Y[None, :, 0]


def test_setitem_different_dtypes():
X = dpt.from_numpy(np.ones(10, "f4"))
Y = dpt.from_numpy(np.zeros(10, "f4"))
Z = dpt.usm_ndarray((20,), "d")
@pytest.mark.parametrize("src_dt,dst_dt", [("i4", "i8"), ("f4", "f8")])
def test_setitem_different_dtypes(src_dt, dst_dt):
try:
q = dpctl.SyclQueue()
except dpctl.SyclQueueCreationError:
pytest.skip("Default queue could not be created")
if dst_dt == "f8" and q.sycl_device.has_aspect_fp64 is False:
pytest.skip(
"Device does not support double precision floating point type"
)
X = dpt.from_numpy(np.ones(10, src_dt), sycl_queue=q)
Y = dpt.from_numpy(np.zeros(10, src_dt), sycl_queue=q)
Z = dpt.empty((20,), dtype=dst_dt, sycl_queue=q)
Z[::2] = X
Z[1::2] = Y
assert np.allclose(dpt.asnumpy(Z), np.tile(np.array([1, 0], "d"), 10))
assert np.allclose(dpt.asnumpy(Z), np.tile(np.array([1, 0], Z.dtype), 10))


def test_shape_setter():
Expand Down Expand Up @@ -804,8 +827,8 @@ def test_to_device_migration():
def test_astype():
X = dpt.empty((5, 5), dtype="i4")
X[:] = np.full((5, 5), 7, dtype="i4")
Y = dpt.astype(X, "c16", order="C")
assert np.allclose(dpt.to_numpy(Y), np.full((5, 5), 7, dtype="c16"))
Y = dpt.astype(X, "c8", order="C")
assert np.allclose(dpt.to_numpy(Y), np.full((5, 5), 7, dtype="c8"))
Y = dpt.astype(X[::2, ::-1], "f2", order="K")
assert np.allclose(dpt.to_numpy(Y), np.full(Y.shape, 7, dtype="f2"))
Y = dpt.astype(X[::2, ::-1], "i4", order="K", copy=False)
Expand Down Expand Up @@ -946,7 +969,15 @@ def test_zeros(dtype):
_all_dtypes,
)
def test_ones(dtype):
X = dpt.ones(10, dtype=dtype)
try:
q = dpctl.SyclQueue()
except dpctl.SyclQueueCreationError:
pytest.skip("Could not created default queue")
if dtype in ["f8", "c16"] and q.sycl_device.has_aspect_fp64 is False:
pytest.skip(
"Device does not support double precision floating point type"
)
X = dpt.ones(10, dtype=dtype, sycl_queue=q)
assert np.array_equal(dpt.asnumpy(X), np.ones(10, dtype=dtype))


Expand All @@ -955,7 +986,15 @@ def test_ones(dtype):
_all_dtypes,
)
def test_full(dtype):
X = dpt.full(10, 4, dtype=dtype)
try:
q = dpctl.SyclQueue()
except dpctl.SyclQueueCreationError:
pytest.skip("Could not created default queue")
if dtype in ["f8", "c16"] and q.sycl_device.has_aspect_fp64 is False:
pytest.skip(
"Device does not support double precision floating point type"
)
X = dpt.full(10, 4, dtype=dtype, sycl_queue=q)
assert np.array_equal(dpt.asnumpy(X), np.full(10, 4, dtype=dtype))


Expand All @@ -976,6 +1015,10 @@ def test_arange(dt):
except dpctl.SyclQueueCreationError:
pytest.skip("Queue could not be created")

if dt in ["f8", "c16"] and q.sycl_device.has_aspect_fp64 is False:
pytest.skip(
"Device does not support double precision floating point type"
)
X = dpt.arange(0, 123, dtype=dt, sycl_queue=q)
dt = np.dtype(dt)
if np.issubdtype(dt, np.integer):
Expand Down Expand Up @@ -1093,6 +1136,10 @@ def test_ones_like(dt, usm_kind):
q = dpctl.SyclQueue()
except dpctl.SyclQueueCreationError:
pytest.skip("Queue could not be created")
if dt in ["f8", "c16"] and q.sycl_device.has_aspect_fp64 is False:
pytest.skip(
"Device does not support double precision floating point type"
)

X = dpt.empty((4, 5), dtype=dt, usm_type=usm_kind, sycl_queue=q)
Y = dpt.ones_like(X)
Expand Down Expand Up @@ -1129,6 +1176,11 @@ def test_full_like(dt, usm_kind):
except dpctl.SyclQueueCreationError:
pytest.skip("Queue could not be created")

if dt in ["f8", "c16"] and q.sycl_device.has_aspect_fp64 is False:
pytest.skip(
"Device does not support double precision floating point type"
)

fill_v = np.dtype(dt).type(1)
X = dpt.empty((4, 5), dtype=dt, usm_type=usm_kind, sycl_queue=q)
Y = dpt.full_like(X, fill_v)
Expand Down