Skip to content

Commit

Permalink
Fix isassigned
Browse files Browse the repository at this point in the history
  • Loading branch information
jishnub committed Mar 9, 2024
1 parent b4e9572 commit 9e27b85
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion base/reshapedarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@ offset_if_vec(i::Integer, axs::Tuple) = i

@inline function isassigned(A::ReshapedArrayLF, index::Int)
@boundscheck checkbounds(Bool, A, index) || return false
@inbounds ret = isassigned(parent(A), index)
indexparent = index - firstindex(A) + firstindex(parent(A))
@inbounds ret = isassigned(parent(A), indexparent)
ret
end
@inline function isassigned(A::ReshapedArray{T,N}, indices::Vararg{Int, N}) where {T,N}
Expand Down
8 changes: 5 additions & 3 deletions test/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2052,8 +2052,10 @@ end
end

@testset "reshape for offset arrays" begin
r = reshape(Base.IdentityUnitRange(0:1), (2,1))
@test r[eachindex(r)] == [0:1;]
p = Base.IdentityUnitRange(3:4)
r = reshape(p, :, 1)
@test r[eachindex(r)] == UnitRange(p)
@test collect(r) == r

struct ZeroBasedArray{T,N,A<:AbstractArray{T,N}} <: AbstractArray{T,N}
a :: A
Expand All @@ -2069,7 +2071,7 @@ end
Base.setindex!(z::ZeroBasedArray{<:Any, N}, val, i::Vararg{Int,N}) where {N} = parent(z)[map(x -> x + 1, i)...] = val

z = ZeroBasedArray(collect(1:4))
r2 = reshape(z, (4, 1))
r2 = reshape(z, :, 1)
@test r2[CartesianIndices(r2)] == r2[LinearIndices(r2)]
r2[firstindex(r2)] = 34
@test z[0] == 34
Expand Down

0 comments on commit 9e27b85

Please sign in to comment.