diff --git a/src/diff.jl b/src/diff.jl index 3c7449260..3e40eb5f6 100644 --- a/src/diff.jl +++ b/src/diff.jl @@ -648,17 +648,17 @@ end function jacobian(ops, vars; simplify=false, kwargs...) ops = vec(scalarize(ops)) - if ops isa Vector{Num} - ops = unwrap.(ops)::Vector{SymbolicT} - elseif ops isa Vector{SymbolicT} + if ops isa AbstractVector{Num} + ops = unwrap.(ops)::AbstractVector{SymbolicT} + elseif ops isa AbstractVector{SymbolicT} else - ops = ops::Vector{eltype(ops)} + ops = ops::AbstractVector{eltype(ops)} end # Suboptimal, but prevents wrong results on Arr for now. Arr resulting from a symbolic function will fail on this due to unknown size. vars = vec(scalarize(vars)) - if vars isa Vector{Num} - vars = unwrap.(vars)::Vector{SymbolicT} - elseif vars isa Vector{SymbolicT} + if vars isa AbstractVector{Num} + vars = unwrap.(vars)::AbstractVector{SymbolicT} + elseif vars isa AbstractVector{SymbolicT} else error("This should not happen!") end diff --git a/test/diff.jl b/test/diff.jl index 5076eb87c..fbfde790f 100644 --- a/test/diff.jl +++ b/test/diff.jl @@ -2,6 +2,7 @@ using Symbolics using SymbolicUtils using Test using LinearAlgebra, SparseArrays +using StaticArrays using Symbolics: value, unwrap # Derivatives @@ -65,6 +66,19 @@ test_equal(jac[3,1], y) test_equal(jac[3,2], x) test_equal(jac[3,3], -1β) +# issue #1691 - jacobian with SVector input +@testset "jacobian with SVector" begin + @variables a b + sv_ops = SVector(a^2 + b, a*b) + sv_vars = SVector(a, b) + sv_jac = Symbolics.jacobian(sv_ops, sv_vars) + @test sv_jac isa Matrix{Num} + test_equal(sv_jac[1,1], 2a) + test_equal(sv_jac[1,2], 1) + test_equal(sv_jac[2,1], b) + test_equal(sv_jac[2,2], a) +end + # issue #545 z = t + t^2 test_equal(expand_derivatives(D(z)), 1 + t * 2)