Skip to content

Commit

Permalink
Add test of #555
Browse files Browse the repository at this point in the history
  • Loading branch information
devmotion committed Dec 12, 2024
1 parent 639daa5 commit 72b39f6
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions test/diff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -465,3 +465,21 @@ let
expr = 3x₁^2 + 4x₁ * x₂ + mymul1plog(q[1], x₂)
@test Matrix(Symbolics.hessian_sparsity(expr, [x₁, x₂])) == [true true; true true]
end

# issue #555
let
# first example
@variables p[1:1] x[1:1]
p = collect(p)
x = collect(x)
@test collect(Symbolics.sparsehessian(p[1] * x[1], x)) == [0;;]
@test isequal(collect(Symbolics.sparsehessian(p[1] * x[1]^2, x)), [2p[1];;])

# second example
@variables a[1:2]
a = collect(a)
ex = (a[1]+a[2])^2
@test Symbolics.hessian(ex, [a[1]]) == [2;;]
@test collect(Symbolics.sparsehessian(ex, [a[1]])) == [2;;]
@test collect(Symbolics.sparsehessian(ex, a)) == fill(2, 2, 2)
end

0 comments on commit 72b39f6

Please sign in to comment.