Skip to content

Commit

Permalink
fix: handle unsized array symbolics in linear_expansion
Browse files Browse the repository at this point in the history
  • Loading branch information
AayushSabharwal committed Jan 20, 2025
1 parent d67cf8d commit d294b0e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/linear_algebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ function _linear_expansion(t, x)
elseif op === getindex
arrt, idxst... = arguments(t)
isequal(arrt, arrx) && return (0, t, true)
shape(arrt) == Unknown() && return (0, t, true)

indexed_t = OffsetArrays.Origin(map(first, axes(arrt)))(Symbolics.scalarize(arrt))[idxst...]
# when indexing a registered function/callable symbolic
Expand Down
4 changes: 4 additions & 0 deletions test/linear_solver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,8 @@ a, b, islinear = Symbolics.linear_expansion(D(x) - x, x)
@variables x[0:2]
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::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])
end

0 comments on commit d294b0e

Please sign in to comment.