Skip to content

Commit

Permalink
Merge pull request #1415 from AayushSabharwal/as/arr-linear_expansion
Browse files Browse the repository at this point in the history
fix: fix handling of arrays of symbolics in `linear_expansion`
  • Loading branch information
ChrisRackauckas authored Jan 23, 2025
2 parents 8841664 + dd81de5 commit 1fa7f87
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ DynamicPolynomials = "0.5, 0.6"
ForwardDiff = "0.10.36"
Groebner = "0.8.2"
IfElse = "0.1"
KernelAbstractions = "<0.9.31"
LaTeXStrings = "1.3"
LambertW = "1.0.0"
Latexify = "0.16"
Expand Down Expand Up @@ -104,6 +105,7 @@ ComponentArrays = "b0b7db55-cfe3-40fc-9ded-d10e2dbeff66"
DynamicQuantities = "06fc5a27-2a28-4c7c-a15d-362465fb6821"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
Groebner = "0b43b601-686d-58a3-8a1c-6623616c7cd4"
KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c"
LambertW = "984bce1d-4616-540c-a9ee-88d1112d94c9"
Lux = "b2108857-7c20-44ae-9111-449ecde12c47"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Expand All @@ -115,4 +117,4 @@ SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test", "SafeTestsets", "Pkg", "PkgBenchmark", "PreallocationTools", "ForwardDiff", "Groebner", "BenchmarkTools", "ReferenceTests", "Random", "LambertW", "Lux", "ComponentArrays", "Nemo", "DynamicQuantities"]
test = ["Test", "SafeTestsets", "Pkg", "PkgBenchmark", "PreallocationTools", "ForwardDiff", "Groebner", "BenchmarkTools", "ReferenceTests", "Random", "LambertW", "Lux", "ComponentArrays", "Nemo", "DynamicQuantities", "KernelAbstractions"]
5 changes: 4 additions & 1 deletion src/linear_algebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -362,9 +362,12 @@ function _occursin_array(sym, arrsym, arr)
if symbolic_type(el) == NotSymbolic()
return el isa AbstractArray && _occursin_array(sym, arrsym, el)
else
return occursin(sym, el) || occursin(arrsym, el)
if sym !== nothing && occursin(sym, el) || arrsym !== nothing && occursin(arrsym, el)
return true
end
end
end
return false
end

###
Expand Down
2 changes: 2 additions & 0 deletions test/downstream/Project.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
[deps]
DynamicQuantities = "06fc5a27-2a28-4c7c-a15d-362465fb6821"
KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c"
ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78"
ParameterizedFunctions = "65888b18-ceab-5e60-b2b9-181511a3b968"
Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7"
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"

[compat]
KernelAbstractions = "<0.9.31"
ModelingToolkit = "8.33, 9"
ParameterizedFunctions = "5.15"
Symbolics = "6"
Expand Down
3 changes: 3 additions & 0 deletions test/linear_solver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,7 @@ a, b, islinear = Symbolics.linear_expansion(D(x) - x, x)
@variables x::Vector{Real}
a, b, islin = Symbolics.linear_expansion(x[0] - z(x[1]), z(x[1]))
@test islin && isequal(a, -1) && isequal(b, x[0])

@variables x y
@test !Symbolics.linear_expansion(x + z([x, y]), y)[3]
end

0 comments on commit 1fa7f87

Please sign in to comment.