Skip to content

Commit e4a14d9

Browse files
authored
move container_copy() to container specific place (#884)
1 parent a3f7dbe commit e4a14d9

File tree

4 files changed

+21
-23
lines changed

4 files changed

+21
-23
lines changed

dpnp/dpnp_algo/dpnp_algo.pyx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ from libc.time cimport time, time_t
3636
import dpnp
3737
import dpnp.config as config
3838
import dpnp.dpnp_utils as utils_py
39+
from dpnp.dpnp_container import container_copy
40+
3941
import numpy
4042

4143
cimport cpython
@@ -118,7 +120,7 @@ cpdef utils.dpnp_descriptor dpnp_array(object obj, object dtype=None):
118120
else:
119121
result = utils_py.create_output_descriptor_py(obj_shape, obj_dtype, None)
120122

121-
utils.container_copy(result.get_pyobj(), obj)
123+
container_copy(result.get_pyobj(), obj)
122124

123125
return result
124126

dpnp/dpnp_container.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,20 @@ def create_output_container(shape, type):
8585
result = dparray(shape, dtype=type)
8686

8787
return result
88+
89+
90+
def container_copy(dst_obj, src_obj, dst_idx = 0):
91+
"""
92+
Copy values to `dst` by iterating element by element in `input_obj`
93+
"""
94+
95+
for elem_value in src_obj:
96+
if isinstance(elem_value, (list, tuple)):
97+
dst_idx = container_copy(dst_obj, elem_value, dst_idx)
98+
elif issubclass(type(elem_value), (numpy.ndarray, dparray)):
99+
dst_idx = container_copy(dst_obj, elem_value, dst_idx)
100+
else:
101+
dst_obj.flat[dst_idx] = elem_value
102+
dst_idx += 1
103+
104+
return dst_idx

dpnp/dpnp_utils/dpnp_algo_utils.pxd

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,6 @@ cpdef find_common_type(object x1_obj, object x2_obj)
9898
Find common type of 2 input objects
9999
"""
100100

101-
cdef long container_copy(object dst_obj, object src_obj, size_t dst_idx=*) except -1
102-
"""
103-
Copy values to `dst` by iterating element by element in `input_obj`
104-
"""
105101

106102
cpdef long _get_linear_index(key, tuple shape, int ndim)
107103
"""

dpnp/dpnp_utils/dpnp_algo_utils.pyx

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,10 @@ import numpy
3535
import dpnp.config as config
3636
import dpnp
3737
from dpnp.dpnp_algo cimport dpnp_DPNPFuncType_to_dtype, dpnp_dtype_to_DPNPFuncType, get_dpnp_function_ptr
38-
from dpnp.dpnp_container import create_output_container
38+
from dpnp.dpnp_container import create_output_container, container_copy
3939
from libcpp cimport bool as cpp_bool
4040
from libcpp.complex cimport complex as cpp_complex
4141

42-
from dpnp.dparray import dparray
43-
4442
cimport cpython
4543
cimport cython
4644
cimport numpy
@@ -194,21 +192,6 @@ cpdef dpnp_descriptor create_output_descriptor_py(shape_type_c output_shape, obj
194192
return create_output_descriptor(output_shape, c_type, requested_out)
195193

196194

197-
cdef long container_copy(object dst_obj, object src_obj, size_t dst_idx = 0) except -1:
198-
cdef elem_dtype = dst_obj.dtype
199-
200-
for elem_value in src_obj:
201-
if isinstance(elem_value, (list, tuple)):
202-
dst_idx = container_copy(dst_obj, elem_value, dst_idx)
203-
elif issubclass(type(elem_value), (numpy.ndarray, dparray)):
204-
dst_idx = container_copy(dst_obj, elem_value, dst_idx)
205-
else:
206-
dst_obj.flat[dst_idx] = elem_value
207-
dst_idx += 1
208-
209-
return dst_idx
210-
211-
212195
cpdef tuple get_axis_indeces(idx, shape):
213196
"""
214197
Compute axis indices of an element in array from array linear index

0 commit comments

Comments
 (0)