[Numpy-discussion] python numpy code many times slower than c++
Neal Becker
ndbecker2@gmail....
Wed Jan 21 14:53:37 CST 2009
Ravi wrote:
> On Wednesday 21 January 2009 13:55:49 Neal Becker wrote:
>> 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.
>
> You are right. I had forgotten that I had simple strided vectors working.
>
>> Unfortunately, it will also be slow. I suggest something like the
>> enclosed. I have done some simple tests, and it seems to work.
>
> I wonder why PyArray_GETPTR1 is slow. Is it because of the implied integer
> multiplication? Unfortunately, your approach means that iterators can
> become invalid if the underlying array is resized to a larger size. Hmmh,
> perhaps we could make this configurable at compile-time ...
>
> Thanks for the code. Could you provide some benchmarks on the relative
> speeds of the two approaches?
>
> Regards,
> Ravi
Do you know about pyublas? This is the same issue we ran into there. I did
not benchmark the code you sent me. I was just going by my experience with
pyublas. I guess a benchmark would be a good idea.
More information about the Numpy-discussion
mailing list