Skip to content

Commit

Permalink
Specialize _memory_offset on number of arguments. (#37444)
Browse files Browse the repository at this point in the history
  • Loading branch information
chriselrod authored Sep 8, 2020
1 parent a36c825 commit 1e6d771
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1070,8 +1070,8 @@ function pointer(x::AbstractArray{T}, i::Integer) where T
end

# The distance from pointer(x) to the element at x[I...] in bytes
_memory_offset(x::DenseArray, I...) = (_to_linear_index(x, I...) - first(LinearIndices(x)))*elsize(x)
function _memory_offset(x::AbstractArray, I...)
_memory_offset(x::DenseArray, I::Vararg{Any,N}) where {N} = (_to_linear_index(x, I...) - first(LinearIndices(x)))*elsize(x)
function _memory_offset(x::AbstractArray, I::Vararg{Any,N}) where {N}
J = _to_subscript_indices(x, I...)
return sum(map((i, s, o)->s*(i-o), J, strides(x), Tuple(first(CartesianIndices(x)))))*elsize(x)
end
Expand Down

0 comments on commit 1e6d771

Please sign in to comment.