[Numpy-discussion] python numpy code many times slower than c++

Ravi lists_ravi@lavabit....
Wed Jan 21 15:04:47 CST 2009

On Wednesday 21 January 2009 14:57:59 Neal Becker wrote:
> ublas::vector<T> func (numpy::array_from_py<T>::type const&)
> But not for a function that modifies it arg in-place (& instead of const&):
> void func (numpy::array_from_py<T>::type &)
Use void func (numpy::array_from_py<T>::type )

Why does this work? It is a tradeoff I had to make; I chose to use python 
conventions rather than C++ conventions. Essentially, what is passed back to 
you is a reference to the numpy array. Any copies you make of it are actually 
copies of the reference, not of the actual array. This simplifies the code 
quite a bit while maintaining the reference semantics that python programmers 

See dump_vec in decco.cc (the example module) for an example. 


More information about the Numpy-discussion mailing list