|
37 | 37 |
|
38 | 38 | """ |
39 | 39 | # pylint: disable=protected-access |
| 40 | +# pylint: disable=redefined-outer-name |
40 | 41 |
|
41 | 42 | import os |
42 | 43 |
|
|
57 | 58 | __all__ = [ |
58 | 59 | "are_same_logical_tensors", |
59 | 60 | "asnumpy", |
60 | | - "astype", |
61 | 61 | "as_usm_ndarray", |
62 | 62 | "check_limitations", |
63 | 63 | "check_supported_arrays_type", |
@@ -209,96 +209,6 @@ def asnumpy(a, order="C"): |
209 | 209 | return numpy.asarray(a, order=order) |
210 | 210 |
|
211 | 211 |
|
212 | | -# pylint: disable=redefined-outer-name |
213 | | -def astype(x, dtype, /, *, order="K", casting="unsafe", copy=True, device=None): |
214 | | - """ |
215 | | - Copy the array with data type casting. |
216 | | -
|
217 | | - Parameters |
218 | | - ---------- |
219 | | - x : {dpnp.ndarray, usm_ndarray} |
220 | | - Array data type casting. |
221 | | - dtype : {None, str, dtype object} |
222 | | - Target data type. |
223 | | - order : {None, "C", "F", "A", "K"}, optional |
224 | | - Row-major (C-style) or column-major (Fortran-style) order. |
225 | | - When `order` is ``"A"``, it uses ``"F"`` if `a` is column-major and |
226 | | - uses ``"C"`` otherwise. And when `order` is ``"K"``, it keeps strides |
227 | | - as closely as possible. |
228 | | -
|
229 | | - Default: ``"K"``. |
230 | | - casting : {"no", "equiv", "safe", "same_kind", "unsafe"}, optional |
231 | | - Controls what kind of data casting may occur. Defaults to ``"unsafe"`` |
232 | | - for backwards compatibility. |
233 | | -
|
234 | | - - "no" means the data types should not be cast at all. |
235 | | - - "equiv" means only byte-order changes are allowed. |
236 | | - - "safe" means only casts which can preserve values are allowed. |
237 | | - - "same_kind" means only safe casts or casts within a kind, like |
238 | | - float64 to float32, are allowed. |
239 | | - - "unsafe" means any data conversions may be done. |
240 | | -
|
241 | | - Default: ``"unsafe"``. |
242 | | - copy : bool, optional |
243 | | - Specifies whether to copy an array when the specified dtype matches the |
244 | | - data type of the input array ``x``. If ``True``, a newly allocated |
245 | | - array must always be returned. If ``False`` and the specified dtype |
246 | | - matches the data type of the input array, the input array must be |
247 | | - returned; otherwise, a newly allocated array must be returned. |
248 | | -
|
249 | | - Default: ``True``. |
250 | | - device : {None, string, SyclDevice, SyclQueue, Device}, optional |
251 | | - An array API concept of device where the output array is created. |
252 | | - `device` can be ``None``, a oneAPI filter selector string, an instance |
253 | | - of :class:`dpctl.SyclDevice` corresponding to a non-partitioned SYCL |
254 | | - device, an instance of :class:`dpctl.SyclQueue`, or a |
255 | | - :class:`dpctl.tensor.Device` object returned by |
256 | | - :attr:`dpnp.ndarray.device`. |
257 | | - If the value is ``None``, returned array is created on the same device |
258 | | - as `x`. |
259 | | -
|
260 | | - Default: ``None``. |
261 | | -
|
262 | | - Returns |
263 | | - ------- |
264 | | - out : dpnp.ndarray |
265 | | - An array having the specified data type. |
266 | | -
|
267 | | - See Also |
268 | | - -------- |
269 | | - :obj:`dpnp.ndarray.astype` : Equivalent method. |
270 | | -
|
271 | | - Examples |
272 | | - -------- |
273 | | - >>> import dpnp as np |
274 | | - >>> x = np.array([1, 2, 3]); x |
275 | | - array([1, 2, 3]) |
276 | | - >>> np.astype(x, np.float32) |
277 | | - array([1., 2., 3.], dtype=float32) |
278 | | -
|
279 | | - Non-copy case: |
280 | | -
|
281 | | - >>> x = np.array([1, 2, 3]) |
282 | | - >>> result = np.astype(x, x.dtype, copy=False) |
283 | | - >>> result is x |
284 | | - True |
285 | | -
|
286 | | - """ |
287 | | - |
288 | | - if order is None: |
289 | | - order = "K" |
290 | | - |
291 | | - usm_x = dpnp.get_usm_ndarray(x) |
292 | | - usm_res = dpt.astype( |
293 | | - usm_x, dtype, order=order, casting=casting, copy=copy, device=device |
294 | | - ) |
295 | | - |
296 | | - if usm_res is usm_x and isinstance(x, dpnp_array): |
297 | | - # return x if dpctl returns a zero copy of usm_x |
298 | | - return x |
299 | | - return dpnp_array._create_from_usm_ndarray(usm_res) |
300 | | - |
301 | | - |
302 | 212 | def as_usm_ndarray(a, dtype=None, device=None, usm_type=None, sycl_queue=None): |
303 | 213 | """ |
304 | 214 | Return :class:`dpctl.tensor.usm_ndarray` from input object `a`. |
|
0 commit comments