[mlpack] Python binding

Ryan Curtin ryan at ratml.org
Thu Jan 28 15:57:04 EST 2016


On Thu, Jan 28, 2016 at 11:59:21AM -0700, Ming Tu wrote:
> Hi everyone,
> 
> I'm working on a project using Theano (a Python library) which needs a
> faster MST implementation. I found mlpack. But, after reading the posts on
> python binding it seems to be a hard work. Do you have any suggestions if I
> only want to compile DualTreeBoruvka MST into python library?

Hi Ming,

Unfortunately at the moment there hasn't been any progress on Python
bindings.  I have written some experimental Python bindings before
though, and it should not be too hard to get what you need.

What you'll need to do is write a Cython binding that has a cdef that
defines the DualTreeBoruvka class and the functions that you need
(probably just ComputeMST() and the constructor).  You'll also need
bindings for the Armadillo types, but someone has already written some
Cython bindings for Armadillo:

https://github.com/andrewcron/cy_armadillo

Then you can convert your data from numpy arrays to Armadillo objects
without copying the memory, and from there you can call the Cython
binding for the DualTreeBoruvka class.

It'll take more than a couple minutes to get all that set up and put
together, but if you want a Python binding that's you're best bet.
Another idea might be to use subprocess() to call the 'mlpack_emst'
program and then use numpy.genfromtxt() or something to load in the
results.  But then you'll have some extra overhead.  I don't know if
that matters in your situation.

Hope this is helpful. :)

Ryan

-- 
Ryan Curtin    | "He's a peculiar man.  You could even say that he
ryan at ratml.org | has principles."  - Carson Wells


More information about the mlpack mailing list