Skip to content

Commit e7a16d2

Browse files
authored
module indexing to desc completed (#862)
1 parent 5d3d2f4 commit e7a16d2

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

dpnp/dpnp_algo/dpnp_algo_indexing.pyx

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,13 @@ cpdef object dpnp_indices(dimensions):
171171
return dpnp_result
172172

173173

174-
cpdef tuple dpnp_nonzero(dparray in_array1):
174+
cpdef tuple dpnp_nonzero(utils.dpnp_descriptor in_array1):
175175
cdef shape_type_c shape_arr = in_array1.shape
176176
res_count = in_array1.ndim
177177

178178
# have to go through array one extra time to count size of result arrays
179-
res_size = dpnp.count_nonzero(in_array1)
179+
res_size_obj = dpnp_count_nonzero(in_array1)
180+
cdef size_t res_size = dpnp.convert_single_elem_array_to_scalar(res_size_obj.get_pyobj())
180181

181182
cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(in_array1.dtype)
182183

@@ -185,12 +186,15 @@ cpdef tuple dpnp_nonzero(dparray in_array1):
185186
cdef fptr_dpnp_nonzero_t func = <fptr_dpnp_nonzero_t > kernel_data.ptr
186187

187188
res_list = []
189+
cdef utils.dpnp_descriptor res_arr
190+
cdef shape_type_c result_shape
188191
for j in range(res_count):
189-
res_arr = dparray((res_size, ), dtype=dpnp.int64)
192+
result_shape = utils._object_to_tuple(res_size)
193+
res_arr = utils_py.create_output_descriptor_py(result_shape, dpnp.int64, None)
190194

191195
func(in_array1.get_data(), res_arr.get_data(), < size_t * > shape_arr.data(), in_array1.ndim, j)
192196

193-
res_list.append(res_arr)
197+
res_list.append(res_arr.get_pyobj())
194198

195199
result = utils._object_to_tuple(res_list)
196200

@@ -266,19 +270,20 @@ cpdef dpnp_putmask(object arr, object mask, object values):
266270

267271

268272
cpdef object dpnp_select(condlist, choicelist, default):
269-
size_ = condlist[0].size
270-
res_array = dparray(size_, dtype=choicelist[0].dtype)
273+
cdef size_t size_ = condlist[0].size
274+
cdef utils.dpnp_descriptor res_array = utils_py.create_output_descriptor_py(condlist[0].shape, choicelist[0].dtype, None)
275+
271276
pass_val = {a: default for a in range(size_)}
272277
for i in range(len(condlist)):
273278
for j in range(size_):
274279
if (condlist[i])[j]:
275-
res_array[j] = (choicelist[i])[j]
280+
res_array.get_pyobj()[j] = (choicelist[i])[j]
276281
pass_val.pop(j)
277282

278283
for ind, val in pass_val.items():
279-
res_array[ind] = val
284+
res_array.get_pyobj()[ind] = val
280285

281-
return res_array.reshape(condlist[0].shape)
286+
return res_array
282287

283288

284289
cpdef utils.dpnp_descriptor dpnp_take(utils.dpnp_descriptor input, utils.dpnp_descriptor indices):
@@ -373,7 +378,7 @@ cpdef object dpnp_take_along_axis(object arr, object indices, int axis):
373378
return dpnp_result_array
374379

375380
else:
376-
result_array = dparray(shape_arr, dtype=res_type)
381+
result_array = utils_py.create_output_descriptor_py(shape_arr, res_type, None).get_pyobj()
377382
for i in range(size_arr):
378383
ind = size_indices * (i // size_indices) + indices[i % size_indices]
379384
result_array[i] = arr[ind]

dpnp/dpnp_iface_indexing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ def nonzero(x1):
345345

346346
x1_desc = dpnp.get_dpnp_descriptor(x1)
347347
if x1_desc:
348-
return dpnp_nonzero(x1)
348+
return dpnp_nonzero(x1_desc)
349349

350350
return call_origin(numpy.nonzero, x1)
351351

0 commit comments

Comments
 (0)