Skip to content

Implement nanpercentile function in keras.ops#22679

Merged
hertschuh merged 13 commits intokeras-team:masterfrom
shashaka:nanpercentile
Apr 21, 2026
Merged

Implement nanpercentile function in keras.ops#22679
hertschuh merged 13 commits intokeras-team:masterfrom
shashaka:nanpercentile

Conversation

@shashaka
Copy link
Copy Markdown
Collaborator

@shashaka shashaka commented Apr 15, 2026

Description

Adds keras.ops.nanpercentile, which computes the q-th percentile of the input tensor along a specified axis while ignoring NaN values.
Supported across NumPy, TensorFlow, PyTorch, and JAX backends. Not supported on OpenVINO.

Contributor Agreement

Please check all boxes below before submitting your PR for review:

  • I am a human, and not a bot.
  • I will be responsible for responding to review comments in a timely manner.
  • I will work with the maintainers to push this PR forward until submission.

Note: Failing to adhere to this agreement may result in your future PRs no longer being reviewed.

Copy link
Copy Markdown
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 implements the nanpercentile operation across Keras backends, including JAX, NumPy, TensorFlow, and Torch, while marking it as unimplemented for OpenVINO. The implementation includes the core Nanpercentile operation, API exports, and extensive unit tests. Feedback focuses on improving the robustness of compute_output_spec regarding multi-dimensional percentile inputs and integer dtype promotion, as well as ensuring consistent tensor conversion and floating-point casting of the q parameter across the NumPy and Torch backends.

Comment thread keras/src/ops/numpy.py
Comment thread keras/src/backend/numpy/numpy.py
Comment thread keras/src/backend/torch/numpy.py Outdated
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 15, 2026

Codecov Report

❌ Patch coverage is 89.79592% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.00%. Comparing base (90e0c5e) to head (5209df1).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
keras/src/ops/numpy.py 87.50% 2 Missing and 1 partial ⚠️
keras/api/_tf_keras/keras/ops/__init__.py 0.00% 1 Missing ⚠️
keras/api/_tf_keras/keras/ops/numpy/__init__.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master   #22679   +/-   ##
=======================================
  Coverage   82.99%   83.00%           
=======================================
  Files         596      596           
  Lines       69629    69678   +49     
  Branches    10863    10869    +6     
=======================================
+ Hits        57792    57836   +44     
- Misses       8991     8995    +4     
- Partials     2846     2847    +1     
Flag Coverage Δ
keras 82.82% <89.79%> (+<0.01%) ⬆️
keras-jax 58.43% <61.22%> (+<0.01%) ⬆️
keras-numpy 54.29% <69.38%> (+0.01%) ⬆️
keras-openvino 59.67% <44.89%> (-0.02%) ⬇️
keras-tensorflow 59.99% <61.22%> (+<0.01%) ⬆️
keras-torch 58.76% <61.22%> (+<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.

@keerthanakadiri keerthanakadiri added the stat:awaiting keras-eng Awaiting response from Keras engineer label Apr 17, 2026
@shashaka shashaka requested a review from hertschuh April 19, 2026 11:59
Copy link
Copy Markdown
Collaborator

@hertschuh hertschuh left a comment

Choose a reason for hiding this comment

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

Thanks!

But I'm realizing now that we don't even have ops.numpy.percentile right now.

@google-ml-butler google-ml-butler Bot added kokoro:force-run ready to pull Ready to be merged into the codebase labels Apr 20, 2026
@shashaka
Copy link
Copy Markdown
Collaborator Author

I’ll take a look and add a implementation for ops.numpy.percentile.

@google-ml-butler google-ml-butler Bot removed the ready to pull Ready to be merged into the codebase label Apr 21, 2026
@hertschuh hertschuh merged commit 40d635f into keras-team:master Apr 21, 2026
11 checks passed
@shashaka shashaka deleted the nanpercentile branch April 21, 2026 04:58
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.

5 participants