From 940ea04712f339da7388284b267ee3957778c467 Mon Sep 17 00:00:00 2001 From: Kris Brown Date: Wed, 17 Jul 2024 11:08:30 -0700 Subject: [PATCH] more verbose names + comments --- src/categorical_algebra/CSets.jl | 6 +++--- src/categorical_algebra/HomSearch.jl | 9 +++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/categorical_algebra/CSets.jl b/src/categorical_algebra/CSets.jl index 7eac16548..d26894a90 100644 --- a/src/categorical_algebra/CSets.jl +++ b/src/categorical_algebra/CSets.jl @@ -451,6 +451,7 @@ function coerce_components(S, components, X::ACSet{<:PT}, Y) where PT return merge(ocomps, acomps) end +# Enforces that function has a valid domain (but not necessarily codomain) function coerce_component(ob::Symbol, f::FinFunction{Int,Int}, dom_size::Int, codom_size::Int; kw...) if haskey(kw, :dom_parts) @@ -458,7 +459,6 @@ function coerce_component(ob::Symbol, f::FinFunction{Int,Int}, else length(dom(f)) == dom_size # check domain of dense parts end || error("Domain error in component $ob") - # length(codom(f)) == codom_size || error("Codomain error in component $ob") return f end @@ -476,8 +476,8 @@ end function coerce_attrvar_component( ob::Symbol, f::VarFunction,::TypeSet{T},::TypeSet{T}, dom_size::Int, codom_size::Int; kw...) where {T} - # length(dom(f.fun)) == dom_size || error("Domain error in component $ob: $(dom(f.fun))!=$dom_size") - length(f.codom) == codom_size || error("Codomain error in component $ob: $(f.fun.codom)!=$codom_size") + length(f.codom) == codom_size || error( + "Codomain error in component $ob: $(f.fun.codom)!=$codom_size") return f end diff --git a/src/categorical_algebra/HomSearch.jl b/src/categorical_algebra/HomSearch.jl index ea3a08154..35737c432 100644 --- a/src/categorical_algebra/HomSearch.jl +++ b/src/categorical_algebra/HomSearch.jl @@ -116,7 +116,8 @@ homomorphisms exist, it is exactly as expensive. homomorphisms(X::ACSet, Y::ACSet; alg=BacktrackingSearch(), kw...) = homomorphisms(X, Y, alg; kw...) -""" +""" Find all homomorphisms between two attributed ``C``-sets via BackTracking Search. + take = number of homomorphisms requested (stop the search process early if this number is reached) max = throw an error if we take more than this many morphisms (e.g. set max=1 if @@ -325,7 +326,7 @@ end """ Note: a successful search returns an *iterator* of solutions, rather than -a single solution. See `postprocess_res`. +a single solution. See `postprocess_search_results`. """ function backtracking_search(f, state::BacktrackingState, depth::Int; random=false) @@ -338,7 +339,7 @@ function backtracking_search(f, state::BacktrackingState, depth::Int; state.assignment, state.type_components, state.dom, state.codom)]) else m = Dict(k=>!isnothing(v) for (k,v) in pairs(state.inv_assignment)) - return f(postprocess_res(state.dom, state.codom, state.assignment, m)) + return f(postprocess_search_results(state.dom, state.codom, state.assignment, m)) end elseif mrv == 0 # An element has no allowable assignment, so we must backtrack. @@ -519,7 +520,7 @@ representables. This function takes a result assignment from backtracking search and returns an iterator of the implicit set of homomorphisms that it specifies. """ -function postprocess_res(dom, codom, assgn, monic) +function postprocess_search_results(dom, codom, assgn, monic) S = acset_schema(dom) od = Dict{Symbol,Vector{Int}}(k=>(assgn[k]) for k in objects(S))