Skip to content

Commit c5a4170

Browse files
authored
Move dparray specific function into dparray specific place (#877)
1 parent f5cc9de commit c5a4170

File tree

3 files changed

+25
-35
lines changed

3 files changed

+25
-35
lines changed

dpnp/dparray.pyx

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ cdef class dparray:
387387
388388
if key_is_slice or key_has_slice:
389389
# fallback to numpy in case of slicing
390-
return utils.nd2dp_array(utils.dp2nd_array(self)[key])
390+
return nd2dp_array(dp2nd_array(self)[key])
391391
392392
lin_idx = utils._get_linear_index(key, self.shape, self.ndim)
393393
@@ -518,9 +518,9 @@ cdef class dparray:
518518
self_desc = iface_get_dpnp_descriptor(self)
519519
return dpnp_flatten(self_desc).get_pyobj()
520520
521-
result = utils.dp2nd_array(self).flatten(order=order)
521+
result = dp2nd_array(self).flatten(order=order)
522522
523-
return utils.nd2dp_array(result)
523+
return nd2dp_array(result)
524524
525525
def ravel(self, order='C'):
526526
"""
@@ -804,9 +804,9 @@ cdef class dparray:
804804
self_desc = iface_get_dpnp_descriptor(self)
805805
return dpnp_astype(self_desc, dtype).get_pyobj()
806806
807-
result = utils.dp2nd_array(self).astype(dtype=dtype, order=order, casting=casting, subok=subok, copy=copy)
807+
result = dp2nd_array(self).astype(dtype=dtype, order=order, casting=casting, subok=subok, copy=copy)
808808
809-
return utils.nd2dp_array(result)
809+
return nd2dp_array(result)
810810
811811
def conj(self):
812812
"""
@@ -1273,3 +1273,20 @@ cdef class dparray:
12731273
"""
12741274
12751275
return asnumpy(self).tostring(order)
1276+
1277+
1278+
def dp2nd_array(arr):
1279+
"""Convert dparray to ndarray"""
1280+
return asnumpy(arr) if isinstance(arr, dparray) else arr
1281+
1282+
1283+
def nd2dp_array(arr):
1284+
"""Convert ndarray to dparray"""
1285+
if not isinstance(arr, numpy.ndarray):
1286+
return arr
1287+
1288+
result = dparray(arr.shape, dtype=arr.dtype)
1289+
for i in range(result.size):
1290+
result._setitem_scalar(i, arr.item(i))
1291+
1292+
return result

dpnp/dpnp_utils/dpnp_algo_utils.pxd

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
from libcpp cimport bool as cpp_bool
2929
from libcpp.vector cimport vector
3030

31-
from dpnp.dparray cimport dparray
3231
from dpnp.dpnp_algo.dpnp_algo cimport DPNPFuncType, DPNPFuncName
3332

3433

@@ -87,7 +86,7 @@ Conversion of the transformation shape axis [-1, 0, 1] into [2, 0, 1] where numb
8786

8887
cdef tuple get_shape_dtype(object input_obj)
8988
"""
90-
input_obj: Complex object with lists, scalars and dparrays
89+
input_obj: Complex object with lists, scalars and numpy-like arrays
9190
9291
Returns a tuple of:
9392
1. concatenated shape, empty `shape_type_c` if unsuccessful.
@@ -119,16 +118,6 @@ cpdef tuple get_axis_offsets(shape)
119118
Compute axis offsets in the linear array memory
120119
"""
121120

122-
cpdef dp2nd_array(arr)
123-
"""
124-
Convert dparray to ndarray
125-
"""
126-
127-
cpdef nd2dp_array(arr)
128-
"""
129-
Convert ndarray to dparray
130-
"""
131-
132121
cdef class dpnp_descriptor:
133122
"""array DPNP descriptor"""
134123

dpnp/dpnp_utils/dpnp_algo_utils.pyx

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ from dpnp.dpnp_algo cimport dpnp_DPNPFuncType_to_dtype, dpnp_dtype_to_DPNPFuncTy
3838
from libcpp cimport bool as cpp_bool
3939
from libcpp.complex cimport complex as cpp_complex
4040

41+
from dpnp.dparray import dparray
42+
4143
cimport cpython
4244
cimport cython
4345
cimport numpy
@@ -69,12 +71,10 @@ __all__ = [
6971
"checker_throw_type_error",
7072
"checker_throw_value_error",
7173
"create_output_descriptor_py",
72-
"dp2nd_array",
7374
"dpnp_descriptor",
7475
"get_axis_indeces",
7576
"get_axis_offsets",
7677
"_get_linear_index",
77-
"nd2dp_array",
7878
"normalize_axis",
7979
"_object_to_tuple",
8080
"use_origin_backend"
@@ -208,10 +208,6 @@ cpdef dpnp_descriptor create_output_descriptor_py(shape_type_c output_shape, obj
208208
return create_output_descriptor(output_shape, c_type, requested_out)
209209

210210

211-
cpdef dp2nd_array(arr):
212-
"""Convert dparray to ndarray"""
213-
return dpnp.asnumpy(arr) if isinstance(arr, dparray) else arr
214-
215211
cdef long container_copy(object dst_obj, object src_obj, size_t dst_idx = 0) except -1:
216212
cdef elem_dtype = dst_obj.dtype
217213

@@ -421,18 +417,6 @@ cdef dpnp_descriptor create_output_descriptor(shape_type_c output_shape,
421417
return result_desc
422418

423419

424-
cpdef nd2dp_array(arr):
425-
"""Convert ndarray to dparray"""
426-
if not isinstance(arr, numpy.ndarray):
427-
return arr
428-
429-
result = dparray(arr.shape, dtype=arr.dtype)
430-
for i in range(result.size):
431-
result._setitem_scalar(i, arr.item(i))
432-
433-
return result
434-
435-
436420
cpdef shape_type_c normalize_axis(object axis_obj, size_t shape_size_inp):
437421
"""
438422
Conversion of the transformation shape axis [-1, 0, 1] into [2, 0, 1] where numbers are `id`s of array shape axis

0 commit comments

Comments
 (0)