Skip to content

Commit 222334a

Browse files
committed
Fix keys for PartialArray
1 parent 633e920 commit 222334a

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

src/varnamedtuple.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,7 @@ function Base.keys(pa::PartialArray)
652652
inds = findall(pa.mask)
653653
lenses = map(x -> IndexLens(Tuple(x)), inds)
654654
ks = Any[]
655+
alb_inds_seen = Set{Tuple}()
655656
for lens in lenses
656657
val = getindex(pa.data, lens.indices...)
657658
if val isa VarNamedTuple
@@ -661,7 +662,10 @@ function Base.keys(pa::PartialArray)
661662
push!(ks, _compose_no_identity(sublens, lens))
662663
end
663664
elseif val isa ArrayLikeBlock
664-
push!(ks, IndexLens(Tuple(val.inds)))
665+
if !(val.inds in alb_inds_seen)
666+
push!(ks, IndexLens(Tuple(val.inds)))
667+
push!(alb_inds_seen, val.inds)
668+
end
665669
else
666670
push!(ks, lens)
667671
end

test/varnamedtuple.jl

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ function test_invariants(vnt::VarNamedTuple)
4040
@test merge(VarNamedTuple(), vnt) == vnt
4141
end
4242

43+
""" A type that has a size but is not an Array. Used in ArrayLikeBlock tests."""
44+
struct SizedThing{T<:Tuple}
45+
size::T
46+
end
47+
Base.size(st::SizedThing) = st.size
48+
4349
@testset "VarNamedTuple" begin
4450
@testset "Construction" begin
4551
vnt1 = VarNamedTuple()
@@ -417,6 +423,22 @@ end
417423
@varname(j[6]),
418424
@varname(n[2].a),
419425
]
426+
427+
vnt = setindex!!(vnt, SizedThing((3, 1, 4)), @varname(o[2:4, 5:5, 11:14]))
428+
@test keys(vnt) == [
429+
@varname(a),
430+
@varname(b),
431+
@varname(c.x.y),
432+
@varname(d[4]),
433+
@varname(e.f[3, 3].g.h[2, 4, 1].i),
434+
@varname(j[1]),
435+
@varname(j[2]),
436+
@varname(j[3]),
437+
@varname(j[4]),
438+
@varname(j[6]),
439+
@varname(n[2].a),
440+
@varname(o[2:4, 5:5, 11:14]),
441+
]
420442
end
421443

422444
@testset "printing" begin
@@ -466,12 +488,6 @@ end
466488
end
467489

468490
@testset "block variables" begin
469-
""" A type that has a size but is not an Array."""
470-
struct SizedThing
471-
size::Tuple
472-
end
473-
Base.size(st::SizedThing) = st.size
474-
475491
# Tests for setting and getting block variables, i.e. variables that have a non-zero
476492
# size in a PartialArray, but are not Arrays themselves.
477493
expected_err = ArgumentError("""

0 commit comments

Comments
 (0)