scikit-learn/scikit-learn — pull request #1086 by larsmans (2012-08-30 16:14:19+00:00)
Title: WIP: cleanup of the Cython code for sklearn.tree

I noticed that the `sklearn.tree._tree` code uses a lot of unchecked `malloc` calls, which IMHO is a recipe for disaster. Instead of adding checks everywhere, I decided to try and replace them all (well, except for one...) with NumPy memory allocation, i.e. `np.empty`. As far as I can tell, this is not significantly slower than using `malloc` directly.

Before I proceed to replace the `value` member as well, whose allocation rules I currently don't understand, I would like some feedback (@pprett?); I only ran the benchmark to check the speed.

The unit tests currently crash because I broke the pickling code, but if you disable the pickling test, the rest passes.

If this works well, it might be a good idea to always use NumPy memory allocation in Cython code in the future, so we get proper exceptions, garbage collection and less chance of memory leaks.