Skip to content

Commit

Permalink
Fix trimming of SubArrays in unaliascopy (JuliaLang#26263)
Browse files Browse the repository at this point in the history
This fixes a bug in SubArray's unaliascopy "trimming" within unaliascopy
  • Loading branch information
mbauman authored Mar 1, 2018
1 parent be4e39f commit 9fd962b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion base/subarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function unaliascopy(V::SubArray{T,N,A,I,LD}) where {T,N,A<:Array,I<:Tuple{Varar
end
# Transform indices to be "dense"
_trimmedindex(i::Real) = oftype(i, 1)
_trimmedindex(i::AbstractUnitRange) = i
_trimmedindex(i::AbstractUnitRange) = oftype(i, OneTo(length(i)))
_trimmedindex(i::AbstractArray) = oftype(i, reshape(linearindices(i), axes(i)))

## SubArray creation
Expand Down
7 changes: 6 additions & 1 deletion test/subarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -588,9 +588,14 @@ end
@test sizeof(view(zeros(UInt8, 10), 1:3)) == 3
@test sizeof(view(zeros(Float64, 10, 10), 1:3, 2:6)) == 120


# PR #25321
# checks that issue in type inference is resolved
A = rand(5,5,5,5)
V = view(A, 1:1 ,:, 1:3, :)
@test @inferred(strides(V)) == (1, 5, 25, 125)

# Issue #26263 — ensure that unaliascopy properly trims the array
A = rand(5,5,5,5)
V = view(A, 2:5, :, 2:5, 1:2:5)
@test @inferred(Base.unaliascopy(V)) == V == A[2:5, :, 2:5, 1:2:5]
@test @inferred(sum(Base.unaliascopy(V))) == sum(V) == sum(A[2:5, :, 2:5, 1:2:5])

0 comments on commit 9fd962b

Please sign in to comment.