Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Informative error for coerce_component with scalar input #936

Merged
merged 1 commit into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading