@@ -40,7 +40,6 @@ __all__ += [
40
40
" dpnp_correlate" ,
41
41
" dpnp_cov" ,
42
42
" dpnp_max" ,
43
- " dpnp_mean" ,
44
43
" dpnp_median" ,
45
44
" dpnp_min" ,
46
45
" dpnp_nanvar" ,
@@ -302,152 +301,6 @@ cpdef utils.dpnp_descriptor dpnp_max(utils.dpnp_descriptor x1, axis):
302
301
303
302
return _dpnp_max(x1, axis_, output_shape)
304
303
305
-
306
- cpdef utils.dpnp_descriptor _dpnp_mean(utils.dpnp_descriptor x1):
307
- cdef shape_type_c x1_shape = x1.shape
308
- cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(x1.dtype)
309
-
310
- cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_MEAN_EXT, param1_type, param1_type)
311
-
312
- x1_obj = x1.get_array()
313
-
314
- cdef utils.dpnp_descriptor result = utils.create_output_descriptor((1 ,),
315
- kernel_data.return_type,
316
- None ,
317
- device = x1_obj.sycl_device,
318
- usm_type = x1_obj.usm_type,
319
- sycl_queue = x1_obj.sycl_queue)
320
-
321
- result_sycl_queue = result.get_array().sycl_queue
322
-
323
- cdef c_dpctl.SyclQueue q = < c_dpctl.SyclQueue> result_sycl_queue
324
- cdef c_dpctl.DPCTLSyclQueueRef q_ref = q.get_queue_ref()
325
-
326
- cdef custom_statistic_1in_1out_func_ptr_t func = < custom_statistic_1in_1out_func_ptr_t > kernel_data.ptr
327
-
328
- # stub for interface support
329
- cdef shape_type_c axis
330
- cdef Py_ssize_t axis_size = 0
331
-
332
- cdef c_dpctl.DPCTLSyclEventRef event_ref = func(q_ref,
333
- x1.get_data(),
334
- result.get_data(),
335
- x1_shape.data(),
336
- x1.ndim,
337
- axis.data(),
338
- axis_size,
339
- NULL ) # dep_events_ref
340
-
341
- with nogil: c_dpctl.DPCTLEvent_WaitAndThrow(event_ref)
342
- c_dpctl.DPCTLEvent_Delete(event_ref)
343
-
344
- return result
345
-
346
-
347
- cpdef object dpnp_mean(utils.dpnp_descriptor x1, axis):
348
- cdef shape_type_c output_shape
349
-
350
- if axis is None :
351
- return _dpnp_mean(x1).get_pyobj()
352
-
353
- cdef long x1_size = x1.size
354
- cdef shape_type_c x1_shape = x1.shape
355
-
356
- if x1.dtype == dpnp.float32:
357
- res_type = dpnp.float32
358
- else :
359
- res_type = dpnp.float64
360
-
361
- if x1_size == 0 :
362
- return dpnp.array([dpnp.nan], dtype = res_type)
363
-
364
- if isinstance (axis, int ):
365
- axis_ = tuple ([axis])
366
- else :
367
- axis_ = axis
368
-
369
- if axis_ is None :
370
- output_shape.push_back(1 )
371
- else :
372
- output_shape = (0 , ) * (len (x1_shape) - len (axis_))
373
- ind = 0
374
- for id , shape_axis in enumerate (x1_shape):
375
- if id not in axis_:
376
- output_shape[ind] = shape_axis
377
- ind += 1
378
-
379
- cdef long prod = 1
380
- for i in range (len (output_shape)):
381
- if output_shape[i] != 0 :
382
- prod *= output_shape[i]
383
-
384
- result_array = [None ] * prod
385
- input_shape_offsets = [None ] * len (x1_shape)
386
- acc = 1
387
-
388
- for i in range (len (x1_shape)):
389
- ind = len (x1_shape) - 1 - i
390
- input_shape_offsets[ind] = acc
391
- acc *= x1_shape[ind]
392
-
393
- output_shape_offsets = [None ] * len (x1_shape)
394
- acc = 1
395
-
396
- if axis_ is not None :
397
- for i in range (len (output_shape)):
398
- ind = len (output_shape) - 1 - i
399
- output_shape_offsets[ind] = acc
400
- acc *= output_shape[ind]
401
- result_offsets = input_shape_offsets[:] # need copy. not a reference
402
- for i in axis_:
403
- result_offsets[i] = 0
404
-
405
- for source_idx in range (x1_size):
406
-
407
- # reconstruct x,y,z from linear source_idx
408
- xyz = []
409
- remainder = source_idx
410
- for i in input_shape_offsets:
411
- quotient, remainder = divmod (remainder, i)
412
- xyz.append(quotient)
413
-
414
- # extract result axis
415
- result_axis = []
416
- if axis_ is None :
417
- result_axis = xyz
418
- else :
419
- for idx, offset in enumerate (xyz):
420
- if idx not in axis_:
421
- result_axis.append(offset)
422
-
423
- # Construct result offset
424
- result_offset = 0
425
- if axis_ is not None :
426
- for i, result_axis_val in enumerate (result_axis):
427
- result_offset += (output_shape_offsets[i] * result_axis_val)
428
-
429
- input_elem = input .get_pyobj().item(source_idx)
430
- if axis_ is None :
431
- if result_array[0 ] is None :
432
- result_array[0 ] = input_elem
433
- else :
434
- result_array[0 ] += input_elem
435
- else :
436
- if result_array[result_offset] is None :
437
- result_array[result_offset] = input_elem
438
- else :
439
- result_array[result_offset] += input_elem
440
-
441
- del_ = x1_size
442
- if axis_ is not None :
443
- for i in range (len (x1_shape)):
444
- if i not in axis_:
445
- del_ = del_ / x1_shape[i]
446
- dpnp_array = dpnp.array(result_array, dtype = input .dtype)
447
- dpnp_result_array = dpnp.reshape(dpnp_array, output_shape)
448
- return dpnp_result_array / del_
449
-
450
-
451
304
cpdef utils.dpnp_descriptor dpnp_median(utils.dpnp_descriptor array1):
452
305
cdef shape_type_c x1_shape = array1.shape
453
306
cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(array1.dtype)
0 commit comments