Skip to content

Fixed bug causing dpt.arange(0,1,1e-3,dtype="f4") be length 1 #855

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 1 commit into from
Jul 3, 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
16 changes: 9 additions & 7 deletions dpctl/tensor/_ctors.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,22 +471,24 @@ def _coerce_and_infer_dt(*args, dt):
raise ValueError(f"Data type {dt} is not supported")


def _round_for_arange(tmp):
k = int(tmp)
if k > 0 and float(k) < tmp:
tmp = tmp + 1
return tmp


def _get_arange_length(start, stop, step):
"Compute length of arange sequence"
span = stop - start
if type(step) in [int, float] and type(span) in [int, float]:
offset = -1 if step > 0 else 1
tmp = 1 + (span + offset) / step
return tmp
return _round_for_arange(span / step)
tmp = span / step
if type(tmp) is complex and tmp.imag == 0:
tmp = tmp.real
else:
return tmp
k = int(tmp)
if k > 0 and float(k) < tmp:
tmp = tmp + 1
return tmp
return _round_for_arange(tmp)


def arange(
Expand Down
14 changes: 14 additions & 0 deletions dpctl/tests/test_usm_ndarray_ctor.py
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,20 @@ def test_arange(dt):
assert X2.shape == (sz,)


def test_arange_fp():
try:
q = dpctl.SyclQueue()
except dpctl.SyclQueueCreationError:
pytest.skip("Queue could not be created")

assert dpt.arange(7, 0, -2, dtype="f4", device=q).shape == (4,)
assert dpt.arange(0, 1, 0.25, dtype="f4", device=q).shape == (4,)

if q.sycl_device.has_aspect_fp64:
assert dpt.arange(7, 0, -2, dtype="f8", device=q).shape == (4,)
assert dpt.arange(0, 1, 0.25, dtype="f4", device=q).shape == (4,)


@pytest.mark.parametrize(
"dt",
_all_dtypes,
Expand Down