Skip to content

Commit

Permalink
Merge pull request #610 from AlgebraicJulia/kris-brown-patch-1
Browse files Browse the repository at this point in the history
add hash method for diagram/diagram hom
  • Loading branch information
epatters authored Mar 29, 2022
2 parents e4b1b5f + d908a1d commit c964d26
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/categorical_algebra/Diagrams.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ 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.:(==)(d1::Diagram{T}, d2::Diagram{S}) where {T,S} =
T == S && diagram(d1) == diagram(d2)

Expand Down Expand Up @@ -137,6 +139,9 @@ 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.:(==)(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
Expand Down
4 changes: 4 additions & 0 deletions test/categorical_algebra/Diagrams.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@ d = Diagram(D)
@test ob_map(d, 3) == SchSGraph[:V]
@test hom_map(d, 1) == SchSGraph[:tgt]
@test startswith(sprint(show, d), "Diagram{id}(")
@test hash(D) == hash(D)
@test hash(D) != hash(Diagram{op}(D))

# Diagram morphisms
###################

f = DiagramHom([(2,:inv), (1,:inv), 3], [2,1], d, d)
@test dom(f) == d
@test codom(f) == d
@test hash(f) == hash(DiagramHom([(2,:inv), (1,:inv), 3], [2,1], d, d))
@test is_functorial(shape_map(f))
@test shape_map(f) == FinFunctor([2,1,3], [2,1], C, C)
ϕ = diagram_map(f)
Expand All @@ -41,6 +44,7 @@ f = DiagramHom([(2,:inv), (1,:inv), 3], [2,1], d, d)
@test collect_hom(f) == [Path(graph(C), 2), Path(graph(C), 1)]
= ff
@test shape_map(f²) == FinFunctor(1:3, 1:2, C, C)
@test hash(f) != hash(f²)

f = DiagramHom{op}([(2,:inv), (1,:inv), 3], [2,1], D, D)
ιV = FinDomFunctor([:V], FinCat(1), FinCat(SchSGraph))
Expand Down

0 comments on commit c964d26

Please sign in to comment.