@@ -68,7 +68,7 @@ cdef ERROR_PREFIX = "DPNP error:"
68
68
69
69
def convert_item (item ):
70
70
if getattr (item, " __sycl_usm_array_interface__" , False ):
71
- item_converted = dpnp.asnumpy(item)
71
+ item_converted = dpnp.asnumpy(item)
72
72
elif getattr (item, " __array_interface__" , False ): # detect if it is a container (TODO any better way?)
73
73
mod_name = getattr (item, " __module__" , ' none' )
74
74
if (mod_name != ' numpy' ):
@@ -91,7 +91,18 @@ def convert_list_args(input_list):
91
91
result_list.append(item_converted)
92
92
93
93
return result_list
94
-
94
+
95
+
96
+ def copy_from_origin (dst , src ):
97
+ """ Copy origin result to output result."""
98
+ if config.__DPNP_OUTPUT_DPCTL__ and hasattr (dst, " __sycl_usm_array_interface__" ):
99
+ if src.size:
100
+ dst.usm_data.copy_from_host(src.reshape(- 1 ).view(" |u1" ))
101
+ else :
102
+ for i in range (dst.size):
103
+ dst.flat[i] = src.item(i)
104
+
105
+
95
106
def call_origin (function , *args , **kwargs ):
96
107
"""
97
108
Call fallback function for unsupported cases
@@ -138,8 +149,7 @@ def call_origin(function, *args, **kwargs):
138
149
else :
139
150
result = kwargs_out
140
151
141
- for i in range (result.size):
142
- result.flat[i] = result_origin.item(i)
152
+ copy_from_origin(result, result_origin)
143
153
144
154
elif isinstance (result, tuple ):
145
155
# convert tuple(fallback_array) to tuple(result_array)
@@ -148,8 +158,7 @@ def call_origin(function, *args, **kwargs):
148
158
res = res_origin
149
159
if isinstance (res_origin, numpy.ndarray):
150
160
res = create_output_container(res_origin.shape, res_origin.dtype)
151
- for i in range (res.size):
152
- res.flat[i] = res_origin.item(i)
161
+ copy_from_origin(res, res_origin)
153
162
result_list.append(res)
154
163
155
164
result = tuple (result_list)
0 commit comments