Skip to content

Commit 2de99b5

Browse files
committed
Specialize pyarray_offset to be more amenable to constprop
This improves performance in tight loops.
1 parent 625f786 commit 2de99b5

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/Wrap/PyArray.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,10 @@ end
669669
x
670670
end
671671

672+
# Specialization for the common case where T == R, we can use the
673+
# constant-propagatable sizeof instead of looking up the stride.
674+
pyarray_offset(x::PyArray{T,N,M,true,T}, i::Int) where {T,N,M} =
675+
N == 0 ? 0 : (i - 1) * sizeof(T)
672676
pyarray_offset(x::PyArray{T,N,M,true}, i::Int) where {T,N,M} =
673677
N == 0 ? 0 : (i - 1) * x.strides[1]
674678
pyarray_offset(x::PyArray{T,1,M,true}, i::Int) where {T,M} = (i - 1) .* x.strides[1]

0 commit comments

Comments
 (0)