Skip to content
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

Fixes repeat for axis=0 with scalar input #1433

Merged
merged 1 commit into from
Oct 9, 2023
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/libtensor/source/repeat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ py_repeat_by_sequence(const dpctl::tensor::usm_ndarray &src,
const py::ssize_t *dst_shape = dst.get_shape_raw();
bool same_orthog_dims(true);
size_t orthog_nelems(1); // number of orthogonal iterations

for (auto i = 0; i < axis; ++i) {
auto src_sh_i = src_shape[i];
orthog_nelems *= src_sh_i;
Expand Down Expand Up @@ -554,7 +553,6 @@ py_repeat_by_scalar(const dpctl::tensor::usm_ndarray &src,
const py::ssize_t *dst_shape = dst.get_shape_raw();
bool same_orthog_dims(true);
size_t orthog_nelems(1); // number of orthogonal iterations

for (auto i = 0; i < axis; ++i) {
auto src_sh_i = src_shape[i];
orthog_nelems *= src_sh_i;
Expand Down Expand Up @@ -634,7 +632,7 @@ py_repeat_by_scalar(const dpctl::tensor::usm_ndarray &src,
assert(dst_shape_vec.size() == 1);
assert(dst_strides_vec.size() == 1);

if (src_nd > 0) {
if (src_nd == 0) {
src_shape_vec = {0};
src_strides_vec = {0};
}
Expand Down
6 changes: 6 additions & 0 deletions dpctl/tests/test_usm_ndarray_manipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1170,6 +1170,12 @@ def test_repeat_axes():
res = dpt.repeat(x, reps, axis=1)
assert dpt.all(res == expected_res)

x = dpt.arange(10, dtype="i4")
expected_res = dpt.empty(x.shape[0] * reps, x.dtype)
expected_res[::2], expected_res[1::2] = x, x
res = dpt.repeat(x, reps, axis=0)
assert dpt.all(res == expected_res)


def test_repeat_size_0_outputs():
get_queue_or_skip()
Expand Down