@@ -36,7 +36,7 @@ import dpnp
36
36
cimport dpnp.dpnp_utils as utils
37
37
import dpnp.dpnp_utils as utils_py
38
38
from dpnp.dpnp_algo cimport *
39
- from dpnp.dparray cimport dparray
39
+
40
40
import numpy
41
41
cimport numpy
42
42
@@ -202,7 +202,7 @@ cpdef utils.dpnp_descriptor dpnp_matrix_rank(utils.dpnp_descriptor input):
202
202
return result
203
203
204
204
205
- cpdef dparray dpnp_norm(dparray input , ord = None , axis = None ):
205
+ cpdef object dpnp_norm(object input , ord = None , axis = None ):
206
206
cdef long size_input = input .size
207
207
cdef shape_type_c shape_input = input .shape
208
208
@@ -246,14 +246,14 @@ cpdef dparray dpnp_norm(dparray input, ord=None, axis=None):
246
246
else :
247
247
absx = dpnp.abs(input )
248
248
absx_size = absx.size
249
- absx_power = dparray( absx_size, dtype = absx.dtype)
249
+ absx_power = utils_py.create_output_descriptor_py(( absx_size,), absx.dtype, None ).get_pyobj( )
250
250
for i in range (absx_size):
251
251
absx_elem = absx.item(i)
252
252
absx_power[i] = absx_elem ** ord
253
253
absx_ = absx_power.reshape(absx.shape)
254
254
ret = dpnp.sum(absx_, axis = axis)
255
255
ret_size = ret.size
256
- ret_power = dparray( ret_size)
256
+ ret_power = utils_py.create_output_descriptor_py(( ret_size,), None , None ).get_pyobj( )
257
257
for i in range (ret_size):
258
258
ret_elem = ret.item(i)
259
259
ret_power[i] = ret_elem ** (1 / ord )
@@ -270,86 +270,73 @@ cpdef dparray dpnp_norm(dparray input, ord=None, axis=None):
270
270
elif ord == 1 :
271
271
if col_axis > row_axis:
272
272
col_axis -= 1
273
- dpnp_sum_val_ = dpnp.sum(dpnp.abs(input ), axis = row_axis)
274
- dpnp_sum_val = dpnp_sum_val_ if isinstance (dpnp_sum_val_, dparray) else dpnp.array([dpnp_sum_val_])
275
- dpnp_max_val = dpnp_sum_val.min(axis = col_axis)
276
- ret = dpnp_max_val if isinstance (dpnp_max_val, dparray) else dpnp.array([dpnp_max_val])
273
+ dpnp_sum_val = dpnp.sum(dpnp.abs(input ), axis = row_axis)
274
+ ret = dpnp_sum_val.min(axis = col_axis)
277
275
elif ord == numpy.inf:
278
276
if row_axis > col_axis:
279
277
row_axis -= 1
280
- dpnp_sum_val_ = dpnp.sum(dpnp.abs(input ), axis = col_axis)
281
- dpnp_sum_val = dpnp_sum_val_ if isinstance (dpnp_sum_val_, dparray) else dpnp.array([dpnp_sum_val_])
282
- dpnp_max_val = dpnp_sum_val.max(axis = row_axis)
283
- ret = dpnp_max_val if isinstance (dpnp_max_val, dparray) else dpnp.array([dpnp_max_val])
278
+ dpnp_sum_val = dpnp.sum(dpnp.abs(input ), axis = col_axis)
279
+ ret = dpnp_sum_val.max(axis = row_axis)
284
280
elif ord == - 1 :
285
281
if col_axis > row_axis:
286
282
col_axis -= 1
287
- dpnp_sum_val_ = dpnp.sum(dpnp.abs(input ), axis = row_axis)
288
- dpnp_sum_val = dpnp_sum_val_ if isinstance (dpnp_sum_val_, dparray) else dpnp.array([dpnp_sum_val_])
289
- dpnp_min_val = dpnp_sum_val.min(axis = col_axis)
290
- ret = dpnp_min_val if isinstance (dpnp_min_val, dparray) else dpnp.array([dpnp_min_val])
283
+ dpnp_sum_val = dpnp.sum(dpnp.abs(input ), axis = row_axis)
284
+ ret = dpnp_sum_val.min(axis = col_axis)
291
285
elif ord == - numpy.inf:
292
286
if row_axis > col_axis:
293
287
row_axis -= 1
294
- dpnp_sum_val_ = dpnp.sum(dpnp.abs(input ), axis = col_axis)
295
- dpnp_sum_val = dpnp_sum_val_ if isinstance (dpnp_sum_val_, dparray) else dpnp.array([dpnp_sum_val_])
296
- dpnp_min_val = dpnp_sum_val.min(axis = row_axis)
297
- ret = dpnp_min_val if isinstance (dpnp_min_val, dparray) else dpnp.array([dpnp_min_val])
288
+ dpnp_sum_val = dpnp.sum(dpnp.abs(input ), axis = col_axis)
289
+ ret = dpnp_sum_val.min(axis = row_axis)
298
290
elif ord in [None , ' fro' , ' f' ]:
299
291
ret = dpnp.sqrt(dpnp.sum(input * input , axis = axis))
300
292
# elif ord == 'nuc':
301
293
# ret = _multi_svd_norm(input, row_axis, col_axis, sum)
302
294
else :
303
295
raise ValueError (" Invalid norm order for matrices." )
296
+
304
297
return ret
305
298
else :
306
299
raise ValueError (" Improper number of dimensions to norm." )
307
300
308
301
309
- cpdef tuple dpnp_qr(dparray x1, mode):
302
+ cpdef tuple dpnp_qr(utils.dpnp_descriptor x1, str mode):
310
303
cdef size_t size_m = x1.shape[0 ]
311
304
cdef size_t size_n = x1.shape[1 ]
305
+ cdef size_t size_tau = min (size_m, size_n)
312
306
313
307
cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(x1.dtype)
314
308
cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_QR, param1_type, param1_type)
315
309
316
- result_type = dpnp_DPNPFuncType_to_dtype( < size_t > kernel_data.return_type)
317
-
318
- cdef dparray res_q = dparray((size_m, size_m), dtype = result_type)
319
- cdef dparray res_r = dparray((size_m, size_n), dtype = result_type)
320
-
321
- size_tau = min (size_m, size_n)
322
- cdef dparray tau = dparray((size_tau, ), dtype = result_type)
310
+ cdef utils.dpnp_descriptor res_q = utils.create_output_descriptor((size_m, size_m), kernel_data.return_type, None )
311
+ cdef utils.dpnp_descriptor res_r = utils.create_output_descriptor((size_m, size_n), kernel_data.return_type, None )
312
+ cdef utils.dpnp_descriptor tau = utils.create_output_descriptor((size_tau, ), kernel_data.return_type, None )
323
313
324
314
cdef custom_linalg_1in_3out_shape_t func = < custom_linalg_1in_3out_shape_t > kernel_data.ptr
325
315
326
316
func(x1.get_data(), res_q.get_data(), res_r.get_data(), tau.get_data(), size_m, size_n)
327
317
328
- return (res_q, res_r)
318
+ return (res_q.get_pyobj() , res_r.get_pyobj() )
329
319
330
320
331
- cpdef tuple dpnp_svd(dparray x1, full_matrices, compute_uv, hermitian):
321
+ cpdef tuple dpnp_svd(utils.dpnp_descriptor x1, cpp_bool full_matrices, cpp_bool compute_uv, cpp_bool hermitian):
332
322
cdef size_t size_m = x1.shape[0 ]
333
323
cdef size_t size_n = x1.shape[1 ]
324
+ cdef size_t size_s = min (size_m, size_n)
334
325
335
326
cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(x1.dtype)
336
327
cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_SVD, param1_type, param1_type)
337
328
338
- result_type = dpnp_DPNPFuncType_to_dtype( < size_t > kernel_data.return_type)
339
-
329
+ cdef DPNPFuncType type_s = DPNP_FT_DOUBLE
340
330
if x1.dtype == dpnp.float32:
341
- type_s = dpnp.float32
342
- else :
343
- type_s = dpnp.float64
331
+ type_s = DPNP_FT_FLOAT
344
332
345
- size_s = min (size_m, size_n)
346
333
347
- cdef dparray res_u = dparray ((size_m, size_m), dtype = result_type )
348
- cdef dparray res_s = dparray ((size_s, ), dtype = type_s)
349
- cdef dparray res_vt = dparray ((size_n, size_n), dtype = result_type )
334
+ cdef utils.dpnp_descriptor res_u = utils.create_output_descriptor ((size_m, size_m), kernel_data.return_type, None )
335
+ cdef utils.dpnp_descriptor res_s = utils.create_output_descriptor ((size_s, ), type_s, None )
336
+ cdef utils.dpnp_descriptor res_vt = utils.create_output_descriptor ((size_n, size_n), kernel_data.return_type, None )
350
337
351
338
cdef custom_linalg_1in_3out_shape_t func = < custom_linalg_1in_3out_shape_t > kernel_data.ptr
352
339
353
340
func(x1.get_data(), res_u.get_data(), res_s.get_data(), res_vt.get_data(), size_m, size_n)
354
341
355
- return (res_u, res_s, res_vt)
342
+ return (res_u.get_pyobj() , res_s.get_pyobj() , res_vt.get_pyobj() )
0 commit comments