Skip to content

Commit

Permalink
Merge pull request #61 from slwu89/_rem_parts-injective
Browse files Browse the repository at this point in the history
fix `_rem_part!` to work with injective cache
  • Loading branch information
epatters authored Sep 30, 2023
2 parents 1655674 + bac94a0 commit c32cd26
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/DenseACSets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
81 changes: 81 additions & 0 deletions test/ACSets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit c32cd26

Please sign in to comment.