Skip to content

Commit 4d9abe3

Browse files
Merge pull request #124 from ChrisRackauckas-Claude/fix-vector-expressions
Add error handling for vector expressions
2 parents 4a11131 + 708e320 commit 4d9abe3

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/integral.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ function integrate(eq, x = nothing;
7272
detailed = true)
7373
deprecation_warnings(; homotopy, use_optim)
7474

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

7782
if x == nothing

test/runtests.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,3 +327,21 @@ end
327327
num_trials = 10)
328328
@test n > 0
329329
end
330+
331+
@testset "vector expression error handling" begin
332+
@variables x α
333+
334+
# Test that vector expressions throw an appropriate error
335+
@test_throws ErrorException("Vector expressions are not supported. Please use element-wise integration with `integrate.([expr1, expr2, ...], x)` instead.") integrate([x])
336+
@test_throws ErrorException("Vector expressions are not supported. Please use element-wise integration with `integrate.([expr1, expr2, ...], x)` instead.") integrate([1, 2 * α], α)
337+
338+
# Test that scalar integration still works
339+
@test integrate(x) == ((1//2)*(x^2), 0, 0)
340+
@test integrate(2 * α, α) ==^2, 0, 0)
341+
342+
# Test that element-wise integration works
343+
results = integrate.([1, 2 * α], α)
344+
@test length(results) == 2
345+
@test results[1] == (α, 0, 0)
346+
@test results[2] ==^2, 0, 0)
347+
end

0 commit comments

Comments
 (0)