kiddo icon indicating copy to clipboard operation
kiddo copied to clipboard

Too many items with the same position on one axis

Open vchugreev opened this issue 1 year ago • 15 comments

Hello, Scott.

I am using kiddo version="2.1.1", while running I get the error:

panicked at 'Too many items with the same position on one axis. Bucket size must be increased to at least 1 more than the number of items with the same position on one axis.': /home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/kiddo-2.1.1/src/float/construction.rs:223

I create KdTree like this

use kiddo::KdTree;
let patterns: KdTree<f32, 3> = KdTree::with_capacity(15000);

Before there was a panic, about 2500-3000 points of this kind were added:

[0.375, 0.02111614, 0.6641945]
[0.4, 0.03517097, 0.7697125]
[0.8333333, 0.29152542, 0.79504514]
[0.39285713, 0.31456685, 0.68769246]
[0.4027778, 0.7054616, 0.17576419]
[0.4, 0.61720204, 0.12553063]
[0.7916667, 0.768097, 0.0121426955]
[0.6458333, 0.84298575, 0.010071943]
[0.35416666, 0.84498125, 0.009049486]
[0.3611111, 0.0, 0.032477904]
[0.75, 0.0, 0.0]
[0.6, 0.018008512, 0.15822956]
[0.20833333, 0.020134605, 0.19604518]
[0.6111111, 0.02478464, 0.21736293]
[0.22222222, 0.028708035, 0.21946773]
[0.6354167, 0.028441446, 0.26566488]
[0.32142857, 0.033044748, 0.24640274]
[0.6770833, 0.05056776, 0.2594764]
[0.35, 0.032584045, 0.23101737]
[0.37121212, 0.034161422, 0.10082746]
[0.70238096, 0.03304547, 0.10467288]
[0.34375, 0.01344555, 0.8041778]
[0.8333333, 0.004752005, 0.0]
[0.375, 0.28213167, 0.60720414]
[0.3888889, 0.0, 0.21019818]
[0.4, 0.0, 0.0]
[0.875, 0.13517289, 0.0]
[0.39583334, 0.14556533, 0.15978695]
[0.8055556, 0.12474227, 0.17170732]
[0.3690476, 0.080061756, 0.52134496]
[0.3690476, 0.117475726, 0.6248968]
...

What capacity should I choose if I expect to add no more than 15000 points? How to calculation it correctly? Why can't you dynamically expand to the right size?

It's a bit discouraging, it's not at all obvious behavior. At first I use KdTree::new() but very quickly got the a similar error, switching to creation via with_capacity also does not completely solve the problem.

In any case, thanks for your library, I use it in my home project to predict the trade price.

Sincerely, Valery

vchugreev avatar Jul 14 '23 11:07 vchugreev