Skip to content
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
5 changes: 5 additions & 0 deletions src/integral.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ function integrate(eq, x = nothing;
detailed = true)
deprecation_warnings(; homotopy, use_optim)

# Check if eq is a vector/array expression and throw an error
if eq isa AbstractArray || eq isa AbstractVector
error("Vector expressions are not supported. Please use element-wise integration with `integrate.([expr1, expr2, ...], x)` instead.")
end

eq = expand(eq)

if x == nothing
Expand Down
18 changes: 18 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -327,3 +327,21 @@ end
num_trials = 10)
@test n > 0
end

@testset "vector expression error handling" begin
@variables x α

# Test that vector expressions throw an appropriate error
@test_throws ErrorException("Vector expressions are not supported. Please use element-wise integration with `integrate.([expr1, expr2, ...], x)` instead.") integrate([x])
@test_throws ErrorException("Vector expressions are not supported. Please use element-wise integration with `integrate.([expr1, expr2, ...], x)` instead.") integrate([1, 2 * α], α)

# Test that scalar integration still works
@test integrate(x) == ((1//2)*(x^2), 0, 0)
@test integrate(2 * α, α) == (α^2, 0, 0)

# Test that element-wise integration works
results = integrate.([1, 2 * α], α)
@test length(results) == 2
@test results[1] == (α, 0, 0)
@test results[2] == (α^2, 0, 0)
end
Loading