Skip to content

Vectorise indexing of contiguous PyArrays - #835

Open
Beforerr wants to merge 1 commit into
JuliaPy:mainfrom
Beforerr:pyarray-unit-stride
Open

Beforerr wants to merge 1 commit into
JuliaPy:mainfrom
Beforerr:pyarray-unit-stride

Conversation

@Beforerr

@Beforerr Beforerr commented Oct 6, 2026

Copy link
Copy Markdown

#715 was closed because the type parameters can't say an array is contiguous. A runtime check turns out to be enough: branching on strides[1] == sizeof(R) lets LLVM version the loop and vectorise the contiguous case.

Float32, Julia 1.13.1, Apple M1, ms:

before after Array
sum, 1e7 vector 4.43 0.45 0.45
sum, 4-D F-order (4e7) 17.8 2.02 2.02
sum, v[::2] 4.43 4.6

Strided and C-order arrays are unchanged within noise.

Broadcasting into an Array (x .* 2) is still ~3x slower than with an Array input. That one is on the Julia side: LLVM won't emit a runtime alias check between the Array store and the Ptr load.

The new test uses _testbuffer, so it doesn't need numpy.

Branch on strides[1] == sizeof(R) so LLVM can version loops on the
contiguous case. No change to the type parameters.
@Beforerr
Beforerr force-pushed the pyarray-unit-stride branch from 3b26ab2 to f700cb4 Compare October 17, 2026 04:36

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant