JuliaSmoothOptimizers / JuliaSmoothOptimizers/ADNLPModels.jl

Document use of conditionals for sparsity detection

Open
#283 2 comments 2 reactions 0 assignees View on GitHub
documentation
Dominant language
Julia
Stars
44
Forks
19
PR merge metrics
No merged PRs in 30d

Description

With the new `TracerSparsityDetector` from SparseConnectivityTracer, `if` blocks are not supported if they involve an input variable. They must be replaced with `ifelse` statements, which are compatible with operator overloading.

In your objective functions or constraints, do not write

```julia
y = if x[1] > 0
x[2]
else
x[3]
end
```

but instead write

```julia
y = ifelse(x[1] > 0, x[2], x[3])
```

Related:

- https://github.com/JuliaSmoothOptimizers/ADNLPModels.jl/issues/247#issuecomment-2207029473

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.