Skip to content

Commit 78c4b8b

Browse files
authored
Get rid of env var which handles dep on dpctl.tensor (#1205)
* Get rid of env var stating dep on dpctl.tensor * Apply review comments
1 parent 384a4ba commit 78c4b8b

File tree

4 files changed

+20
-24
lines changed

4 files changed

+20
-24
lines changed

dpnp/config.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22
# *****************************************************************************
3-
# Copyright (c) 2016-2020, Intel Corporation
3+
# Copyright (c) 2016-2022, Intel Corporation
44
# All rights reserved.
55
#
66
# Redistribution and use in source and binary forms, with or without
@@ -43,11 +43,6 @@
4343
Explicitly use NumPy.ndarray as return type for creation functions
4444
'''
4545

46-
__DPNP_OUTPUT_DPCTL__ = int(os.getenv('DPNP_OUTPUT_DPCTL', 1))
47-
'''
48-
Explicitly use DPCtl package container as return type for creation functions
49-
'''
50-
5146
__DPNP_OUTPUT_DPCTL_DEFAULT_SHARED__ = int(os.getenv('DPNP_OUTPUT_DPCTL_DEFAULT_SHARED', 0))
5247
'''
5348
Explicitly use SYCL shared memory parameter in DPCtl array constructor for creation functions

dpnp/dpnp_array.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,9 @@ def astype(self, dtype, order='K', casting='unsafe', subok=True, copy=True):
443443
444444
"""
445445

446-
return dpnp.astype(self, dtype, order, casting, subok, copy)
446+
new_array = self.__new__(dpnp_array)
447+
new_array._array_obj = dpt.astype(self._array_obj, dtype, order=order, casting=casting, copy=copy)
448+
return new_array
447449

448450
# 'base',
449451
# 'byteswap',

dpnp/dpnp_iface.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import dpctl
5050
import dpctl.tensor as dpt
5151

52+
from dpnp.dpnp_array import dpnp_array
5253
from dpnp.dpnp_algo import *
5354
from dpnp.dpnp_utils import *
5455
from dpnp.fft import *
@@ -137,26 +138,24 @@ def asnumpy(input, order='C'):
137138
This function works exactly the same as :obj:`numpy.asarray`.
138139
139140
"""
141+
if isinstance(input, dpnp_array):
142+
return dpt.asnumpy(input.get_array())
140143

141-
if isinstance(input, dpctl.tensor.usm_ndarray):
142-
return dpctl.tensor.to_numpy(input)
143-
144-
if config.__DPNP_OUTPUT_DPCTL__ and hasattr(input, "__sycl_usm_array_interface__"):
145-
return dpctl.tensor.to_numpy(input.get_array())
144+
if isinstance(input, dpt.usm_ndarray):
145+
return dpt.asnumpy(input)
146146

147147
return numpy.asarray(input, order=order)
148148

149149

150150
def astype(x1, dtype, order='K', casting='unsafe', subok=True, copy=True):
151151
"""Copy the array with data type casting."""
152-
if config.__DPNP_OUTPUT_DPCTL__ and hasattr(x1, "__sycl_usm_array_interface__"):
153-
import dpctl.tensor as dpt
154-
# TODO: remove check dpctl.tensor has attribute "astype"
155-
if hasattr(dpt, "astype"):
156-
# return dpt.astype(x1, dtype, order=order, casting=casting, copy=copy)
157-
return dpt.astype(x1.get_array(), dtype, order=order, casting=casting, copy=copy)
158-
159-
x1_desc = get_dpnp_descriptor(x1)
152+
if isinstance(x1, dpnp_array):
153+
return x1.astype(dtype, order=order, casting=casting, copy=copy)
154+
155+
if isinstance(x1, dpt.usm_ndarray):
156+
return dpt.astype(x1, dtype, order=order, casting=casting, copy=copy)
157+
158+
x1_desc = get_dpnp_descriptor(x1, copy_when_nondefault_queue=False)
160159
if not x1_desc:
161160
pass
162161
elif order != 'K':

dpnp/dpnp_utils/dpnp_algo_utils.pyx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# cython: language_level=3
22
# -*- coding: utf-8 -*-
33
# *****************************************************************************
4-
# Copyright (c) 2016-2020, Intel Corporation
4+
# Copyright (c) 2016-2022, Intel Corporation
55
# All rights reserved.
66
#
77
# Redistribution and use in source and binary forms, with or without
@@ -100,10 +100,10 @@ def convert_list_args(input_list):
100100

101101
def copy_from_origin(dst, src):
102102
"""Copy origin result to output result."""
103-
if config.__DPNP_OUTPUT_DPCTL__ and hasattr(dst, "__sycl_usm_array_interface__"):
103+
if hasattr(dst, "__sycl_usm_array_interface__"):
104104
if src.size:
105-
# dst.usm_data.copy_from_host(src.reshape(-1).view("|u1"))
106-
dpctl.tensor._copy_utils._copy_from_numpy_into(unwrap_array(dst), src)
105+
dst_dpt = unwrap_array(dst)
106+
dst_dpt[...] = src
107107
else:
108108
for i in range(dst.size):
109109
dst.flat[i] = src.item(i)

0 commit comments

Comments
 (0)