Skip to content

Commit

Permalink
Fix bugs in Base.in methods and empty comprehension (#954)
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelsonric authored Jan 22, 2025
1 parent 6240f83 commit 246b5fb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/categorical_algebra/FinRelations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ FinRel(set::S) where {T,S<:AbstractSet{T}} = FinRel{S,T}(set)
Base.eltype(::Type{FinRel{S,T}}) where {S,T} = T
Base.iterate(s::FinRel, args...) = iterate(iterable(s), args...)
Base.length(s::FinRel) = length(iterable(s))
Base.in(s::FinRel, elem) = in(s, iterable(s))
Base.in(elem, s::FinRel) = in(elem, iterable(s))
iterable(s::FinRel{Int}) = 1:s.set
iterable(s::FinRel{<:AbstractSet}) = s.set

Expand Down
6 changes: 3 additions & 3 deletions src/categorical_algebra/FinSets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ FinSet(n::Int) = FinSetInt(n)

Base.iterate(set::FinSetInt, args...) = iterate(1:set.n, args...)
Base.length(set::FinSetInt) = set.n
Base.in(set::FinSetInt, elem) = in(elem, 1:set.n)
Base.in(elem, set::FinSetInt) = in(elem, 1:set.n)

Base.show(io::IO, set::FinSetInt) = print(io, "FinSet($(set.n))")

Expand All @@ -75,7 +75,7 @@ FinSet(collection::S) where {T, S<:Union{AbstractVector{T},AbstractSet{T}}} =

Base.iterate(set::FinSetCollection, args...) = iterate(set.collection, args...)
Base.length(set::FinSetCollection) = length(set.collection)
Base.in(set::FinSetCollection, elem) = in(elem, set.collection)
Base.in(elem, set::FinSetCollection) = in(elem, set.collection)

function Base.show(io::IO, set::FinSetCollection)
print(io, "FinSet(")
Expand Down Expand Up @@ -320,7 +320,7 @@ 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.in(elem, set::VarSet{T}) where T = in(elem, 1:set.n)
Base.eltype(set::VarSet{T}) where T = Union{AttrVar,T}


Expand Down
4 changes: 2 additions & 2 deletions src/wiring_diagrams/Algebras.jl
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,9 @@ function is_homomorphic(X::ACSet, Y::ACSet, ::HomomorphismQuery)
length(query(Y, homomorphism_query(X, count=true)...)) > 0
end

function make_homomorphism(row, X::StructACSet{S}, Y::StructACSet{S}) where S
function make_homomorphism(row::AbstractVector{T}, X::StructACSet{S}, Y::StructACSet{S}) where {T, S}
components = let i = 0
NamedTuple{ob(S)}([row[i+=1] for _ in parts(X,c)] for c in ob(S))
NamedTuple{ob(S)}(T[row[i+=1] for _ in parts(X,c)] for c in ob(S))
end
ACSetTransformation(components, X, Y)
end
Expand Down

0 comments on commit 246b5fb

Please sign in to comment.