Skip to content

Conversation

@danielenricocahall
Copy link
Contributor

Addresses #21617 by ensuring the "full" and "same" case are properly handled. For simplicity, "same" just reuses "full" and truncates. To validate, a unit test has been added which uses the original data from the issue.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @danielenricocahall, 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 resolves a bug in the correlate function within the Keras NumPy API's TensorFlow backend. The changes ensure that the 'full' and 'same' correlation modes produce accurate results, aligning with standard NumPy behavior. The 'same' mode's implementation has been streamlined by leveraging the 'full' mode's output, and a new test case has been introduced to confirm the fix.

Highlights

  • Bug Fix for correlate function: The correlate function in the TensorFlow backend has been updated to correctly handle the 'full' and 'same' modes, addressing a reported issue.
  • Improved 'same' mode implementation: The 'same' correlation mode now reuses the output from the 'full' mode and truncates it, simplifying the logic and ensuring correctness.
  • New Unit Test: A dedicated unit test, test_correlate_bug, has been added to validate the fix using the specific data that caused the original issue.
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.

@danielenricocahall danielenricocahall changed the title Fix bug with correlate Fix bug with correlate for tensorflow Oct 25, 2025
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 fixes a bug in the correlate function for "full" and "same" modes. The logic for both modes has been corrected, and a new unit test has been added to verify the fix using data from the original issue. The changes look correct and the test is a good addition. I've added one suggestion to improve the code structure and robustness by using an if/elif/else block and adding explicit validation for the mode parameter, which aligns with the Keras API design guidelines on error handling.

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@codecov-commenter
Copy link

codecov-commenter commented Oct 25, 2025

Codecov Report

❌ Patch coverage is 83.33333% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.63%. Comparing base (47fcb39) to head (718a92f).
⚠️ Report is 22 commits behind head on master.

Files with missing lines Patch % Lines
keras/src/backend/tensorflow/numpy.py 83.33% 3 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #21778      +/-   ##
==========================================
- Coverage   82.69%   82.63%   -0.06%     
==========================================
  Files         573      577       +4     
  Lines       58888    59425     +537     
  Branches     9218     9315      +97     
==========================================
+ Hits        48696    49107     +411     
- Misses       7845     7913      +68     
- Partials     2347     2405      +58     
Flag Coverage Δ
keras 82.46% <83.33%> (-0.04%) ⬇️
keras-jax 63.32% <6.66%> (+0.07%) ⬆️
keras-numpy 57.55% <6.66%> (-0.17%) ⬇️
keras-openvino 34.30% <6.66%> (-0.11%) ⬇️
keras-tensorflow 64.13% <83.33%> (+0.11%) ⬆️
keras-torch 63.62% <6.66%> (+0.05%) ⬆️

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.

Copy link
Collaborator

@fchollet fchollet left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the fix

@google-ml-butler google-ml-butler bot added kokoro:force-run ready to pull Ready to be merged into the codebase labels Oct 27, 2025
@gbaned gbaned added this to PR Queue Oct 28, 2025
@github-project-automation github-project-automation bot moved this to Assigned Reviewer in PR Queue Oct 28, 2025
Copy link
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.

@danielenricocahall

Thank you for fixing this! This was a tricky one.

@google-ml-butler google-ml-butler bot removed the ready to pull Ready to be merged into the codebase label Oct 30, 2025
@danielenricocahall
Copy link
Contributor Author

Hey @hertschuh thank you for the feedback! I think I've addressed all comments - to confirm, for squeeze, we wanted to be explicit about only dropping the first and last (batch and channel) axes to ensure we don't squeeze the correlation result if it winds up being of size 1?

@hertschuh
Copy link
Collaborator

Hey @hertschuh thank you for the feedback! I think I've addressed all comments - to confirm, for squeeze, we wanted to be explicit about only dropping the first and last (batch and channel) axes to ensure we don't squeeze the correlation result if it winds up being of size 1?

Yes, exactly!

@google-ml-butler google-ml-butler bot added kokoro:force-run ready to pull Ready to be merged into the codebase labels Oct 30, 2025
@github-project-automation github-project-automation bot moved this from Assigned Reviewer to Approved by Reviewer in PR Queue Oct 30, 2025
@google-ml-butler google-ml-butler bot removed the ready to pull Ready to be merged into the codebase label Oct 30, 2025
@google-ml-butler google-ml-butler bot added kokoro:force-run ready to pull Ready to be merged into the codebase labels Oct 30, 2025
@google-ml-butler google-ml-butler bot removed the ready to pull Ready to be merged into the codebase label Oct 31, 2025
@google-ml-butler google-ml-butler bot added kokoro:force-run ready to pull Ready to be merged into the codebase labels Oct 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready to pull Ready to be merged into the codebase size:M

Projects

Status: Approved by Reviewer

Development

Successfully merging this pull request may close these issues.

6 participants