Problem
ifelse(tracer_condition, constant1, constant2) fails when both branches are constants (not tracers), because output_union(::Float64, ::Float64) is not defined.
MWE
using SparseConnectivityTracer
detector = TracerSparsityDetector()
# This fails - both branches are constants
f(x) = [ifelse(x[1] > 0, 1.0, 0.0) * x[2]]
jacobian_sparsity(f, [1.0, 2.0], detector)
# MethodError: no method matching output_union(::Float64, ::Float64)
# This works - at least one branch is a tracer
g(x) = [ifelse(x[1] > 0, x[1], x[2])]
jacobian_sparsity(g, [1.0, 2.0], detector)
# OK: nnz=2
Expected behavior
When both branches are constants, ifelse should return a constant (zero sparsity pattern), not error.
Fix
Add method in src/overloads/ifelse_global.jl:
output_union(x::Real, y::Real) = x # or some neutral value, since no tracers
Problem
ifelse(tracer_condition, constant1, constant2)fails when both branches are constants (not tracers), becauseoutput_union(::Float64, ::Float64)is not defined.MWE
Expected behavior
When both branches are constants,
ifelseshould return a constant (zero sparsity pattern), not error.Fix
Add method in
src/overloads/ifelse_global.jl: