Skip to content

Fix L1 distance to use Manhattan sum - #1998

Open
SahilKumar75 wants to merge 1 commit into
sbi-dev:mainfrom
SahilKumar75:fix/l1-manhattan-distance
Open

Fix L1 distance to use Manhattan sum#1998
SahilKumar75 wants to merge 1 commit into
sbi-dev:mainfrom
SahilKumar75:fix/l1-manhattan-distance

Conversation

@SahilKumar75

@SahilKumar75 SahilKumar75 commented Aug 23, 2026

Copy link
Copy Markdown

What does this PR do?

Changes l1() from the mean of absolute differences to their sum, implementing the standard Manhattan distance.

Updates the docstring and adds a regression test showing that a single differing coordinate contributes a distance of 1, including when additional identical coordinates are present.

Does this close any issues?

No linked issue.

Anything else we should know?

The existing docstring explicitly describes averaging. This change therefore alters existing behavior: for an axis of length n, the new distance is n times the previous distance. The intended convention and compatibility approach need discussion before merging.

Previously reported validation:

  • ruff check sbi/utils/metrics.py tests/metrics_test.py
  • ruff format --check sbi/utils/metrics.py tests/metrics_test.py
  • A direct L1/L2 regression check passed.
  • The full metrics test module could not be collected in the reported environment because pytest_harvest and nflows were unavailable.

No tests were rerun for this description update. The broader checks below remain unverified.

Checklist

  • I have read the contributing guide.
  • uv run pytest -n auto -m "not slow and not gpu" passes.
  • uv run pre-commit run --all-files passes (ruff and formatting).
  • uv run pyright sbi passes.
  • I added or updated tests for the changed behavior.
  • I used Google-style docstrings for new or changed public functions.
  • (If applicable) I reported how long new tests run and marked slow ones with pytest.mark.slow.

@coderabbitai

coderabbitai Bot commented Aug 23, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 9976e788-7f82-4c0f-8d80-b8b0200d6588

📥 Commits

Reviewing files that changed from the base of the PR and between 900821d and 69df3b4.

📒 Files selected for processing (2)
  • sbi/utils/metrics.py
  • tests/metrics_test.py

Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

The l1 metric now computes non-averaged Manhattan distance by summing absolute differences along the selected axis. Regression tests verify behavior when identical dimensions are added.

Changes

Metric distance behavior

Layer / File(s) Summary
Update L1 distance and regression coverage
sbi/utils/metrics.py, tests/metrics_test.py
l1 now sums absolute differences instead of averaging them. Tests verify the expected distance for one differing dimension and additional identical dimensions.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 69df3

This change corrects L1 distance to use the documented Manhattan sum and adds regression coverage. No actionable merge-blocking risk remains beyond normal checks and review.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring check was indeterminate for this PR — some files could not be analyzed in time. Not blocking.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely describes the primary change: updating L1 distance to use the Manhattan sum.
Description check ✅ Passed The description is complete and directly relevant. It explains the behavior change, test coverage, validation results, unavailable dependencies, compatibility concern, and checklist status.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@SahilKumar75

Copy link
Copy Markdown
Author

The focused regression change is ready for maintainer review. The test suite coverage and formatting checks are complete.

@BHARATH0153

Copy link
Copy Markdown
Contributor

sum fix looks right but it's a breaking change for existing l1 users — distances will scale with dim now. Consider adding a deprecation warning or changelog note

@janfb

janfb commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Hi @SahilKumar75 Thanks for the pull request! Please so our guidelines for the usual contribution process: https://sbi.readthedocs.io/en/latest/contributing.html

The usual workflow would be first creating an issue stating the problem and discussing a solution.

Can you please provide more details (as intended in our Pull Request Template): What's the problem here? what is this PR implementing and why?

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants