Skip to content

Commit

Permalink
Merge pull request #641 from epatters/structequality
Browse files Browse the repository at this point in the history
Replace AutoHashEquals with StructEquality
  • Loading branch information
epatters committed Jul 19, 2022
2 parents 3dc22f3 + 9ae5d5c commit 11b7f57
Show file tree
Hide file tree
Showing 23 changed files with 110 additions and 108 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ authors = ["Evan Patterson <[email protected]>"]
version = "0.13.12"

[deps]
AutoHashEquals = "15f4f7f2-30c1-5605-9d31-71845cf9641f"
Compose = "a81c6b42-2e10-5240-aca2-a61377ecd94b"
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
GeneralizedGenerated = "6b9d7cbe-bcb9-11e9-073f-15a7a543e2eb"
Expand All @@ -22,10 +21,10 @@ Requires = "ae029012-a4dd-5104-9daa-d747884805df"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
StructEquality = "6ec83bb0-ed9f-11e9-3b4c-2b04cb4e219c"
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"

[compat]
AutoHashEquals = "0.2"
Compose = "0.7, 0.8, 0.9"
DataStructures = "0.17, 0.18"
GeneralizedGenerated = "0.2, 0.3"
Expand All @@ -36,6 +35,7 @@ PrettyTables = "0.12, 1.0"
Reexport = "^1"
Requires = "^1"
StaticArrays = "0.12, 1.0"
StructEquality = "2.1"
Tables = "^1"
julia = "1.6"

Expand Down
5 changes: 4 additions & 1 deletion experiments/CompAlgebra/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ authors = ["Evan Patterson <[email protected]>"]
version = "0.1.0"

[deps]
AutoHashEquals = "15f4f7f2-30c1-5605-9d31-71845cf9641f"
Catlab = "134e5e36-593f-5add-ad60-77f754baafbe"
GeneralizedGenerated = "6b9d7cbe-bcb9-11e9-073f-15a7a543e2eb"
Match = "7eb4fadd-790c-5f42-8a69-bfa0b872bfbf"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
StructEquality = "6ec83bb0-ed9f-11e9-3b4c-2b04cb4e219c"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[compat]
StructEquality = "2.1"
4 changes: 2 additions & 2 deletions experiments/CompAlgebra/src/MathFormulas.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export Formula, head, args, first, last, to_formula, to_wiring_diagram,
import Base: first, last, show
import Base.Meta: show_sexpr

using AutoHashEquals
using StructEquality
using Match

using Catlab
Expand All @@ -39,7 +39,7 @@ the operations (head symbols) are interpreted as Julia functions, e.g., `:/` is
right multiplication by the matrix pseudoinverse while `:./` is the elementwise
division.
"""
@auto_hash_equals struct Formula
@struct_hash_equal struct Formula
head::Symbol
args::Vector
Formula(head::Symbol, args...) = new(head, collect(args))
Expand Down
10 changes: 5 additions & 5 deletions src/categorical_algebra/CSets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export ACSetTransformation, CSetTransformation,

using Base.Iterators: flatten
using Base.Meta: quot
using AutoHashEquals
using StructEquality
using JSON
using Reexport
using Tables
Expand Down Expand Up @@ -141,7 +141,7 @@ const ACSetDomCat = FinCats.FinCatPresentation{

""" Wrapper type to interpret attributed C-set as a functor.
"""
@auto_hash_equals struct ACSetFunctor{ACS<:ACSet} <:
@struct_hash_equal struct ACSetFunctor{ACS<:ACSet} <:
Functor{ACSetDomCat,TypeCat{SetOb,FinDomFunction{Int}}}
acset::ACS
end
Expand Down Expand Up @@ -260,7 +260,7 @@ CSetTransformation(X::StructCSet, Y::StructCSet; components...) =
See [`ACSetTranformation`](@ref) for the distinction between tight and loose.
"""
@auto_hash_equals struct TightACSetTransformation{
@struct_hash_equal struct TightACSetTransformation{
S <: SchemaDescType, Comp <: NamedTuple,
Dom <: StructACSet{S}, Codom <: StructACSet{S}} <: ACSetTransformation{S,Comp,Dom,Codom}
components::Comp
Expand Down Expand Up @@ -314,7 +314,7 @@ end
See [`ACSetTranformation`](@ref) for the distinction between tight and loose.
"""
@auto_hash_equals struct LooseACSetTransformation{
@struct_hash_equal struct LooseACSetTransformation{
S <: SchemaDescType, Comp <: NamedTuple, TypeComp <: NamedTuple,
Dom <: StructACSet{S}, Codom <: StructACSet{S}} <: ACSetTransformation{S,Comp,Dom,Codom}
components::Comp
Expand Down Expand Up @@ -932,7 +932,7 @@ force(A::SubACSet) = Subobject(force(hom(A)))

""" Sub-C-set represented componentwise as a collection of subsets.
"""
@auto_hash_equals struct SubACSetComponentwise{
@struct_hash_equal struct SubACSetComponentwise{
Ob<:ACSet, Comp<:NamedTuple} <: Subobject{Ob}
ob::Ob
components::Comp
Expand Down
16 changes: 8 additions & 8 deletions src/categorical_algebra/Categories.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export 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

using AutoHashEquals
using StructEquality

using ...GAT
import ...Theories: Category2, ob, hom, dom, codom, compose, , , id,
Expand Down Expand Up @@ -141,7 +141,7 @@ abstract type Functor{Dom<:Cat,Codom<:Cat} end

""" Identity functor on a category.
"""
@auto_hash_equals struct IdentityFunctor{Dom<:Cat} <: Functor{Dom,Dom}
@struct_hash_equal struct IdentityFunctor{Dom<:Cat} <: Functor{Dom,Dom}
dom::Dom
end

Expand All @@ -158,7 +158,7 @@ end

""" Composite of functors.
"""
@auto_hash_equals struct CompositeFunctor{Dom,Codom,
@struct_hash_equal struct CompositeFunctor{Dom,Codom,
F<:Functor{Dom,<:Cat},G<:Functor{<:Cat,Codom}} <: Functor{Dom,Codom}
fst::F
snd::G
Expand Down Expand Up @@ -204,7 +204,7 @@ Functor(f::Function, g::Function, C::Cat, D::Cat) = FunctorCallable(f, g, C, D)

""" Functor defined by two Julia callables, an object map and a morphism map.
"""
@auto_hash_equals struct FunctorCallable{Dom,Codom} <: Functor{Dom,Codom}
@struct_hash_equal struct FunctorCallable{Dom,Codom} <: Functor{Dom,Codom}
ob_map::Any
hom_map::Any
dom::Dom
Expand Down Expand Up @@ -253,7 +253,7 @@ Given ``α: F ⇒ G: C → D``, this function returns ``D``.
"""
codom_ob::Transformation) = codom(dom(α)) # == codom(codom(α))

@auto_hash_equals struct IdentityTransformation{C<:Cat,D<:Cat,Dom<:Functor{C,D}} <:
@struct_hash_equal struct IdentityTransformation{C<:Cat,D<:Cat,Dom<:Functor{C,D}} <:
Transformation{C,D,Dom,Dom}
dom::Dom
end
Expand Down Expand Up @@ -360,7 +360,7 @@ end
Call `op(::Cat)` instead of directly instantiating this type.
"""
@auto_hash_equals struct OppositeCat{Ob,Hom,Size<:CatSize,C<:Cat{Ob,Hom,Size}} <:
@struct_hash_equal struct OppositeCat{Ob,Hom,Size<:CatSize,C<:Cat{Ob,Hom,Size}} <:
Cat{Ob,Hom,Size}
cat::C
end
Expand All @@ -377,7 +377,7 @@ compose(C::OppositeCat, f, g) = compose(C.cat, g, f)
Call `op(::Functor)` instead of directly instantiating this type.
"""
@auto_hash_equals struct OppositeFunctor{C,D,F<:Functor{C,D}} <: Functor{C,D}
@struct_hash_equal struct OppositeFunctor{C,D,F<:Functor{C,D}} <: Functor{C,D}
# XXX: Requires more type parameters: ObC, HomC, ObD, HomD.
#Functor{OppositeCat{C},OppositeCat{D}}
func::F
Expand All @@ -399,7 +399,7 @@ do_compose(F::OppositeFunctor, G::OppositeFunctor) =
Call `op(::Transformation)` instead of directly instantiating this type.
"""
@auto_hash_equals struct OppositeTransformation{C,D,F,G,T<:Transformation{C,D,F,G}} <: Transformation{C,D,F,G}
@struct_hash_equal struct OppositeTransformation{C,D,F,G,T<:Transformation{C,D,F,G}} <: Transformation{C,D,F,G}
# XXX: Requires more type parameters: ObC, HomC, ObD, HomD.
#Transformation{OppositeCat{C},OppositeCat{D},OppositeFunctor{C,D,G},OppositeFunctor{C,D,F}}
trans::T
Expand Down
4 changes: 2 additions & 2 deletions src/categorical_algebra/CommutativeDiagrams.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ commutative squares are implemented.
module CommutativeDiagrams
export SquareDiagram, ob, hom, left, right, top, bottom

using AutoHashEquals
using StructEquality

using ...GAT
using ...Theories: DoubleCategory
Expand All @@ -23,7 +23,7 @@ Creates a square diagram in a category, which forms the 2-cells of the double
category Sq(C). The four 1-cells are given in top, bottom, left, right order, to
match the GAT of a double category.
"""
@auto_hash_equals struct SquareDiagram{Ob,Hom,Homs<:AbstractVector{Hom}}
@struct_hash_equal struct SquareDiagram{Ob,Hom,Homs<:AbstractVector{Hom}}
corners::Vector{Ob}
sides::Homs
end
Expand Down
12 changes: 6 additions & 6 deletions src/categorical_algebra/Diagrams.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
module Diagrams
export Diagram, DiagramHom, id, op, co, shape, diagram, shape_map, diagram_map

using StructEquality

using ...GAT
import ...Theories: dom, codom, id, compose, , , munit
using ...Theories: Category, composeH
Expand Down Expand Up @@ -41,10 +43,10 @@ This is the domain of the underlying functor.
"""
shape(d::Diagram) = dom(diagram(d))

Base.hash(d::Diagram{T}, h::UInt) where {T} = hash(T, hash(diagram(d), h))
Base.hash(d::Diagram{T}, h::UInt) where {T} = hash(T, struct_hash(d, h))

Base.:(==)(d1::Diagram{T}, d2::Diagram{S}) where {T,S} =
T == S && diagram(d1) == diagram(d2)
T == S && struct_equal(d1, d2)

ob_map(d::Diagram, x) = ob_map(diagram(d), x)
hom_map(d::Diagram, f) = hom_map(diagram(d), f)
Expand Down Expand Up @@ -132,12 +134,10 @@ cell2(D::FinDomFunctor, x) = id(codom(D), ob_map(D, x))
shape_map(f::DiagramHom) = f.shape_map
diagram_map(f::DiagramHom) = f.diagram_map

Base.hash(f::DiagramHom{T}, h::UInt) where {T} = hash(T, hash(f.shape_map,
hash(f.diagram_map, hash(f.precomposed_diagram, h))))
Base.hash(f::DiagramHom{T}, h::UInt) where {T} = hash(T, struct_hash(f, h))

Base.:(==)(f::DiagramHom{T}, g::DiagramHom{S}) where {T,S} =
T == S && shape_map(f) == shape_map(g) && diagram_map(f) == diagram_map(g) &&
f.precomposed_diagram == g.precomposed_diagram
T == S && struct_equal(f, g)

ob_map(f::DiagramHom, x) = (ob_map(f.shape_map, x), component(f.diagram_map, x))
hom_map(f::DiagramHom, g) = hom_map(f.shape_map, g)
Expand Down
14 changes: 7 additions & 7 deletions src/categorical_algebra/FinCats.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export FinCat, FinCatGraph, Path, ob_generator, hom_generator,
FinFunctor, FinDomFunctor, is_functorial, collect_ob, collect_hom, force,
FinTransformation, components, is_natural, is_initial

using AutoHashEquals
using StructEquality
using Reexport
using StaticArrays: SVector
using DataStructures: IntDisjointSets, in_same_set, num_groups
Expand Down Expand Up @@ -162,7 +162,7 @@ end
The path is allowed to be empty but always has definite start and end points
(source and target vertices).
"""
@auto_hash_equals struct Path{V,E,Edges<:AbstractVector{E}}
@struct_hash_equal struct Path{V,E,Edges<:AbstractVector{E}}
edges::Edges
src::V
tgt::V
Expand Down Expand Up @@ -229,7 +229,7 @@ coerce_path(g::HasGraph, x) = Path(g, x)
The objects of the free category are vertices in the graph and the morphisms are
(possibly empty) paths.
"""
@auto_hash_equals struct FreeCatGraph{G<:HasGraph} <: FinCatPathGraph{G,Int,Int}
@struct_hash_equal struct FreeCatGraph{G<:HasGraph} <: FinCatPathGraph{G,Int,Int}
graph::G
end

Expand All @@ -252,7 +252,7 @@ The objects of the category are vertices in the graph and the morphisms are
paths, quotiented by the congruence relation generated by the path equations.
See (Spivak, 2014, *Category theory for the sciences*, §4.5).
"""
@auto_hash_equals struct FinCatGraphEq{G<:HasGraph,Eqs<:AbstractVector{<:Pair}} <:
@struct_hash_equal struct FinCatGraphEq{G<:HasGraph,Eqs<:AbstractVector{<:Pair}} <:
FinCatPathGraph{G,Int,Int}
graph::G
equations::Eqs
Expand Down Expand Up @@ -283,7 +283,7 @@ the attribute types are identity morphisms). When the schema is formalized as a
profunctor whose codomain category is discrete, this amounts to taking the
collage of the profunctor.
"""
@auto_hash_equals struct FinCatPresentation{T,Ob,Hom} <: FinCat{Ob,Hom}
@struct_hash_equal struct FinCatPresentation{T,Ob,Hom} <: FinCat{Ob,Hom}
presentation::Presentation{T}
end

Expand Down Expand Up @@ -446,7 +446,7 @@ Categories.show_type_constructor(io::IO, ::Type{<:FinFunctor}) =

""" Functor out of a finitely presented category given by explicit mappings.
"""
@auto_hash_equals struct FinDomFunctorMap{Dom<:FinCat, Codom<:Cat,
@struct_hash_equal struct FinDomFunctorMap{Dom<:FinCat, Codom<:Cat,
ObMap, HomMap} <: FinDomFunctor{Dom,Codom}
ob_map::ObMap
hom_map::HomMap
Expand Down Expand Up @@ -587,7 +587,7 @@ end

""" Natural transformation with components given by explicit mapping.
"""
@auto_hash_equals struct FinTransformationMap{C<:FinCat,D<:Cat,
@struct_hash_equal struct FinTransformationMap{C<:FinCat,D<:Cat,
Dom<:FinDomFunctor{C,D},Codom<:FinDomFunctor,Comp} <: FinTransformation{C,D,Dom,Codom}
components::Comp
dom::Dom
Expand Down
10 changes: 5 additions & 5 deletions src/categorical_algebra/FinRelations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export BoolRig, FinRel, FinRelation, FinRelationCallable, FinRelationMatrix,
force

import Base: +, *
using AutoHashEquals
using StructEquality

using ...GAT
using ...Theories: DistributiveBicategoryRelations
Expand All @@ -25,7 +25,7 @@ using ..Matrices: zero_matrix
This struct is needed because in base Julia, the product of booleans is another
boolean, but the sum of booleans is coerced to an integer: `true + true == 2`.
"""
@auto_hash_equals struct BoolRig <: Number
@struct_hash_equal struct BoolRig <: Number
value::Bool
end

Expand All @@ -44,7 +44,7 @@ Base.show(io::IO, x::BoolRig) = print(io, x.value)
See also: [`FinSet`](@ref).
"""
@auto_hash_equals struct FinRel{S,T}
@struct_hash_equal struct FinRel{S,T}
set::S
end

Expand Down Expand Up @@ -72,7 +72,7 @@ FinRelation(R::AbstractMatrix, args...) = FinRelationMatrix(R, args...)

""" Relation in FinRel defined by a callable Julia object.
"""
@auto_hash_equals struct FinRelationCallable{S,S′,T,T′} <: FinRelation{S,S′,T,T′}
@struct_hash_equal struct FinRelationCallable{S,S′,T,T′} <: FinRelation{S,S′,T,T′}
# Field `rel` is usually a `Function` but can be any Julia callable.
rel::Any
dom::FinRel{S,T}
Expand All @@ -91,7 +91,7 @@ FinRelationCallable(R, dom::Int, codom::Int) =
Boolean matrices are also known as logical matrices or relation matrices.
"""
@auto_hash_equals struct FinRelationMatrix{M<:AbstractMatrix{BoolRig}} <: FinRelation{Int,Int,Int,Int}
@struct_hash_equal struct FinRelationMatrix{M<:AbstractMatrix{BoolRig}} <: FinRelation{Int,Int,Int,Int}
rel::M
end

Expand Down
Loading

0 comments on commit 11b7f57

Please sign in to comment.