diff --git a/src/DenseACSets.jl b/src/DenseACSets.jl index cdeef36..5e7cc15 100644 --- a/src/DenseACSets.jl +++ b/src/DenseACSets.jl @@ -575,12 +575,14 @@ ACSetInterface.rem_part!(acs::DynamicACSet, type::Symbol, part::Int) = end @ct_ctrl for f in [out_homs; out_attrs] - if haskey(acs.subparts[@ct f], last_part) - set_subpart!(acs, part, (@ct f), subpart(acs, last_part, @ct f)) - end - clear_subpart!(acs, last_part, @ct f) + if haskey(acs.subparts[@ct f], last_part) && part != last_part + last_part_f = subpart(acs, last_part, @ct f) + clear_subpart!(acs, last_part, @ct f) + set_subpart!(acs, part, (@ct f), last_part_f) + else + clear_subpart!(acs, last_part, @ct f) + end end - acs.parts[@ct ob].val -= 1 end diff --git a/test/ACSets.jl b/test/ACSets.jl index 1482e9a..9e0d581 100644 --- a/test/ACSets.jl +++ b/test/ACSets.jl @@ -575,4 +575,85 @@ g′′ = sparsify(g′) @test g′[:src] == [1,2] @test g′′[:src] == [1,2] +# Recursive deletion with indexing +#--------------------------------- + +RecSch = BasicSchema( + [:Thing,:Node,:Edge], [(:src,:Edge,:Node),(:tgt,:Edge,:Node),(:thing,:Thing,:Node)], + [],[] +) + +@acset_type RecDataInj(RecSch, index=[:src,:tgt], unique_index=[:thing]) +@acset_type RecDataIdx(RecSch, index=[:src,:tgt,:thing]) +@acset_type RecDataNoIdx(RecSch) + +datainj = @acset RecDataInj begin + Thing=3 + Node=3 + Edge=3 + thing=[1,2,3] + src=[1,1,2] + tgt=[1,2,3] end + +dataidx = @acset RecDataIdx begin + Thing=3 + Node=3 + Edge=3 + thing=[1,2,3] + src=[1,1,2] + tgt=[1,2,3] +end + +datanoidx = @acset RecDataNoIdx begin + Thing=3 + Node=3 + Edge=3 + thing=[1,2,3] + src=[1,1,2] + tgt=[1,2,3] +end + +map_inj = cascading_rem_parts!(datainj, :Node, 1) +map_idx = cascading_rem_parts!(dataidx, :Node, 1) +map_noidx = cascading_rem_parts!(datanoidx, :Node, 1) + +@test map_inj == map_idx +@test map_idx == map_noidx + +@test nparts(datainj,:Thing) == 2 +@test nparts(datainj,:Node) == 2 +@test nparts(datainj,:Edge) == 1 +@test incident(datainj, 3, :thing) == [] +@test incident(datainj, 3, :src) == [] +@test incident(datainj, 3, :tgt) == [] + +# attributes and an injective index +RecAttrSch = BasicSchema( + [:Thing,:Node,:Edge], [(:src,:Edge,:Node),(:tgt,:Edge,:Node),(:thing,:Thing,:Node)], + [:Attr1,:Attr2,:Attr3],[(:attr1,:Node,:Attr1),(:attr2,:Edge,:Attr2),(:attr3,:Thing,:Attr3)] +) + +@acset_type RecAttrData(RecAttrSch, index=[:src,:tgt], unique_index=[:thing]) + +dataattr = @acset RecAttrData{String,Symbol,Float64} begin + Thing=3 + Node=3 + Edge=3 + thing=[1,2,3] + src=[1,1,2] + tgt=[1,2,3] + attr1=["1","2","3"] + attr2=[:a,:b,:c] + attr3=[10.0,11.0,12.0] +end + +map_attr = cascading_rem_parts!(dataattr, :Node, 1) + +@test map_inj == map_attr + +@test all(map(x -> x ∈ subpart(dataattr,:attr1), ["2","3"])) +@test only(subpart(dataattr,:attr2)) == :c +@test all(map(x -> x ∈ subpart(dataattr,:attr3), [12.0,11.0])) + +end \ No newline at end of file