Skip to content

Fix lu_solve with batch inputs #1394

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 2 commits into from
May 9, 2025

Conversation

ricardoV94
Copy link
Member

@ricardoV94 ricardoV94 commented May 8, 2025

Closes #1376


📚 Documentation preview 📚: https://pytensor--1394.org.readthedocs.build/en/1394/

@ricardoV94 ricardoV94 added the bug Something isn't working label May 8, 2025
@ricardoV94 ricardoV94 force-pushed the fix_lu_solve_batch_dims branch from 3098cc7 to b8a1ede Compare May 8, 2025 16:24
@ricardoV94 ricardoV94 force-pushed the fix_lu_solve_batch_dims branch from b8a1ede to de031b7 Compare May 8, 2025 17:07
Copy link

codecov bot commented May 8, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.02%. Comparing base (afe934b) to head (de031b7).
Report is 3 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1394   +/-   ##
=======================================
  Coverage   82.02%   82.02%           
=======================================
  Files         207      207           
  Lines       49294    49301    +7     
  Branches     8746     8747    +1     
=======================================
+ Hits        40433    40440    +7     
  Misses       6695     6695           
  Partials     2166     2166           
Files with missing lines Coverage Δ
pytensor/tensor/slinalg.py 93.18% <100.00%> (+0.07%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR addresses a bug in lu_solve when handling batch inputs and cleans up test function calls. The changes include replacing all instances of “pytensor.function” with “function” in the tests and refactoring lu_solve into a private _lu_solve that is then vectorized via a new public lu_solve.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
tests/tensor/test_slinalg.py Updated function calls and added a new test for lu_solve with batch dimensions.
pytensor/tensor/slinalg.py Refactored lu_solve to support vectorized batch operations and updated imports.

b = pt.tensor("b", shape=(1, 4, 5))
lu_and_pivots = lu_factor(A)
x = lu_solve(lu_and_pivots, b, b_ndim=1)
assert x.type.shape in {(3, 4, None), (3, 4, 5)}
Copy link
Preview

Copilot AI May 8, 2025

Choose a reason for hiding this comment

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

[nitpick] The assertion on x.type.shape uses a set containing None, which may be brittle or ambiguous. Consider clarifying the expected shape explicitly to improve test robustness.

Suggested change
assert x.type.shape in {(3, 4, None), (3, 4, 5)}
assert x.type.shape == (3, 4, 5) or (x.type.shape[:2] == (3, 4) and x.type.shape[2] is None)

Copilot uses AI. Check for mistakes.

Copy link
Member Author

Choose a reason for hiding this comment

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

This was on purpose, right now it returns None, but if we improve static type it should return 5 and won't make the test fail

@@ -508,8 +507,8 @@ def test_infer_shape(self):
A = matrix()
b = matrix()
self._compile_and_check(
[A, b], # pytensor.function inputs
[self.op_class(b_ndim=2)(A, b)], # pytensor.function outputs
[A, b], # function inputs
Copy link
Member

Choose a reason for hiding this comment

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

These comments are silly anyway, just use a keyword argument?

Copy link
Member Author

Choose a reason for hiding this comment

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

That was a find replace spill over to comments

Copy link
Member

Choose a reason for hiding this comment

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

The comments are still stupid >:(

Copy link
Member Author

Choose a reason for hiding this comment

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

But I didn't add them :D

@ricardoV94 ricardoV94 merged commit 5335a68 into pymc-devs:main May 9, 2025
73 checks passed
@ricardoV94 ricardoV94 deleted the fix_lu_solve_batch_dims branch May 9, 2025 08:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

lu_solve doesn't work with batched inputs
2 participants