kiddo icon indicating copy to clipboard operation
kiddo copied to clipboard

distance_fn with bigger return type?

Open wentasah opened this issue 2 years ago • 2 comments

I have a KdTree<FixedI32<U0>, usize, 2, 32, u32>. When I want to use squared_euclidean as distance_fn, I get an overflow. Would it be possible to support FixedI64 as distance_fn return type?

Currently, I work around it by using KdTree<FixedI64<U0>,...>, which seems wasteful.

wentasah avatar May 10 '23 06:05 wentasah

Hi Michael. That's a good point. When I used FixedU16 I was having to sacrifice some precision in order to ensure that the distance would not overflow, which is not ideal.

Getting this working generically will be interesting - I'll have a think about how it could be done. Any suggestions or PRs appreciated, if you have some ideas.

sdd avatar May 10 '23 09:05 sdd

Hi Scott,

Again with the RGB color information. Since RGB values can be stored in a U8F0, I tried using that as coordinate type, but distances are frequently higher than 255 even with the Manhattan distance function, which forces me to use a U16F0 because of this issue. I would say, to fix this, maybe just always set the distance type to a FixedU64 with the given bits of precision? Or calculate the maximum distance for the given coordinate type and distance function, and pick the smallest FixedUx that will fit; not sure if that's worth it though.

NeuralModder avatar Jun 02 '24 11:06 NeuralModder