Skip to content

Commit

Permalink
make parentindices consistent with Base (#250)
Browse files Browse the repository at this point in the history
* make parentindices consistent with Base

* remove allequal
  • Loading branch information
aplavin authored Oct 14, 2022
1 parent efda46e commit 0933432
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/structarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,12 @@ end
StructArray{T}(map(v -> @inbounds(view(v, I...)), components(s)))
end

function Base.parentindices(s::StructArray)
res = parentindices(component(s, 1))
all(c -> parentindices(c) == res, components(s)) || throw(ArgumentError("inconsistent parentindices of components"))
return res
end

Base.@propagate_inbounds function Base.setindex!(s::StructArray{T, <:Any, <:Any, CartesianIndex{N}}, vals, I::Vararg{Int, N}) where {T,N}
@boundscheck checkbounds(s, I...)
valsT = maybe_convert_elt(T, vals)
Expand Down
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ Base.convert(::Type{Millimeters}, x::Meters) = Millimeters(x.x*1000)
@test (@inferred t[2,1:2]) == StructArray((a = [3, 4], b = [6, 7]))
@test_throws BoundsError t[3,3]
@test (@inferred view(t, 2, 1:2)) == StructArray((a = view(a, 2, 1:2), b = view(b, 2, 1:2)))
@test @inferred(parentindices(view(t, 2, 1:2))) == (2, 1:2)
@test_throws ArgumentError parentindices(StructArray((view([1, 2], [1]), view([1, 2], [2]))))

# Element type conversion (issue #216)
x = StructArray{Complex{Int}}((a, b))
Expand Down

0 comments on commit 0933432

Please sign in to comment.