feat: Add Chebyshev distance (L_∞ norm) support#290
Conversation
|
Hi again Carlson! Just seen this, I will check them out over the next day or two. Thanks! |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## v5.x.x #290 +/- ##
==========================================
+ Coverage 94.89% 95.04% +0.14%
==========================================
Files 54 54
Lines 5685 6252 +567
Branches 5685 6252 +567
==========================================
+ Hits 5395 5942 +547
- Misses 273 286 +13
- Partials 17 24 +7 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Sounds good, thanks :) |
|
Thanks. As it is, the commit lint step fails because some of your commit message subjects are not confirming to Conventional Commits standard. You can either fix them individually with interactive rebase, or squash them into one commit with a catch-all subject like |
Yes, I will do that asap for all three PRs. |
7adffe8 to
80c8d89
Compare
|
Hello @sdd, I have changed the commit messages to conform with the conventional commits standard, rebasing this PR, #293 and #294. If there is any more feedback, let me know. Otherwise, I'd be happy to these features in a coming release, so I can use this as a dependency going beta with |
|
Thanks for running the CI. |
sdd
left a comment
There was a problem hiding this comment.
Thanks for getting this into shape Carlson, it's a very welcome addition and very thoroughly tested 😄
I just need to work out why the CI didn't seem to run on this. Once we've worked out why and got it to run on this again, I'm happy to merge and we'll get it released.
src/fixed/distance.rs
Outdated
| #[case([ZERO, ZERO], [ZERO, ZERO], ZERO)] | ||
| #[case([ZERO, ZERO], [ONE, ZERO], ONE)] | ||
| #[case([ZERO, ZERO], [ZERO, ONE], ONE)] | ||
| #[case([ZERO, ZERO], [ONE, ONE], FxdU16::lit("2"))] |
There was a problem hiding this comment.
We could use TWO here instead of FxdU16::lit("2") but I'm not going to block merging for such a trivial change :-)
There was a problem hiding this comment.
Good catch, maybe I missed one click in find+replace there.
…lidean distance metrics
- deprecate `rd_update` with `D::accumulate` for consistent sum-based and max-based metrics - conditional logic for SIMD (L1/L2) and general L∞ - differentiate distance accumulation behaviour
- integration `nearest_n` tests (Chebyshev, Manhattan, SquaredEuclidean).
- improve `DistanceMetric` doc - add Gaussian scenario to tests
… trait - improve test coverage
7479563 to
f33b6e9
Compare
- `A::dist` - `saturating_mul`
6605b39 to
c4e8db9
Compare
|
While I was not able to reproduce the overflow, it happend with
For both I did not know before these exist for
That's great to hear, thanks! |
|
Hi Carlson - I've merged this in now. Looking at your other PR now (#291), there's a small merge conflict now that this one has been merged, as well as a failure on the formatting check. If you can get that one back into shape, I'll merge that one in as well so we can get both into a 5.3.0 release. Thanks! |
|
Thanks for the review and merge! 👏 |
This is a PR #286, reopened for the fitting branch. I rebased my suggested changes, dropping all other commits. Locally all test still pass. I have added a few cases to increase code coverage. Find the PR description over at #286. I will just add onto. it here.
For the default implementation of
accumulateI understood best to usenum_traits::SaturatingAdd, but this trait is only implemented for integer types, not for floating-point types (f32, f64). So now I changed it to usestd::ops::Addas the bound, which works for both integers and floats. This means the defaultrd + deltaworks correctly for floating-point types (produces inf on overflow), but fixed-point types need to override accumulate with rd.saturating_add(delta) to prevent overflow. I ignorantly assume that this covers a larger userbase and think this solution is the best we can do without specialization (is currently unstable https://std-dev-guide.rust-lang.org/policy/specialization.html / rust-lang/rust#31844). To my understanding this is still a breaking change for users with fixed-point types who implement customDistanceMetrics. The only feasible alternative I see would be with a macro to generate implementations that can differentiate the two. Please correct me if I got this wrong.Secondly, I want to clarify a statement from my previous #286 (comment).
I was only not able to find a relevant test where the
<=removed in c934656 did (dist_belongs_in_heap) make a difference, so I changed them to<. But still, there are other occurences that are still included and that did make a difference in the test with gaussian data. So if you think there are some cases where having the<=fordist_belongs_in_heap, these can be re-added. Right now there are many parametrizes test cases withnearest_n, but not forwithin.If there are suggestions for changes, don't heasitate to say so.
Closes #286