fix(optim): refuse non-finite bounds in differential evolution

Assisted-by: DeepSeek V4.1 Flash
This commit is contained in:
2026-09-28 14:07:46 +02:00
parent 3a44be625f
commit b2e69ff57b
3 changed files with 31 additions and 2 deletions
+6 -2
View File
@@ -58,8 +58,12 @@ func MinimiseDifferentialEvolution(f func(*core.Array) (float64, error),
return nil, 0, base.Errf("%s: complex bounds are not supported", name)
}
for i := range n {
if !(upper.FloatAt(i) > lower.FloatAt(i)) {
return nil, 0, base.Errf("%s: bound %d runs from %g to %g", name, i, lower.FloatAt(i), upper.FloatAt(i))
lo, up := lower.FloatAt(i), upper.FloatAt(i)
// An infinite side has no uniform draw: the population would be
// born NaN and the best point would come back NaN with no error,
// so a non-finite bound is degenerate exactly as a crossed one is.
if math.IsNaN(lo) || math.IsNaN(up) || math.IsInf(lo, 0) || math.IsInf(up, 0) || !(up > lo) {
return nil, 0, base.Errf("%s: bound %d runs from %g to %g", name, i, lo, up)
}
}
pop := opts.Population