Skip to content

Commit

Permalink
Improve performance of size(A) and drop pure on indices
Browse files Browse the repository at this point in the history
  • Loading branch information
timholy committed Aug 1, 2016
1 parent 000d5a6 commit 6001540
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ indices{T,N}(A::AbstractArray{T,N}, d) = d <= N ? indices(A)[d] : OneTo(1)
Returns the tuple of valid indices for array `A`.
"""
function indices(A)
@_inline_pure_meta
@_inline_meta
map(s->OneTo(s), size(A))
end

Expand Down
7 changes: 5 additions & 2 deletions base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ import Core: arraysize, arrayset, arrayref
size(a::Array, d) = arraysize(a, d)
size(a::Vector) = (arraysize(a,1),)
size(a::Matrix) = (arraysize(a,1), arraysize(a,2))
size(a::Array) = _size((), a)
size(a::Array) = (@_inline_meta; _size((), a))
_size{_,N}(out::NTuple{N}, A::Array{_,N}) = out
_size{_,M,N}(out::NTuple{M}, A::Array{_,N}) = _size((out..., size(A,M+1)), A)
function _size{_,M,N}(out::NTuple{M}, A::Array{_,N})
@_inline_meta
_size((out..., size(A,M+1)), A)
end

asize_from(a::Array, n) = n > ndims(a) ? () : (arraysize(a,n), asize_from(a, n+1)...)

Expand Down

0 comments on commit 6001540

Please sign in to comment.