From 72b39f63cf1e14cbf3863fc31a4375359ee6b61a Mon Sep 17 00:00:00 2001 From: David Widmann Date: Fri, 13 Dec 2024 00:16:01 +0100 Subject: [PATCH] Add test of #555 --- test/diff.jl | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/diff.jl b/test/diff.jl index 6f0c97160..2d7906582 100644 --- a/test/diff.jl +++ b/test/diff.jl @@ -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