Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix _rem_part! to work with injective cache #61

Merged
merged 9 commits into from
Sep 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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