Skip to content

Commit 6c5cdb2

Browse files
authored
manip module to desc completed (#868)
1 parent b05569f commit 6c5cdb2

File tree

4 files changed

+39
-32
lines changed

4 files changed

+39
-32
lines changed

dpnp/dpnp_algo/dpnp_algo_manipulation.pyx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,39 +51,42 @@ ctypedef void(*fptr_custom_elemwise_transpose_1in_1out_t)(void * , size_t * , si
5151
ctypedef void(*fptr_dpnp_repeat_t)(const void *, void * , const size_t , const size_t)
5252

5353

54-
cpdef dparray dpnp_atleast_2d(dparray arr):
54+
cpdef utils.dpnp_descriptor dpnp_atleast_2d(utils.dpnp_descriptor arr):
55+
# it looks like it should be dpnp.copy + dpnp.reshape
56+
cdef utils.dpnp_descriptor result
5557
cdef size_t arr_ndim = arr.ndim
5658
cdef long arr_size = arr.size
5759
if arr_ndim == 1:
58-
result = dparray((1, arr_size), dtype=arr.dtype)
60+
result = utils_py.create_output_descriptor_py((1, arr_size), arr.dtype, None)
5961
for i in range(arr_size):
60-
result[0, i] = arr[i]
62+
result.get_pyobj()[0, i] = arr.get_pyobj()[i]
6163
return result
6264
else:
6365
return arr
6466

6567

66-
cpdef dparray dpnp_atleast_3d(dparray arr):
68+
cpdef utils.dpnp_descriptor dpnp_atleast_3d(utils.dpnp_descriptor arr):
69+
# it looks like it should be dpnp.copy + dpnp.reshape
6770
cdef size_t arr_ndim = arr.ndim
6871
cdef shape_type_c arr_shape = arr.shape
6972
cdef long arr_size = arr.size
7073
if arr_ndim == 1:
71-
result = dparray((1, 1, arr_size), dtype=arr.dtype)
74+
result = utils_py.create_output_descriptor_py((1, 1, arr_size), arr.dtype, None)
7275
for i in range(arr_size):
73-
result[0, 0, i] = arr[i]
76+
result.get_pyobj()[0, 0, i] = arr.get_pyobj()[i]
7477
return result
7578
elif arr_ndim == 2:
76-
result = dparray((1, arr_shape[0], arr_shape[1]), dtype=arr.dtype)
79+
result = utils_py.create_output_descriptor_py((1, arr_shape[0], arr_shape[1]), arr.dtype, None)
7780
for i in range(arr_shape[0]):
7881
for j in range(arr_shape[1]):
79-
result[0, i, j] = arr[i, j]
82+
result.get_pyobj()[0, i, j] = arr.get_pyobj()[i, j]
8083
return result
8184
else:
8285
return arr
8386

8487

8588
cpdef dpnp_copyto(utils.dpnp_descriptor dst, utils.dpnp_descriptor src, where=True):
86-
# Convert string type names (dparray.dtype) to C enum DPNPFuncType
89+
# Convert string type names (array.dtype) to C enum DPNPFuncType
8790
cdef DPNPFuncType dst_type = dpnp_dtype_to_DPNPFuncType(dst.dtype)
8891
cdef DPNPFuncType src_type = dpnp_dtype_to_DPNPFuncType(src.dtype)
8992

@@ -167,7 +170,7 @@ cpdef utils.dpnp_descriptor dpnp_transpose(utils.dpnp_descriptor array1, axes=No
167170
""" construct output shape """
168171
result_shape[i] = input_shape[permute_axes[i]]
169172

170-
# convert string type names (dparray.dtype) to C enum DPNPFuncType
173+
# convert string type names (array.dtype) to C enum DPNPFuncType
171174
cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(array1.dtype)
172175

173176
# get the FPTR data structure

dpnp/dpnp_iface_manipulation.py

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
import collections.abc
4444

4545
from dpnp.dpnp_algo import *
46-
from dpnp.dparray import dparray
4746
from dpnp.dpnp_utils import *
4847
from dpnp.dpnp_iface_arraycreation import array
4948

@@ -128,16 +127,20 @@ def atleast_2d(*arys):
128127
Input arrays is supported as :obj:`dpnp.ndarray`.
129128
"""
130129

131-
all_is_dparray = True
130+
all_is_array = True
131+
arys_desc = []
132132
for ary in arys:
133-
if not isinstance(ary, dparray):
134-
all_is_dparray = False
133+
ary_desc = dpnp.get_dpnp_descriptor(ary)
134+
if ary_desc:
135+
arys_desc.append(ary_desc)
136+
else:
137+
all_is_array = False
135138
break
136139

137-
if not use_origin_backend(arys[0]) and all_is_dparray:
140+
if not use_origin_backend(arys[0]) and all_is_array:
138141
result = []
139-
for ary in arys:
140-
res = dpnp_atleast_2d(ary)
142+
for ary_desc in arys_desc:
143+
res = dpnp_atleast_2d(ary_desc).get_pyobj()
141144
result.append(res)
142145

143146
if len(result) == 1:
@@ -159,16 +162,20 @@ def atleast_3d(*arys):
159162
Input arrays is supported as :obj:`dpnp.ndarray`.
160163
"""
161164

162-
all_is_dparray = True
165+
all_is_array = True
166+
arys_desc = []
163167
for ary in arys:
164-
if not isinstance(ary, dparray):
165-
all_is_dparray = False
168+
ary_desc = dpnp.get_dpnp_descriptor(ary)
169+
if ary_desc:
170+
arys_desc.append(ary_desc)
171+
else:
172+
all_is_array = False
166173
break
167174

168-
if not use_origin_backend(arys[0]) and all_is_dparray:
175+
if not use_origin_backend(arys[0]) and all_is_array:
169176
result = []
170-
for ary in arys:
171-
res = dpnp_atleast_3d(ary)
177+
for ary_desc in arys_desc:
178+
res = dpnp_atleast_3d(ary_desc).get_pyobj()
172179
result.append(res)
173180

174181
if len(result) == 1:
@@ -206,11 +213,11 @@ def concatenate(arrs, axis=0, out=None, dtype=None, casting="same_kind"):
206213
"""
207214

208215
# TODO:
209-
# `call_origin` cannot convert sequence of dparray to sequence of
216+
# `call_origin` cannot convert sequence of array to sequence of
210217
# ndarrays
211218
arrs_new = []
212219
for arr in arrs:
213-
arrx = dpnp.asnumpy(arr) if isinstance(arr, dparray) else arr
220+
arrx = dpnp.asnumpy(arr) if not isinstance(arr, numpy.ndarray) else arr
214221
arrs_new.append(arrx)
215222

216223
return call_origin(numpy.concatenate, arrs_new, axis=axis, out=out, dtype=dtype, casting=casting)
@@ -330,11 +337,11 @@ def hstack(tup):
330337
"""
331338

332339
# TODO:
333-
# `call_origin` cannot convert sequence of dparray to sequence of
340+
# `call_origin` cannot convert sequence of array to sequence of
334341
# nparrays
335342
tup_new = []
336343
for tp in tup:
337-
tpx = dpnp.asnumpy(tp) if isinstance(tp, dparray) else tp
344+
tpx = dpnp.asnumpy(tp) if not isinstance(tp, numpy.ndarray) else tp
338345
tup_new.append(tpx)
339346

340347
return call_origin(numpy.hstack, tup_new)
@@ -686,11 +693,11 @@ def vstack(tup):
686693
"""
687694

688695
# TODO:
689-
# `call_origin` cannot convert sequence of dparray to sequence of
696+
# `call_origin` cannot convert sequence of array to sequence of
690697
# nparray
691698
tup_new = []
692699
for tp in tup:
693-
tpx = dpnp.asnumpy(tp) if isinstance(tp, dparray) else tp
700+
tpx = dpnp.asnumpy(tp) if not isinstance(tp, numpy.ndarray) else tp
694701
tup_new.append(tpx)
695702

696703
return call_origin(numpy.vstack, tup_new)

dpnp/dpnp_iface_mathematical.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,7 +1357,6 @@ def prod(x1, axis=None, dtype=None, out=None, keepdims=False, initial=None, wher
13571357
13581358
Limitations
13591359
-----------
1360-
Parameter ``x1`` is supported as :obj:`dpnp.dparray` only.
13611360
Parameter ``where`` is unsupported.
13621361
Input array data types are limited by DPNP :ref:`Data types`.
13631362
@@ -1560,7 +1559,6 @@ def sum(x1, axis=None, dtype=None, out=None, keepdims=False, initial=None, where
15601559
15611560
Limitations
15621561
-----------
1563-
Parameter ``x1`` is supported as :obj:`dpnp.dparray` only.
15641562
Parameter `where`` is unsupported.
15651563
Input array data types are limited by DPNP :ref:`Data types`.
15661564

dpnp/dpnp_iface_trigonometric.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
import numpy
4444

4545
from dpnp.dpnp_algo import *
46-
from dpnp.dparray import dparray
4746
from dpnp.dpnp_utils import *
4847
import dpnp
4948

0 commit comments

Comments
 (0)