@@ -322,9 +322,37 @@ def average(x, axis=None, weights=None):
322
322
323
323
324
324
def bincount (x , weights = None , minlength = 0 , sparse = False ):
325
- raise NotImplementedError (
326
- "`bincount` is not supported with openvino backend"
325
+ if x is None :
326
+ raise ValueError ("input x is None" )
327
+ x = get_ov_output (x )
328
+ x_type = x .get_element_type ()
329
+ minlength = get_ov_output (minlength )
330
+ minlength = ov_opset .convert (minlength , x_type ).output (0 )
331
+ const_one = ov_opset .constant (1 , x_type ).output (0 )
332
+ const_zero = ov_opset .constant (0 , x_type ).output (0 )
333
+ max_element = ov_opset .reduce_max (x , const_zero , keep_dims = False ).output (0 )
334
+ depth = ov_opset .add (max_element , const_one ).output (0 )
335
+ depth = ov_opset .maximum (depth , minlength ).output (0 )
336
+ depth = ov_opset .convert (depth ,x_type ).output (0 )
337
+ one_hot = ov_opset .one_hot (x , depth , const_one , const_zero , axis = - 1 ).output (
338
+ 0
327
339
)
340
+ if weights is not None :
341
+ weights = get_ov_output (weights )
342
+ weights_type = weights .get_element_type ()
343
+ weights_new = ov_opset .reshape (weights , [- 1 , 1 ], False ).output (0 )
344
+ one_hot = ov_opset .convert (one_hot , weights_type ).output (0 )
345
+ final_one_hot = ov_opset .multiply (one_hot , weights_new ).output (0 )
346
+ final_output = ov_opset .reduce_sum (
347
+ final_one_hot , const_zero , keep_dims = False
348
+ ).output (0 )
349
+ return OpenVINOKerasTensor (final_output )
350
+ else :
351
+ one_hot = ov_opset .convert (one_hot , x_type ).output (0 )
352
+ final_output = ov_opset .reduce_sum (
353
+ one_hot , const_zero , keep_dims = False
354
+ ).output (0 )
355
+ return OpenVINOKerasTensor (final_output )
328
356
329
357
330
358
def broadcast_to (x , shape ):
0 commit comments