Skip to content

Commit 8cd2042

Browse files
committed
Implement call of arange() function from dpctl.tensor
1 parent 35e28a4 commit 8cd2042

File tree

2 files changed

+46
-33
lines changed

2 files changed

+46
-33
lines changed

dpnp/dpnp_container.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,43 @@
3434
"""
3535

3636

37+
import dpctl.utils as dpu
3738
import dpctl.tensor as dpt
3839

3940
from dpnp.dpnp_array import dpnp_array
4041
import dpnp
4142

4243

4344
__all__ = [
45+
"arange",
4446
"asarray",
4547
"empty",
4648
]
4749

4850

51+
def arange(start,
52+
/,
53+
stop=None,
54+
step=1,
55+
*,
56+
dtype=None,
57+
device=None,
58+
usm_type="device",
59+
sycl_queue=None):
60+
"""Validate input parameters before passing them into `dpctl.tensor` module"""
61+
dpu.validate_usm_type(usm_type, allow_none=False)
62+
sycl_queue_normalized = dpnp.normalize_queue_device(sycl_queue=sycl_queue, device=device)
63+
64+
array_obj = dpt.arange(start,
65+
stop=stop,
66+
step=step,
67+
dtype=dtype,
68+
usm_type=usm_type,
69+
sycl_queue=sycl_queue_normalized)
70+
71+
return dpnp_array(array_obj.shape, buffer=array_obj)
72+
73+
4974
def asarray(x1,
5075
dtype=None,
5176
copy=False,

dpnp/dpnp_iface_arraycreation.py

Lines changed: 21 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# distutils: language = c++
33
# -*- coding: utf-8 -*-
44
# *****************************************************************************
5-
# Copyright (c) 2016-2020, Intel Corporation
5+
# Copyright (c) 2016-2022, Intel Corporation
66
# All rights reserved.
77
#
88
# Redistribution and use in source and binary forms, with or without
@@ -90,7 +90,16 @@
9090
]
9191

9292

93-
def arange(start, stop=None, step=1, dtype=None):
93+
def arange(start,
94+
/,
95+
stop=None,
96+
step=1,
97+
*,
98+
dtype=None,
99+
like=None,
100+
device=None,
101+
usm_type="device",
102+
sycl_queue=None):
94103
"""
95104
Returns an array with evenly spaced values within a given interval.
96105
@@ -99,12 +108,11 @@ def arange(start, stop=None, step=1, dtype=None):
99108
Returns
100109
-------
101110
arange : :obj:`dpnp.ndarray`
102-
The 1-D array of range values.
111+
The 1-D array containing evenly spaced values.
103112
104113
Limitations
105114
-----------
106-
Parameter ``start`` is supported as integer only.
107-
Parameters ``stop`` and ``step`` are supported as either integer or ``None``.
115+
Parameter ``like`` is supported only with default value ``None``.
108116
Otherwise the function will be executed sequentially on CPU.
109117
110118
See Also
@@ -113,7 +121,6 @@ def arange(start, stop=None, step=1, dtype=None):
113121
114122
Examples
115123
--------
116-
117124
>>> import dpnp as np
118125
>>> [i for i in np.arange(3)]
119126
[0, 1, 2]
@@ -123,34 +130,15 @@ def arange(start, stop=None, step=1, dtype=None):
123130
[3, 5]
124131
125132
"""
126-
if not use_origin_backend():
127-
if not isinstance(start, int):
128-
pass
129-
elif (stop is not None) and (not isinstance(stop, int)):
130-
pass
131-
elif (step is not None) and (not isinstance(step, int)):
132-
pass
133-
# TODO: modify native implementation to accept negative values
134-
elif (step is not None) and (step < 0):
135-
pass
136-
elif (start is not None) and (start < 0):
137-
pass
138-
elif (start is not None) and (stop is not None) and (start > stop):
139-
pass
140-
elif (dtype is not None) and (dtype not in [dpnp.int32, dpnp.int64, dpnp.float32, dpnp.float64]):
141-
pass
142-
else:
143-
if dtype is None:
144-
dtype = numpy.int64
145-
146-
if stop is None:
147-
stop = start
148-
start = 0
149-
150-
if step is None:
151-
step = 1
152133

153-
return dpnp_arange(start, stop, step, dtype).get_pyobj()
134+
if like is None:
135+
return dpnp_container.arange(start,
136+
stop=stop,
137+
step=step,
138+
dtype=dtype,
139+
device=device,
140+
usm_type=usm_type,
141+
sycl_queue=sycl_queue)
154142

155143
return call_origin(numpy.arange, start, stop=stop, step=step, dtype=dtype)
156144

0 commit comments

Comments
 (0)