Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stack overflow in type inference when using large matrix-valued functions from Symbolics.build_function #990

Open
Krebbekx opened this issue Oct 6, 2023 · 1 comment

Comments

@Krebbekx
Copy link

Krebbekx commented Oct 6, 2023

When using Symbolics.build_function to generate a numerically usable Julia function from a symbolic function, the resulting function is very slow and raises a stack overflow error when calling it. The following example reproduces the error:

using Symbolics

N = 100  # for N=10, no error.

@variables xarray[1:N]

funexpr = xarray.^2  # example vector-valued function of length N

jacobianfun = eval(Symbolics.build_function(Symbolics.jacobian(funexpr, xarray), xarray)[1])  # build function from symbolic expression

xvalue = ones(N)

jacobianfun(xvalue)  # raises overflow error

generating the error

Internal error: stack overflow in type inference of #29(Array{Float64, 1}).
This might be caused by recursion over very long tuples or argument lists.

This limits the usage of symbolics to efficiently generate functions from symbolic expressions.

@Krebbekx
Copy link
Author

This does not solve the issue, but by using Symbolics.sparsejacobian, the problem does not occur.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants