Skip to content

Commit 185c9a8

Browse files
authored
more algo module functions to desc (#850)
1 parent 2d09f58 commit 185c9a8

File tree

2 files changed

+32
-32
lines changed

2 files changed

+32
-32
lines changed

dpnp/dpnp_algo/dpnp_algo_indexing.pyx

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ cpdef dparray dpnp_choose(input, choices):
7373

7474

7575
cpdef tuple dpnp_diag_indices(n, ndim):
76-
cdef dparray res_item = dpnp.arange(n, dtype=dpnp.int64)
76+
res_item = dpnp.arange(n, dtype=dpnp.int64)
7777

7878
# yes, all are the same item
7979
result = []
@@ -123,8 +123,8 @@ cpdef utils.dpnp_descriptor dpnp_diagonal(dpnp_descriptor input, offset=0):
123123

124124
cpdef dpnp_fill_diagonal(dpnp_descriptor input, val):
125125
cdef shape_type_c input_shape = input.shape
126-
val_arr = dparray(1, dtype=input.dtype)
127-
val_arr[0] = val
126+
cdef utils.dpnp_descriptor val_arr = utils_py.create_output_descriptor_py((1,), input.dtype, None)
127+
val_arr.get_pyobj()[0] = val
128128

129129
cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(input.dtype)
130130

@@ -135,7 +135,7 @@ cpdef dpnp_fill_diagonal(dpnp_descriptor input, val):
135135
func(input.get_data(), val_arr.get_data(), < size_t * > input_shape.data(), input.ndim)
136136

137137

138-
cpdef dparray dpnp_indices(dimensions):
138+
cpdef object dpnp_indices(dimensions):
139139
len_dimensions = len(dimensions)
140140
res_shape = []
141141
res_shape.append(len_dimensions)
@@ -196,12 +196,12 @@ cpdef tuple dpnp_nonzero(dparray in_array1):
196196

197197

198198
cpdef dpnp_place(dpnp_descriptor arr, object mask, dpnp_descriptor vals):
199-
mask_ = dparray(mask.size, dtype=dpnp.int64)
199+
cdef utils.dpnp_descriptor mask_ = utils_py.create_output_descriptor_py((mask.size,), dpnp.int64, None)
200200
for i in range(mask.size):
201201
if mask[i]:
202-
mask_[i] = 1
202+
mask_.get_pyobj()[i] = 1
203203
else:
204-
mask_[i] = 0
204+
mask_.get_pyobj()[i] = 0
205205
cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(arr.dtype)
206206

207207
cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_PLACE, param1_type, param1_type)
@@ -218,23 +218,23 @@ cpdef dpnp_put(dpnp_descriptor input, object ind, v):
218218
ind_size = 1
219219
else:
220220
ind_size = len(ind)
221-
ind_array = dparray(ind_size, dtype=dpnp.int64)
221+
cdef utils.dpnp_descriptor ind_array = utils_py.create_output_descriptor_py((ind_size,), dpnp.int64, None)
222222
if dpnp.isscalar(ind):
223-
ind_array[0] = ind
223+
ind_array.get_pyobj()[0] = ind
224224
else:
225225
for i in range(ind_size):
226-
ind_array[i] = ind[i]
226+
ind_array.get_pyobj()[i] = ind[i]
227227

228228
if dpnp.isscalar(v):
229229
v_size = 1
230230
else:
231231
v_size = len(v)
232-
v_array = dparray(v_size, dtype=input.dtype)
232+
cdef utils.dpnp_descriptor v_array = utils_py.create_output_descriptor_py((v_size,), input.dtype, None)
233233
if dpnp.isscalar(v):
234-
v_array[0] = v
234+
v_array.get_pyobj()[0] = v
235235
else:
236236
for i in range(v_size):
237-
v_array[i] = v[i]
237+
v_array.get_pyobj()[i] = v[i]
238238

239239
cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(input.dtype)
240240

@@ -263,7 +263,7 @@ cpdef dpnp_putmask(object arr, object mask, object values):
263263
arr[i] = values[i % values_size]
264264

265265

266-
cpdef dparray dpnp_select(condlist, choicelist, default):
266+
cpdef object dpnp_select(condlist, choicelist, default):
267267
size_ = condlist[0].size
268268
res_array = dparray(size_, dtype=choicelist[0].dtype)
269269
pass_val = {a: default for a in range(size_)}
@@ -279,13 +279,12 @@ cpdef dparray dpnp_select(condlist, choicelist, default):
279279
return res_array.reshape(condlist[0].shape)
280280

281281

282-
cpdef dparray dpnp_take(dpnp_descriptor input, dpnp_descriptor indices):
282+
cpdef utils.dpnp_descriptor dpnp_take(utils.dpnp_descriptor input, utils.dpnp_descriptor indices):
283283
cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(input.dtype)
284284

285285
cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_TAKE, param1_type, param1_type)
286286

287-
result_type = dpnp_DPNPFuncType_to_dtype( < size_t > kernel_data.return_type)
288-
cdef dparray result = dparray(indices.shape, dtype=result_type)
287+
cdef utils.dpnp_descriptor result = utils.create_output_descriptor(indices.shape, kernel_data.return_type, None)
289288

290289
cdef custom_indexing_2in_1out_func_ptr_t func = <custom_indexing_2in_1out_func_ptr_t > kernel_data.ptr
291290

@@ -294,9 +293,10 @@ cpdef dparray dpnp_take(dpnp_descriptor input, dpnp_descriptor indices):
294293
return result
295294

296295

297-
cpdef dparray dpnp_take_along_axis(object arr, object indices, int axis):
296+
cpdef object dpnp_take_along_axis(object arr, object indices, int axis):
298297
cdef long size_arr = arr.size
299298
cdef shape_type_c shape_arr = arr.shape
299+
cdef shape_type_c output_shape
300300
cdef long size_indices = indices.size
301301
res_type = arr.dtype
302302

@@ -305,7 +305,7 @@ cpdef dparray dpnp_take_along_axis(object arr, object indices, int axis):
305305
res_shape_list[axis] = 1
306306
res_shape = tuple(res_shape_list)
307307

308-
output_shape = dparray(len(shape_arr) - 1, dtype=numpy.int64)
308+
output_shape = (0,) * (len(shape_arr) - 1)
309309
ind = 0
310310
for id, shape_axis in enumerate(shape_arr):
311311
if id != axis:
@@ -396,9 +396,9 @@ cpdef tuple dpnp_tril_indices(n, k=0, m=None):
396396
array1.append(i)
397397
array2.append(j)
398398

399-
dparray1 = dpnp.array(array1, dtype=dpnp.int64)
400-
dparray2 = dpnp.array(array2, dtype=dpnp.int64)
401-
return (dparray1, dparray2)
399+
array1 = dpnp.array(array1, dtype=dpnp.int64)
400+
array2 = dpnp.array(array2, dtype=dpnp.int64)
401+
return (array1, array2)
402402

403403

404404
cpdef tuple dpnp_tril_indices_from(dpnp_descriptor arr, k=0):
@@ -421,9 +421,9 @@ cpdef tuple dpnp_tril_indices_from(dpnp_descriptor arr, k=0):
421421
array1.append(i)
422422
array2.append(j)
423423

424-
dparray1 = dpnp.array(array1, dtype=dpnp.int64)
425-
dparray2 = dpnp.array(array2, dtype=dpnp.int64)
426-
return (dparray1, dparray2)
424+
array1 = dpnp.array(array1, dtype=dpnp.int64)
425+
array2 = dpnp.array(array2, dtype=dpnp.int64)
426+
return (array1, array2)
427427

428428

429429
cpdef tuple dpnp_triu_indices(n, k=0, m=None):
@@ -440,9 +440,9 @@ cpdef tuple dpnp_triu_indices(n, k=0, m=None):
440440
array1.append(i)
441441
array2.append(j)
442442

443-
dparray1 = dpnp.array(array1, dtype=dpnp.int64)
444-
dparray2 = dpnp.array(array2, dtype=dpnp.int64)
445-
return (dparray1, dparray2)
443+
array1 = dpnp.array(array1, dtype=dpnp.int64)
444+
array2 = dpnp.array(array2, dtype=dpnp.int64)
445+
return (array1, array2)
446446

447447

448448
cpdef tuple dpnp_triu_indices_from(dpnp_descriptor arr, k=0):
@@ -461,6 +461,6 @@ cpdef tuple dpnp_triu_indices_from(dpnp_descriptor arr, k=0):
461461
array1.append(i)
462462
array2.append(j)
463463

464-
dparray1 = dpnp.array(array1, dtype=dpnp.int64)
465-
dparray2 = dpnp.array(array2, dtype=dpnp.int64)
466-
return (dparray1, dparray2)
464+
array1 = dpnp.array(array1, dtype=dpnp.int64)
465+
array2 = dpnp.array(array2, dtype=dpnp.int64)
466+
return (array1, array2)

dpnp/dpnp_iface_indexing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ def take(x1, indices, axis=None, out=None, mode='raise'):
507507
elif mode != 'raise':
508508
pass
509509
else:
510-
return dpnp_take(x1_desc, indices_desc)
510+
return dpnp_take(x1_desc, indices_desc).get_pyobj()
511511

512512
return call_origin(numpy.take, x1, indices, axis, out, mode)
513513

0 commit comments

Comments
 (0)