[Numpy-discussion] python numpy code many times slower than c++
Ravi
lists_ravi@lavabit....
Wed Jan 21 14:37:33 CST 2009
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
More information about the Numpy-discussion
mailing list