Skip to content

Added tests to cover red lines in coverage report #619

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 3 commits into from
Oct 4, 2021
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: 1 addition & 3 deletions dpctl/tensor/_copy_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,6 @@ def copy_same_shape(dst, src):
sh_i, dst_st, dst_disp, src_st, src_disp = contract_iter2(
dst.shape, dst.strides, src.strides
)
# sh_i, dst_st, dst_disp, src_st, src_disp = (
# dst.shape, dst.strides, 0, src.strides, 0
# )
src_iface = src.__sycl_usm_array_interface__
dst_iface = dst.__sycl_usm_array_interface__
src_iface["shape"] = tuple()
Expand Down Expand Up @@ -250,6 +247,7 @@ def copy_from_usm_ndarray_to_usm_ndarray(dst, src):
)
else:
src_same_shape = src
src_same_shape.shape = common_shape

copy_same_shape(dst, src_same_shape)

Expand Down
5 changes: 4 additions & 1 deletion dpctl/tensor/_reshape.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ def reshaped_strides(old_sh, old_sts, new_sh, order="C"):
]
]
valid = all(
[check_st == old_st for check_st, old_st in zip(check_sts, old_sts)]
[
check_st == old_st or old_dim == 1
for check_st, old_st, old_dim in zip(check_sts, old_sts, old_sh)
]
)
return new_sts if valid else None

Expand Down
1 change: 0 additions & 1 deletion dpctl/tensor/_usmarray.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,6 @@ cdef class usm_ndarray:
PyMem_Free(self.shape_)
if (self.strides_):
PyMem_Free(self.strides_)
print(contig_flag)
self.flags_ = contig_flag
self.nd_ = new_nd
self.shape_ = shape_ptr
Expand Down
19 changes: 19 additions & 0 deletions dpctl/tests/test_usm_ndarray_ctor.py
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,25 @@ def test_setitem_scalar(dtype, usm_type):
)


def test_setitem_errors():
X = dpt.usm_ndarray((4,), dtype="u1")
Y = dpt.usm_ndarray((4, 2), dtype="u1")
with pytest.raises(ValueError):
X[:] = Y
with pytest.raises(ValueError):
X[:] = Y[:, 0:1]
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")
Z[::2] = X
Z[1::2] = Y
assert np.allclose(dpt.asnumpy(Z), np.tile(np.array([1, 0], "d"), 10))


def test_shape_setter():
def cc_strides(sh):
return np.empty(sh, dtype="u1").strides
Expand Down