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

Neal Becker ndbecker2@gmail....
Wed Jan 21 13:57:59 CST 2009


Ravi wrote:

> On Wednesday 21 January 2009 10:22:36 Neal Becker wrote:
>> > [http://mail.python.org/pipermail/cplusplus-sig/2008-
October/013825.html
>>
>> Thanks for reminding me about this!
>>
>> Do you have a current version of the code?  I grabbed the files from the
>> above message, but I see some additional subsequent messages with more
>> patches.
> 
> That is the latest publicly posted code. Since then, there is just one
> minor patch (attached) which enables use of row-major (c-contiguous)
> arrays.
> 
> This does *not* work with strided arrays which would be a fair bit of
> effort to support. Further, you will have to work with the numpy iterator
> interface, which, while well-designed, is a great illustration of the
> effort required to support OO programming in an non-OO language, and is
> pretty tedious to map to the ublas storage iterator interface. If you do
> implement it, I would very much like to take a look at it.
> 
> Regards,
> Ravi

It seems your code works fine for my usual style:

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 &)

This gives:
ArgumentError: Python argument types in
    test1.double(numpy.ndarray)
did not match C++ signature:
    double(boost::numeric::ublas::vector<std::complex<double>, 
numpy::detail::numpy_storage_array<std::complex<double> > > {lvalue})


My instinct is to ignore it, because I think I don't need it, but do you 
have a workaround?





More information about the Numpy-discussion mailing list