Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Arlin committed Aug 22, 2023
1 parent 844caa6 commit 1beceaf
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 204 deletions.
6 changes: 0 additions & 6 deletions perf/Project.toml

This file was deleted.

4 changes: 1 addition & 3 deletions src/categorical_algebra/Categories.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ presented categories are provided by another module, [`FinCats`](@ref).
module Categories
export Category, Cat, TypeCat, Functor, Transformation, dom, codom, compose, id,
ob, hom, is_hom_equal, ob_map, hom_map, dom_ob, codom_ob, component,
OppositeCat, op, co, ob_type, hom_type, dom_type, codom_type
OppositeCat, op, co

using StructEquality

Expand Down Expand Up @@ -136,8 +136,6 @@ sometimes but not always the case (see [`Category`](@ref)), so when writing
generic code one should prefer the `ob_map` and `hom_map` functions.
"""
abstract type Functor{Dom<:Cat,Codom<:Cat} end
dom_type(F::Functor{Dom}) where Dom = Dom
codom_type(F::Functor{Dom,Codom}) where {Dom,Codom} = Codom

""" Evaluate functor on object.
"""
Expand Down
75 changes: 4 additions & 71 deletions src/categorical_algebra/DataMigrations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ function migrate(X::FinDomFunctor,M::DeltaSchemaMigration)
params = M.params
funcs = make_map(hom_generators(tgt_schema)) do f
Ff, c, d = hom_map(F, f), dom(tgt_schema, f), codom(tgt_schema, f)
if Ff isa GATExpr{:zeromap} #this is ugly but mo fincatgraphs mo problems
if head(Ff) == :zeromap
domain = obs[c]
codomain = obs[d]
FinDomFunction(params[nameof(f)](homfuns...),domain,codomain)
Expand Down Expand Up @@ -214,60 +214,6 @@ function get_src_schema(F::Functor)
end
end

#=
#Arbitrary migration
function migrate(X::FinDomFunctor, M::ContravariantDataMigration;
return_limits::Bool=false, tabular::Bool=false,colimit::Bool=false)
F = functor(M)
tgt_schema = dom(F)
homnames = get_homnames(X, tgt_schema)
homfuns = map(x -> hom_map(X, x), homnames)
params = M.params
lims_or_colims = make_map(ob_generators(tgt_schema)) do c
Fc = ob_map(F, c)
J = shape(Fc)
# XXX: Must supply object/morphism types to handle case of empty diagram.
diagram_types = if c isa AttrTypeExpr
(TypeSet, SetFunction)
elseif isempty(J)
(FinSet{Int}, FinFunction{Int})
else
(SetOb, FinDomFunction{Int})
end
#
# XXX: Disable domain check because acsets don't store schema equations.
limit_or_colimit = colimit ? colimit : limit
alg = colimit ? SpecializeColimit() : SpecializeLimit(fallback=ToBipartiteLimit())
lim_or_colim = limit_or_colimit(force(compose(Fc, X, strict=false), diagram_types...),alg=alg)
if tabular
names = (ob_generator_name(J, j) for j in ob_generators(J))
TabularLimit(lim_or_colim, names=names)
else
lim_or_colim
end
end
funcs = make_map(hom_generators(tgt_schema)) do f
Ff, c, d = hom_map(F, f), dom(tgt_schema, f), codom(tgt_schema, f)
f_params = haskey(params, f) ? map(x -> x(homfuns...), params[f]) : []
# XXX: Disable domain check for same reason.
# Hand the Julia function form of the not-yet-defined components to compose
universal(compose(Ff, X, strict=false, params=f_params), limits[c], limits[d])
end
Y = FinDomFunctor(mapvals(ob, limits), funcs, tgt_schema)
return_limits ? (Y, limits) : Y
end
=#
#=
function codom_r(F::Functor{Dom,Codom}) where {Dom,Codom}
@match Codom begin
a::Type{TypeCat{T,S}} where {T,S}=> codom_r(T)
a::Type{Diagram{T,C,F}} where {T,C,F} => codom_r(C)
a::Type{QueryDiagram{T,C,F,P}} where {T,C,F,P} => codom_r(C)
a::Type{<:FinCat} => C
_ => "you done it now"
end
end
=#
# Conjunctive migration
#----------------------
function migrate(X::FinDomFunctor, M::ConjSchemaMigration;
Expand All @@ -289,7 +235,7 @@ function migrate(X::FinDomFunctor, M::ConjSchemaMigration;
(SetOb, FinDomFunction{Int})
end
# Make sure the diagram to be limited is a FinCat{<:Int}.
# XXX: Disable domain check because acsets don't store schema equations.
# Disable domain check because acsets don't store schema equations.
k = dom_to_graph(diagram(force(compose(Fc, X, strict=false), diagram_types...)))
lim = limit(k,SpecializeLimit(fallback=ToBipartiteLimit()))
if tabular
Expand All @@ -301,10 +247,8 @@ function migrate(X::FinDomFunctor, M::ConjSchemaMigration;
end
funcs = make_map(hom_generators(tgt_schema)) do f
Ff, c, d = hom_map(F, f), dom(tgt_schema, f), codom(tgt_schema, f)
#Not sure whether params[nameof(f)] might ever
#need to have multiple entries.
f_params = haskey(params,nameof(f)) ? Dict(nameof(codom(f)) => params[nameof(f)](homfuns...)) : Dict()
# XXX: Disable domain check for same reason.
# Disable domain check for same reason.
# Hand the Julia function form of the not-yet-defined components to compose
universal(compose(Ff, X, strict=false,params=f_params), limits[c], limits[d])
end
Expand All @@ -330,9 +274,6 @@ function migrate(X::FinDomFunctor, M::GlueSchemaMigration)
end
funcs = make_map(hom_generators(tgt_schema)) do f
Ff, c, d = hom_map(F, f), dom(tgt_schema, f), codom(tgt_schema, f)
#Get a single anonymous function, if there's one needed and
#the domain of Ff's shape map is a singleton, or else get a dict
#of them if the domain is a non-singleton and there are any.
f_params = haskey(params,f) ? map(x->x(homfuns...),params[f]) :
isempty(get_params(Ff)) ? [] : mapvals(x->x(homfuns...),get_params(Ff))
universal(compose(Ff, X, strict=false,params=f_params), colimits[c], colimits[d])
Expand Down Expand Up @@ -365,8 +306,7 @@ function migrate(X::FinDomFunctor, M::GlucSchemaMigration)
haskey(Ff_params,nameof(j)) ?
Dict(only(keys(components(diagram_map(Ffⱼ))))=>Ff_params[nameof(j)](homfuns...)) :
mapvals(x->x(homfuns...),get_params(Ffⱼ)) : Dict{Int,Int}()
universal(compose(Ffⱼ, X, strict=false,params = Ffⱼ_params),
Fc_limits[j], Fd_limits[j′])
universal(compose(Ffⱼ, X, strict=false,params = Ffⱼ_params), Fc_limits[j], Fd_limits[j′])
end
Ff_set = DiagramHom{id}(shape_map(Ff), component_funcs, Fc_set, Fd_set)
universal(Ff_set, Fc_colim, Fd_colim)
Expand Down Expand Up @@ -713,14 +653,7 @@ function colimit_representables(M::ConjSchemaMigration, y)
end
FinDomFunctor(mapvals(ob, colimits), homs, op(J))
end
# FIXME: The edge name should also be uniquely indexed, but this currently
# doesn't play nicely with nullable attributes.

#vertex_name(g::AbstractNamedGraph, args...) = subpart(g, args..., :vname)
#edge_name(g::AbstractNamedGraph, args...) = subpart(g, args..., :ename)

vertex_named(g::NamedGraph, name) = only(incident(g, name, :vname))
#edge_named(g::AbstractNamedGraph, name)= only(incident(g, name, :ename))
# Schema translation
####################

Expand Down
22 changes: 8 additions & 14 deletions src/categorical_algebra/Diagrams.jl
Original file line number Diff line number Diff line change
Expand Up @@ -291,11 +291,8 @@ function param_compose(α::FinTransformation, H::Functor; params=[])
if head(f) == :zeromap
func = params[i]
FinDomFunction(func,s,t)
#may need to population params with identities
else
func = haskey(params,i) ? SetFunction(params[i],t,t) : SetFunction(identity,t,t)
#could change target to let the attribute be valued in the
#wrong place fufufu
hom_map(H,f)func
end
end
Expand All @@ -305,28 +302,21 @@ end

#This is only to be used when F lands in Set, or wherever
#the functions in d's params are supposed to live.
#Perhaps needs a keyword argument about whether to fill in
#blanks
#Also inelegant way of returning
function compose(d::QueryDiagram{T},F::Functor; kw...) where T
D = diagram(d)
partial = compose(D,F;strict=false) #cannot be evaluated on the keys of params yet
#Get the FinDomFunctions in the range of F that must be plugged into
#the Functions in params
#XXX this is more lines that it needs to be
params = d.params
attrs,homs = generators(presentation(codom(D)),:Attr),generators(presentation(codom(D)),:Hom)
mornames = map(first,[attrs;homs])
morfuns = map(x->hom_map(F,x),mornames)
morfuns = map(x->hom_map(F,nameof(x)),hom_generators(codom(D)))
paramsNew = Dict{keytype(params),FinDomFunction}()
for (n,f) in params #Calculate the intended value of the composition on n
domain = ob_map(partial,dom(hom(dom(partial),n)))
codomain = ob_map(partial,codom(hom(dom(partial),n)))
paramsNew[n] =
FinDomFunction(f(morfuns...),domain,codomain)
end
composite = force(partial;params = paramsNew)

composite = force(partial;params = paramsNew)
Diagram{T}(composite)
end
# Limits and colimits
Expand Down Expand Up @@ -372,7 +362,9 @@ end

# TODO: Define monad multiplications that go along with the units.

#Sends an object of C to the diagram picking it out.
"""
Sends an object of C to the diagram picking it out.
"""
function munit(::Type{Diagram{T}}, C::Cat, x; shape=nothing) where T
if isnothing(shape)
shape = FinCat(1)
Expand All @@ -385,7 +377,9 @@ function munit(::Type{Diagram{T}}, C::Cat, x; shape=nothing) where T
end
hasPresentation(C::FinCat) = false
hasPresentation(C::FinCatPresentation) = true

"""
Sends a morphism of C to the diagram picking it out.
"""
function munit(::Type{DiagramHom{T}}, C::Cat, f;
dom_shape=nothing, codom_shape=nothing) where T
f = hom(C, f)
Expand Down
30 changes: 0 additions & 30 deletions src/categorical_algebra/FinCats.jl
Original file line number Diff line number Diff line change
Expand Up @@ -370,17 +370,6 @@ function FinCatPresentation(pres::Presentation{ThSchema})
Hom = Union{S.Hom, S.Attr, S.AttrType}
FinCatPresentation{ThSchema,Ob,Hom}(pres)
end
#=
#TBD whether this guy should get explicit generators for the
#zero object and homs. These are legitimate generators when seen qua
#category but not qua pointed category...
function FinCatPresentation(pres::Presentation{ThPtCategory})
S = pres.syntax
Ob = S.Ob
Hom = Union{S.Hom,S.ZeroHom}
FinCatPresentation{ThPtCategory,Ob,Hom}(pres)
end
=#

#better to inherit from schema to avoid this kind of thing
function FinCatPresentation(pres::Presentation{ThPtSchema})
Expand All @@ -405,24 +394,6 @@ side and any equations. Optionally returns
the mappings from generators to their indices
in the resulting graph.
"""
#=
function graph(C::FinCatPresentation;maps::Bool=false,inv::Bool=false)
g = Graph()
pres = C.presentation
obgens = pres.generators[:Ob]
homgens = pres.generators[:Hom]
nob = length(obgens)
add_parts!(g,:V,nob)
map(pres.generators[:Hom]) do f
i,j = indexin([dom(f),codom(f)],pres.generators[:Ob])
add_edge!(g,i,j)
end
maps || return g
inv ? (g, Dict(obgens[i] => i for i in 1:length(obgens)),
Dict(homgens[i] => i for i in 1:length(homgens))) :
(g, Dict(pairs(obgens)), Dict(pairs(homgens)))
end
=#
presentation(C::FinCatPresentation) = C.presentation

ob_generators(C::FinCatPresentation) = generators(presentation(C), :Ob)
Expand Down Expand Up @@ -561,7 +532,6 @@ function functoriality_failures(F::FinDomFunctor; check_equations::Bool=false)
(bad_dom, bad_cod, bad_eqs)
end

#XX:make more principled using make_map or something similar
function Base.map(F::Functor{<:FinCat,<:TypeCat}, f_ob, f_hom)
C = dom(F)
FinDomFunctor(map(x -> f_ob(ob_map(F, x)), ob_generators(C)),
Expand Down
Loading

0 comments on commit 1beceaf

Please sign in to comment.