getindex(S::SubArray{T,2}, i::Integer) allocates memory when it probably shouldn't #3790

Closed
timholy opened this Issue Jul 22, 2013 · 0 comments

Comments

Projects
None yet
1 participant
Owner

timholy commented Jul 22, 2013

julia> A = reshape(1:3004*3002, 3004, 3002);

julia> sA = sub(A, 1:3003, 1:3002);

julia> @time sum(A)
elapsed time: 0.022972412 seconds (121728 bytes allocated)
40662238653036

julia> @time sum(A)
elapsed time: 0.027780444 seconds (64 bytes allocated)
40662238653036

julia> @time sum(sA)
elapsed time: 0.599137738 seconds (144450680 bytes allocated)
40648698114024

julia> @time sum(sA)
elapsed time: 0.58232922 seconds (144232032 bytes allocated)
40648698114024

The specialized implementation at subarray.jl: 176 would seem to suggest that it's not necessary.

@timholy timholy closed this in caabd83 Jul 23, 2013

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