[Numpy-discussion] python numpy code many times slower than c++
Neal Becker
ndbecker2@gmail....
Wed Jan 21 12:55:49 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
I'm only interested in simple strided 1-d vectors. In that case, I think
your code already works. If you have c++ code using the iterator interface,
the iterators dereference will use (*array )[index]. This will use
operator[], which will call PyArray_GETPTR. So I think this will obey
strides.
Unfortunately, it will also be slow. I suggest something like the enclosed.
I have done some simple tests, and it seems to work.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: numpy.hpp
Type: text/x-c++hdr
Size: 9909 bytes
Desc: not available
Url : http://projects.scipy.org/pipermail/numpy-discussion/attachments/20090121/8aa09eac/attachment-0002.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test1.cc
Type: text/x-c++src
Size: 1359 bytes
Desc: not available
Url : http://projects.scipy.org/pipermail/numpy-discussion/attachments/20090121/8aa09eac/attachment-0003.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: testsum.py
Type: text/x-python
Size: 246 bytes
Desc: not available
Url : http://projects.scipy.org/pipermail/numpy-discussion/attachments/20090121/8aa09eac/attachment-0001.py
More information about the Numpy-discussion
mailing list