Repository navigation
Fix Grid.to_LRCGeometry for grids with 2 points along a dimension - #711
Open
raashish1601 wants to merge 1 commit into
Open
raashish1601 wants to merge 1 commit into
raashish1601 wants to merge 1 commit into
Conversation
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.
Fixes #669.
Grid.to_LRCGeometry()converts the point cloud of each grid dimension withgeom.to_LRCGeometry(rank=0, ...)and then readscost_1/cost_2. For a squared Euclidean (or negative dot product) point cloud,PointCloud.to_LRCGeometry()returns the point cloud itself when the factors would not be smaller than the cost matrix (n * m <= (n + m) * d). With 2 points on a dimension that is always the case (4 <= 4), so any grid with a dimension of size 2 fails withAttributeError: 'PointCloud' object has no attribute 'cost_1'.SinkhornOutput.primal_costhits this throughtransport_cost_at_geom(), sinceGrid.can_LRCisTrue.When the slice conversion does not return an
LRCGeometry, the grid now factorizes that slice with the exact SVD fromGeometry.to_LRCGeometry(rank=0), which is what the comment above the loop already asks for.Tests:
test_conversion_gridintests/geometry/lr_cost_test.pyis parametrized with grids that have size-2 dimensions ([2],[2, 3],[3, 2, 2]) in addition to the existing[6, 7, 11].test_primal_cost_grid_with_two_pointsintests/solvers/linear/sinkhorn_grid_test.pycomparesprimal_coston grids of size(2,),(2, 2)and(2, 3)with the same problem on aPointCloud.Both fail on
mainand pass with the change.tests/solvers/linear/sinkhorn_grid_test.pyand the grid conversion tests pass locally (CPU), and ruff, isort and yapf at the pre-commit versions report no changes.