Skip to content

Commit 0933432

Browse files
authored
make parentindices consistent with Base (#250)
* make parentindices consistent with Base * remove allequal
1 parent efda46e commit 0933432

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/structarray.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,12 @@ end
368368
StructArray{T}(map(v -> @inbounds(view(v, I...)), components(s)))
369369
end
370370

371+
function Base.parentindices(s::StructArray)
372+
res = parentindices(component(s, 1))
373+
all(c -> parentindices(c) == res, components(s)) || throw(ArgumentError("inconsistent parentindices of components"))
374+
return res
375+
end
376+
371377
Base.@propagate_inbounds function Base.setindex!(s::StructArray{T, <:Any, <:Any, CartesianIndex{N}}, vals, I::Vararg{Int, N}) where {T,N}
372378
@boundscheck checkbounds(s, I...)
373379
valsT = maybe_convert_elt(T, vals)

test/runtests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ Base.convert(::Type{Millimeters}, x::Meters) = Millimeters(x.x*1000)
3737
@test (@inferred t[2,1:2]) == StructArray((a = [3, 4], b = [6, 7]))
3838
@test_throws BoundsError t[3,3]
3939
@test (@inferred view(t, 2, 1:2)) == StructArray((a = view(a, 2, 1:2), b = view(b, 2, 1:2)))
40+
@test @inferred(parentindices(view(t, 2, 1:2))) == (2, 1:2)
41+
@test_throws ArgumentError parentindices(StructArray((view([1, 2], [1]), view([1, 2], [2]))))
4042

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

0 commit comments

Comments
 (0)