MOE
MOE copied to clipboard
[C++] [Python] Pass data through C++/Python interface in numpy arrays, not python lists
Right now, the Python optimal_learning library uses only numpy arrays internally. But the interface to the C++ library only accepts python lists. The usual process to transfer data in is:
- flatten numpy array (python)
- copy it into a list (python)
- copy it out of list into a std::vector (C++)
And getting data out:
- copy (flat) from std vector to python list (C++)
- copy from list to numpy array (python)
- reshape appropriately (python)
That's a lot of extra awkward steps! It introduces a bunch of 'translation' functions that just perform the input steps, call a C++ function, and perform the output steps.
It'd be nice if the steps could be simpler--if we could send numpy arrays from which we can get pointers to double OR even better directly pass in a type usable by the C++ interface (e.g., install a translator in boost for numpy array <-> std vector, see below), eliminating the need for so many purely translation functions. Woo simplicity!
boost converters: http://misspent.wordpress.com/2009/09/27/how-to-write-boost-python-converters/