mirror of
https://github.com/gonum/gonum.git
synced 2025-10-05 23:26:52 +08:00
optimize/functions: fix ExtendedRosenbrock for BFGS test
With the fused operation, grad diverges, resulting in a non-progression of the location.
This commit is contained in:
@@ -789,12 +789,13 @@ func (ExtendedRosenbrock) Grad(grad, x []float64) {
|
||||
for i := range grad {
|
||||
grad[i] = 0
|
||||
}
|
||||
// Prevent fused multiply add and fused multiply subtract.
|
||||
for i := 0; i < dim-1; i++ {
|
||||
grad[i] -= 2 * (1 - x[i])
|
||||
grad[i] -= 400 * (x[i+1] - x[i]*x[i]) * x[i]
|
||||
grad[i] -= float64(2 * (1 - x[i]))
|
||||
grad[i] -= float64(400 * (x[i+1] - float64(x[i]*x[i])) * x[i])
|
||||
}
|
||||
for i := 1; i < dim; i++ {
|
||||
grad[i] += 200 * (x[i] - x[i-1]*x[i-1])
|
||||
grad[i] += float64(200 * (x[i] - float64(x[i-1]*x[i-1])))
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user