MOE icon indicating copy to clipboard operation
MOE copied to clipboard

[C++] [Python] Pass data through C++/Python interface in numpy arrays, not python lists

Open suntzu86 opened this issue 10 years ago • 0 comments

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:

  1. flatten numpy array (python)
  2. copy it into a list (python)
  3. copy it out of list into a std::vector (C++)

And getting data out:

  1. copy (flat) from std vector to python list (C++)
  2. copy from list to numpy array (python)
  3. 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/

suntzu86 avatar Jun 05 '14 04:06 suntzu86