Skip to content

Commit

Permalink
Fix construction of varacset from FinDomFunctor (#919)
Browse files Browse the repository at this point in the history
* Correct constructor of acset from findomfunctor for varacset case

* Added test

* Fix parameter error in building acsets from certain findomfunctors

* Iteration of varset returns Attrvars

* ci being weird

* Remove spurious comment added to trigger CI

---------

Co-authored-by: Kevin Arlin <[email protected]>
Co-authored-by: Evan Patterson <[email protected]>
  • Loading branch information
3 people authored Jun 29, 2024
1 parent 0b4b218 commit 6282d26
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/categorical_algebra/CSets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,15 @@ functor_key(expr::GATExpr{:generator}) = first(expr)
function (::Type{ACS})(F::FinDomFunctor) where ACS <: ACSet
X = if ACS isa UnionAll
pres = presentation(dom(F))
ACS{(eltype(ob_map(F, c)) for c in generators(pres, :AttrType))...}()
ACS{(strip_attrvars(eltype(ob_map(F, c))) for c in generators(pres, :AttrType))...}()
else
ACS()
end
copy_parts!(X, F)
return X
end
strip_attrvars(T) = T
strip_attrvars(::Type{Union{AttrVar, T}}) where T = T

""" Copy parts from a set-valued `FinDomFunctor` to an `ACSet`.
"""
Expand Down
10 changes: 7 additions & 3 deletions src/categorical_algebra/FinSets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,13 @@ VarSet(i::Int) = VarSet{Union{}}(i)
SetOb(s::VarSet{Union{}}) = FinSet(s)
SetOb(s::VarSet{T}) where T = TypeSet{Union{AttrVar,T}}()
FinSet(s::VarSet) = FinSet(s.n) #Note this throws away `T`, most accurate when thinking about tight `VarFunction`s.
Base.iterate(set::VarSet{T}, args...) where T = iterate(1:set.n, args...)
"""
The iterable part of a varset is its collection of `AttrVar`s.
"""
Base.iterate(set::VarSet{T}, args...) where T = iterate(AttrVar.(1:set.n), args...)
Base.length(set::VarSet{T}) where T = set.n
Base.in(set::VarSet{T}, elem) where T = in(elem, 1:set.n)
Base.eltype(set::VarSet{T}) where T = Union{AttrVar,T}


abstract type AbsVarFunction{T} end # either VarFunction or LooseVarFunction
Expand Down Expand Up @@ -363,7 +367,7 @@ function is_monic(f::VarFunction)
vals = [v.val for v in collect(f.fun)]
return length(vals) == length(unique(vals))
end
is_epic(f::VarFunction) = AttrVar.(f.codom) collect(f)
is_epic(f::VarFunction) = AttrVar.(f.codom) collect(f) #XXX: tested?

compose(::IdentityFunction{TypeSet{T}}, f::AbsVarFunction{T}) where T = f
compose(f::VarFunction{T}, ::IdentityFunction{TypeSet{T}}) where T = f
Expand Down Expand Up @@ -1288,7 +1292,7 @@ end

# FIXME: Handle more specific diagrams? Now only VarSet colimits will be bipartite
function universal(lim::BipartiteColimit{<:VarSet{T}}, cocone::Multicospan) where {T}
VarFunction{T}(map(AttrVar.(collect(apex(lim)))) do p
VarFunction{T}(map(collect(apex(lim))) do p
for (l, csp) in zip(legs(lim), cocone)
pre = preimage(l, p) # find some colimit leg which maps onto this part
if !isempty(pre)
Expand Down
16 changes: 12 additions & 4 deletions test/categorical_algebra/CSets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -559,9 +559,17 @@ w1,w2,w3 = ws = [WG{x}() for x in [Symbol,Bool,Int]]
rem_part!(w1, :Weight, 1)
@test [nparts(w, :Weight) for w in ws] == [1,2,2]

A′ = WG{Bool}(FinDomFunctor(A))
rem_part!(A,:Weight,2)
@test is_isomorphic(A,A′)
A′ = WG(FinDomFunctor(A))
rem_part!(A,:Weight,2) #remove the dangling attrvar from A

C = FinCat(SchWeightedGraph)
obs = Dict(x=>x for x in ob_generators(C))
homs = Dict(f=> f for f in hom_generators(C))
F = FinDomFunctor(obs,homs,C,C)
A′′ = WG(compose(F,FinDomFunctor(A)))
#Test both A′ and A′′ for constructing an acset from
# an ACSetFunctor, respectively, a FinDomFunctorMap.
@test A == A′ == A′′

# Construct Tight/Loose ACSet Transformations
#--------------------------------------------
Expand Down Expand Up @@ -826,4 +834,4 @@ hs = [:it,:ot]
@test sum(h->is_cartesian(h,hs),homoms) == 12


end
end

0 comments on commit 6282d26

Please sign in to comment.