Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/diff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions test/diff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ using Symbolics
using SymbolicUtils
using Test
using LinearAlgebra, SparseArrays
using StaticArrays
using Symbolics: value, unwrap

# Derivatives
Expand Down Expand Up @@ -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)
Expand Down
Loading