Skip to content

[OpenVINO Backend] Support numpy min operation #21168

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions keras/src/backend/openvino/excluded_concrete_tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ NumpyDtypeTest::test_max
NumpyDtypeTest::test_mean
NumpyDtypeTest::test_median
NumpyDtypeTest::test_meshgrid
NumpyDtypeTest::test_min
NumpyDtypeTest::test_minimum_python_types
NumpyDtypeTest::test_moveaxis
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add line with NumpyDtypeTest::test_minimum_python_types

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added it. Thank you!

NumpyDtypeTest::test_multiply
NumpyDtypeTest::test_nan
Expand Down Expand Up @@ -95,7 +95,6 @@ NumpyOneInputOpsCorrectnessTest::test_max
NumpyOneInputOpsCorrectnessTest::test_mean
NumpyOneInputOpsCorrectnessTest::test_median
NumpyOneInputOpsCorrectnessTest::test_meshgrid
NumpyOneInputOpsCorrectnessTest::test_min
NumpyOneInputOpsCorrectnessTest::test_moveaxis
NumpyOneInputOpsCorrectnessTest::test_nan_to_num
NumpyOneInputOpsCorrectnessTest::test_ndim
Expand Down
41 changes: 40 additions & 1 deletion keras/src/backend/openvino/numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,46 @@ def meshgrid(*x, indexing="xy"):


def min(x, axis=None, keepdims=False, initial=None):
raise NotImplementedError("`min` is not supported with openvino backend")
x = get_ov_output(x)
original_type = x.get_element_type()
x_type = original_type
x_shape = x.get_partial_shape().to_shape()

is_bool = x_type == Type.boolean
if is_bool:
x = ov_opset.convert(x, Type.i32).output(0)
x_type = Type.i32

if isinstance(axis, tuple) and len(axis) == 0:
return OpenVINOKerasTensor(x)

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)

axis_const = ov_opset.constant(axis, Type.i32).output(0)
min_result = ov_opset.reduce_min(x, axis_const, keepdims).output(0)

if initial is not None:
initial_tensor = ov_opset.constant(initial, x_type).output(0)
min_result = ov_opset.minimum(min_result, initial_tensor).output(0)

if keepdims:
result_shape = [1] * len(x_shape)
min_result = ov_opset.reshape(
min_result,
ov_opset.constant(result_shape, Type.i32).output(0),
False,
).output(0)

if is_bool:
min_result = ov_opset.convert(min_result, Type.boolean).output(0)

return OpenVINOKerasTensor(min_result)


def minimum(x1, x2):
Expand Down