Skip to content

[OpenVINO backend] Fix array(), maximum(), minimum(), reshape() and split() ops in the numpy suite#22319

Open
goyaladitya05 wants to merge 3 commits intokeras-team:masterfrom
goyaladitya05:openvino/fix-numpy-array-reshape-maximum-minimum
Open

[OpenVINO backend] Fix array(), maximum(), minimum(), reshape() and split() ops in the numpy suite#22319
goyaladitya05 wants to merge 3 commits intokeras-team:masterfrom
goyaladitya05:openvino/fix-numpy-array-reshape-maximum-minimum

Conversation

@goyaladitya05
Copy link
Contributor

This PR focuses on improving the implementations for array(), maximum(), minimum(), reshape() and split() for the OpenVINO Backend in the numpy suite.

  • array() - replaced np.array() with convert_to_tensor() so the return value is always an OpenVINOKerasTensor instead of a raw NumPy array, making it consistent with other ops in the backend.
  • maximum() / minimum() - added the t1/t2 dtype-extraction step (same pattern as add(), subtract(), multiply()) so Python int/float literals are promoted using JAX weak-type semantics instead of being unconditionally cast to int32/float32
  • reshape() - added a guard for integer newshape (e.g. Reshape(-1)), wrapping it in a list before passing to ov_opset.constant() which requires a 1-D shape tensor
  • split() - handle OpenVINOKerasTensor as indices_or_sections by extracting the underlying constant data via get_node().get_data(); this was a side-effect of the array() fix and also covers hsplit() / vsplit() which delegate to split()

Included the relevent tests from excluded_concrete_tests.txt.

Closes: openvinotoolkit/openvino/issues/34409

…plit() numpy ops

- array(): use convert_to_tensor() instead of np.array() so the result
  is always an OpenVINOKerasTensor rather than a raw NumPy array
- maximum() / minimum(): apply the same t1/t2 dtype-extraction pattern
  used by add() / subtract() / multiply() so that Python int/float
  literals are promoted according to JAX weak-type semantics
- reshape(): wrap a bare integer newshape in a list before passing it
  to ov_opset.constant(), which requires a 1-D shape tensor
- split(): extract constant data from an OpenVINOKerasTensor passed as
  indices_or_sections (side-effect of the array() fix); also fixes
  hsplit() and vsplit() which delegate to split()
@goyaladitya05 goyaladitya05 changed the title [OpenVINO backend] Fix array(), maximum(), minimum(), reshape() and split() ops in numpy suite [OpenVINO backend] Fix array(), maximum(), minimum(), reshape() and split() ops in the numpy suite Mar 1, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the robustness and consistency of several core NumPy operations within the OpenVINO backend. By refining how array(), maximum(), minimum(), reshape(), and split() handle various input types and internal representations, it ensures more predictable behavior and better integration with the OpenVINO graph. These changes address specific edge cases and align the backend's implementation with expected NumPy and JAX semantics, leading to a more reliable and compliant OpenVINO backend.

Highlights

  • Numpy array() function: The array() function now consistently returns an OpenVINOKerasTensor by replacing np.array() with convert_to_tensor(), aligning with other backend operations.
  • Numpy maximum() and minimum() functions: The maximum() and minimum() functions have been updated to correctly promote Python int/float literals using JAX weak-type semantics, preventing unconditional casting to int32/float32.
  • Numpy reshape() function: The reshape() function now properly handles integer newshape arguments (e.g., reshape(-1)) by wrapping them in a list before passing to ov_opset.constant().
  • Numpy split() function: The split() function can now accept an OpenVINOKerasTensor as indices_or_sections, extracting its underlying constant data to ensure proper splitting behavior.
  • Test suite updates: Several previously excluded tests related to array, maximum, minimum, and reshape operations have been re-enabled in excluded_concrete_tests.txt, indicating improved correctness for these functions.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • keras/src/backend/openvino/excluded_concrete_tests.txt
    • Removed NumpyDtypeTest::test_array from the exclusion list.
    • Removed NumpyDtypeTest::test_maximum_python_types from the exclusion list.
    • Removed NumpyDtypeTest::test_minimum_python_types from the exclusion list.
    • Removed NumpyOneInputOpsCorrectnessTest::test_array from the exclusion list.
    • Removed NumpyOneInputOpsCorrectnessTest::test_reshape from the exclusion list.
  • keras/src/backend/openvino/numpy.py
    • Modified array() to use convert_to_tensor() for consistent OpenVINOKerasTensor return.
    • Implemented dtype-extraction and promotion for maximum() to support Python int/float literals with JAX weak-type semantics.
    • Implemented dtype-extraction and promotion for minimum() to support Python int/float literals with JAX weak-type semantics.
    • Added a guard in reshape() to wrap integer newshape arguments in a list.
    • Added handling in split() for OpenVINOKerasTensor as indices_or_sections by extracting constant data.
Activity
  • No human activity has occurred on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces several important fixes for the OpenVINO backend's numpy operations, enhancing correctness and consistency. The changes for array(), reshape(), and split() are well-implemented and address the described issues effectively. The fixes for maximum() and minimum() correctly align their behavior with other binary operations by adding proper type promotion logic. While this follows an existing pattern, it also duplicates a significant block of code. I've added comments suggesting a refactoring to improve maintainability.

@goyaladitya05 goyaladitya05 force-pushed the openvino/fix-numpy-array-reshape-maximum-minimum branch from 8da27ad to 80f37e5 Compare March 1, 2026 06:38
@codecov-commenter
Copy link

codecov-commenter commented Mar 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.75%. Comparing base (4f85917) to head (0ad936b).

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #22319      +/-   ##
==========================================
+ Coverage   82.73%   82.75%   +0.01%     
==========================================
  Files         594      594              
  Lines       65732    65722      -10     
  Branches    10266    10267       +1     
==========================================
+ Hits        54385    54386       +1     
+ Misses       8711     8696      -15     
- Partials     2636     2640       +4     
Flag Coverage Δ
keras 82.57% <100.00%> (+0.01%) ⬆️
keras-jax 60.92% <14.28%> (+0.01%) ⬆️
keras-numpy 55.12% <0.00%> (+<0.01%) ⬆️
keras-openvino 39.35% <100.00%> (+0.01%) ⬆️
keras-tensorflow 62.17% <14.28%> (+0.01%) ⬆️
keras-torch 61.03% <14.28%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Keras 3 OpenVINO backend]: Improve support for array(), maximum(), minimum(), reshape() and split() operations

3 participants