Closed nicky-zs closed 11 years ago
Methods like remove()
are currently implemented in a recursive way. For very large trees (and also depending on other circumstances), your stack might not be able to hold the contents of the recursive calls.
The proper solution would be to refactor those methods from recursive to iterative, however this is not planned at the moment. In the meantime, you can use sys.setrecursionlimit()
to increase the recursion limit.
Er... In the code above, only 8000 points are inserted into the tree. In my opinion, trees of 8000 node cannot be called large trees, because if a tree of 8000 node is balanced more or less, the height of the tree may be just 20 to 30, which is quite small. Furthermore, the limit of resursion in my system is 10,000. I did set that. So, even the tree is extremely imbalanced, my system can easily finished the recursion of depth 8000. Thus, I think the problem is, in fact, caused by some incorrect logic in the code, such as an infinite loop, not to filter the same points, or something else, not really the recursion depth.
import random, functools, kdtree r = functools.partial(random.randint, 1, 100) points = [(r(), r()) for x in xrange(8000)] tree = kdtree.create(points) tree = tree.remove((3,4))