From d294b0eff07f80641dec4b8b478f9862d09ac297 Mon Sep 17 00:00:00 2001 From: Aayush Sabharwal Date: Mon, 20 Jan 2025 17:54:31 +0530 Subject: [PATCH] fix: handle unsized array symbolics in `linear_expansion` --- src/linear_algebra.jl | 1 + test/linear_solver.jl | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/src/linear_algebra.jl b/src/linear_algebra.jl index bcaaaeaff..8f30fb095 100644 --- a/src/linear_algebra.jl +++ b/src/linear_algebra.jl @@ -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 diff --git a/test/linear_solver.jl b/test/linear_solver.jl index 8881f3b00..e3f038af8 100644 --- a/test/linear_solver.jl +++ b/test/linear_solver.jl @@ -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