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

LoadError: MethodError: no method matching _sparse(::SymbolicUtils.BasicSymbolic{Any}, ::Int64) #893

Open
tmigot opened this issue May 1, 2023 · 3 comments

Comments

@tmigot
Copy link
Contributor

tmigot commented May 1, 2023

I tried the following code:

using Symbolics, IfElse

f(x) = Base.ifelse( # IfElse.ifelse doesn't work either
    x[1] <= 0,
    -x[1],
    x[1],
)
x0 = ones(1)
nvar = 1

@variables xs[1:nvar]
xsi = Symbolics.scalarize(xs)
fun = f(xsi)
S = Symbolics.hessian_sparsity(fun, xsi)

and got the following error

ERROR: LoadError: MethodError: no method matching _sparse(::SymbolicUtils.BasicSymbolic{Any}, ::Int64)
Closest candidates are:
  _sparse(::Number, ::Any) at .julia\packages\Symbolics\gy00O\src\linearity.jl:170
  _sparse(::Symbolics.TermCombination, ::Any) at .julia\packages\Symbolics\gy00O\src\linearity.jl:147
Stacktrace:
 [1] hessian_sparsity(expr::Num, vars::Vector{Num}; full::Bool)
   @ Symbolics .julia\packages\Symbolics\gy00O\src\diff.jl:679
 [2] hessian_sparsity(expr::Num, vars::Vector{Num})
   @ Symbolics .julia\packages\Symbolics\gy00O\src\diff.jl:671

It might be related to #888 .

@aravindh-krishnamoorthy
Copy link

Sorry, but it's unclear to me what are you trying to achieve here? Isn't ifelse(x <= 0, -x, x) just abs(x), which is non-differentiable?

@tmigot
Copy link
Contributor Author

tmigot commented May 5, 2023

@aravindh-krishnamoorthy you are right, let me reformulate the example. The error is the same if the function is differentiable as follows:

using Symbolics

f(x) = Base.ifelse(
    x[1] <= 0,
    -x[1]^2,
    x[1]^2,
)
x0 = ones(1)
nvar = 1

@variables xs[1:nvar]
xsi = Symbolics.scalarize(xs)
fun = f(xsi)
S = Symbolics.hessian_sparsity(fun, xsi)

@ChrisRackauckas
Copy link
Member

@shashi do you know what's going on in this one?

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

No branches or pull requests

3 participants