Repository navigation
[MRG] Fix paired Gaussian distances for unequal batch sizes - #909
Open
DiadkoShmek wants to merge 3 commits into
Open
DiadkoShmek wants to merge 3 commits into
DiadkoShmek wants to merge 3 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #909 +/- ##
=======================================
Coverage 97.09% 97.09%
=======================================
Files 130 130
Lines 27273 27300 +27
=======================================
+ Hits 26481 26508 +27
Misses 792 792 🚀 New features to boost your workflow:
|
clbonet
approved these changes
Nov 30, 2026
clbonet
left a comment
Collaborator
There was a problem hiding this comment.
Thank you for the fix, it seems good to me!
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Types of changes
Bug fix.
Motivation and context / Related issue
ot.gaussian.bures_wasserstein_distance(..., paired=True)documents paired distances when the two batches have the same size, and crossed distances otherwise. The mean term checks tensor ranks rather than batch sizes, while the covariance term checks batch sizes. With two source Gaussians and one target, these terms silently broadcast to a 2×2 result instead of the required 2×1 matrix. With batches of size two and three, the function raises a broadcasting error.Compare batch sizes for the mean term as well. The diagonal-Gaussian regression uses the independent closed form
W2² = ||ms-mt||² + ||stds-stdt||², including equal-batch and explicit-cross controls, both log modes, float32/64, and input immutability. A release note records the corrected behavior.This change was prepared with AI assistance.
How has this been tested (if it applies)
Exact source checkout at
0b6f8d506950be47f072a4cba439cd1836ba038d, full native installation including Cython/C++ extensions; CPU/NumPy only:python -m pytest test/test_gaussian.py -k unequal_batches -q: unmodified implementation with the same regression: 12 failed, 28 passed; patched: 40 passed.python -m pytest test/test_gaussian.py -q: 74 passed; one existing fixed-point barycenter nonconvergence warning.git diff --check: passed.The complete repository test suite and optional Torch/JAX/TensorFlow/CuPy backends were not run.
PR checklist
The existing API docstring already describes this fallback correctly. No documentation build was run. The test results and remaining backend coverage are listed above; the full repository-suite checkbox is intentionally unchecked.