stefankoegl / kdtree

A Python implementation of a kd-tree
ISC License
365 stars 118 forks source link

Add persistency capability? #44

Closed Rhuax closed 6 years ago

Rhuax commented 6 years ago

I think it would be extremely useful adding methods to save and load the kdtree to file.

stefankoegl commented 6 years ago

I have not tested it, but you should be able to pickle/unpickle kdtrees. Have you tried this already, or do you have some more specific requirements?

Rhuax commented 6 years ago

There are problems with lambda functions. I found a workaround: get all indexed points, save them to file. Later, create a new kdtree using points read from the file. It's obviously a bad solution.

By the way, handling lambda functions should solve the problem.

https://stackoverflow.com/questions/25348532/can-python-pickle-lambda-functions

Rhuax commented 6 years ago

@stefankoegl Did you check it?

Rhuax commented 6 years ago

Problem solved using dill package, which can handle lambda functions. It would be still useful having a wrapper inside the kdtree class. I close the issue