JuliaSymbolics/Symbolics.jl

Symbolics.hessian and Symbolics.sparsehessian discrepancy

asterycs opened this issue · 1 comments

Hello! I encountered a use case that errors with sparsehessian but not with hessian. Below is an MVE:

using Symbolics

function f(x, y)
    y[1] * x'*x + y[2] * x'*x
end

@variables x[1:10] y[1:2]

H = Symbolics.hessian(f(collect(x), collect(y)), collect(x))
# H = Symbolics.sparsehessian(f(collect(x), collect(y)), collect(x)) # errors

hfuns = Symbolics.build_function(H, collect(x), collect(y), expression = Val{false}())

@show hfuns[1](ones(10), [2.0, 3.0])

The error message is rather long but starts with:

ERROR: LoadError: Failed to apply rule (~f)(~x, ~y) => begin ...
...
[40] top-level scope
    @ (...)/main.jl:10

Could this be a bug or is it perhaps a limitation of sparsehessian?

This looks like a bug.