Skip to content

Commit

Permalink
Merge pull request #936 from slwu89/coerce-component-error
Browse files Browse the repository at this point in the history
Informative error for `coerce_component` with scalar input
  • Loading branch information
epatters authored Sep 4, 2024
2 parents b71a5b8 + ce50fb6 commit 982ea6e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/categorical_algebra/CSets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,11 @@ function coerce_component(ob::Symbol, f::FinFunction{Int,Int},
return f
end

coerce_component(::Symbol, f, dom_size::Int, codom_size::Int; kw...) =
coerce_component(ob::Symbol, f::T, dom_size::Int, codom_size::Int; kw...) where {T<:Integer} =
error("Scalar component for $ob not allowed; " *
"this is probably from a scalar component in an ACSetTransformation, please use a vector")

coerce_component(::Symbol, f::T, dom_size::Int, codom_size::Int; kw...) where {T<:AbstractVector{<:Integer}}=
FinFunction(f, dom_size, codom_size; kw...)

function coerce_attrvar_component(
Expand Down
2 changes: 2 additions & 0 deletions test/categorical_algebra/CSets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ f = ACSetTransformation(X,X; V=[1,2], E=[1,2,3])
@test components(f) == (V=FinFunction([1,2]), E=FinFunction([1,2,3]),
Weight=VarFunction{Float64}([], FinSet(0)))

@test_throws ErrorException ACSetTransformation(Y,X; V=[1,2], E=1)
g = ACSetTransformation(Y,X; V=[1,2], E=[1])
@test is_natural(g)
@test compose(g,f) |> force == g
Expand Down Expand Up @@ -300,6 +301,7 @@ diagram = FreeDiagram([g, ob(terminal(Graph)), Graph(1)], [(α,3,1), (β,3,2)])
# Constructors and accessors. Test type conversion as well Int -> Float64
g = path_graph(WeightedGraph{Float64}, 2, E=(weight=2,))
h = path_graph(WeightedGraph{Float64}, 4, E=(weight=[1,2,3],))
@test_throws ErrorException ACSetTransformation((V=[2,3], E=2), g, h)
α = ACSetTransformation((V=[2,3], E=[2]), g, h)
@test length(components(α)) == 3

Expand Down

0 comments on commit 982ea6e

Please sign in to comment.