matthieugomez / LeastSquaresOptim.jl

Dense and Sparse Least Squares Optimization
Other
53 stars 16 forks source link

Can't create LeastSquaresProblem: UndefVarError: f not defined #22

Closed hronellenfitsch closed 4 years ago

hronellenfitsch commented 4 years ago

The following code fails:

using LeastSquaresOptim
function f!(fvec, x)
    fvec[1] = 1 - x[1]
    fvec[2] = 10(x[2]-x[1]^2)
end
function g!(fjac, x)
    fjac[1,1] = -1
    fjac[1,2] = 0
    fjac[2,1] = -20x[1]
    fjac[2,2] = 10
end
x = [-1.2; 1.]
J = zeros(2, 2)
y = similar(x)
LeastSquaresProblem(x=x, y=y, f!=f!, g!=g!, J=J)

With the error message UndefVarError: f not defined.

This is especially strange since it is copied straight from the tests, and test LeastSquaresOptim runs through successfully.

matthieugomez commented 4 years ago

The issue is that f!=f! is interpreted as f != f!, rather than f! = f!. Maybe I should change the keyword argument to avoid this kind of ambiguity.

hronellenfitsch commented 4 years ago

Thanks, that works.