Skip to content

Commit

Permalink
[OpenVino BackEnd]support np.count_nonzero for ov BackEnd (#20945)
Browse files Browse the repository at this point in the history
* suppoer np.count_nonzero for ov BackEnd

* modifing function vars to lowercase
  • Loading branch information
Mohamed-Ashraf273 authored Feb 28, 2025
1 parent 21c8997 commit 0902ff4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
2 changes: 0 additions & 2 deletions keras/src/backend/openvino/excluded_concrete_tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ NumpyDtypeTest::test_bitwise
NumpyDtypeTest::test_ceil
NumpyDtypeTest::test_concatenate
NumpyDtypeTest::test_correlate
NumpyDtypeTest::test_count_nonzero
NumpyDtypeTest::test_cross
NumpyDtypeTest::test_cumprod
NumpyDtypeTest::test_cumsum_bool
Expand Down Expand Up @@ -99,7 +98,6 @@ NumpyOneInputOpsCorrectnessTest::test_bincount
NumpyOneInputOpsCorrectnessTest::test_bitwise_invert
NumpyOneInputOpsCorrectnessTest::test_conj
NumpyOneInputOpsCorrectnessTest::test_correlate
NumpyOneInputOpsCorrectnessTest::test_count_nonzero
NumpyOneInputOpsCorrectnessTest::test_cumprod
NumpyOneInputOpsCorrectnessTest::test_diag
NumpyOneInputOpsCorrectnessTest::test_diagonal
Expand Down
18 changes: 15 additions & 3 deletions keras/src/backend/openvino/numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,9 +444,21 @@ def cosh(x):


def count_nonzero(x, axis=None):
raise NotImplementedError(
"`count_nonzero` is not supported with openvino backend"
)
x = get_ov_output(x)
zero_constant = ov_opset.constant(0, dtype=Type.i32).output(0)
zero_constant = ov_opset.convert_like(zero_constant, x)
x = ov_opset.not_equal(x, zero_constant).output(0)
x = ov_opset.convert(x, Type.i32).output(0)
if axis is None:
flatten_shape = ov_opset.constant([-1], Type.i32).output(0)
x = ov_opset.reshape(x, flatten_shape, False).output(0)
axis = 0
if isinstance(axis, tuple):
axis = list(axis)
if axis == []:
return OpenVINOKerasTensor(x)
axis = ov_opset.constant(axis, Type.i32).output(0)
return OpenVINOKerasTensor(ov_opset.reduce_sum(x, axis, False).output(0))


def cross(x1, x2, axisa=-1, axisb=-1, axisc=-1, axis=None):
Expand Down

0 comments on commit 0902ff4

Please sign in to comment.