JuliaNLSolvers / NLsolve.jl

Julia solvers for systems of nonlinear equations and mixed complementarity problems
Other
325 stars 66 forks source link

Detection of `inplace` for fixed point #191

Closed jlperla closed 5 years ago

jlperla commented 5 years ago

@pkofod and @arnavs

I am finding that the code using the fixedpoint and solve functions look uglier than they need to be when using inplace = false all over the place.

I think this could have an almost trivial change: For the following:

and if you want to do it for the nlsolve interface:

CHange inplace = true to something like

inplace = !applicable(f, initial_x)

that is, check if it can be called with just the initial condition... if so, then we can use inplace = false

Of course, there is a small chance that there is a method for both f(out, x) and f(x) for the same function (at which point this would choose the f(x) one by default)... but I doubt that would happen in practice. People are very careful to use the ! for modifying functions, so it is pretty rare to have both.

jlperla commented 5 years ago

My guess is that checking that the typeof(f) <: Union{InplaceObjective, NotInplaceObjective} might also be important for the nlsolve case.. But if we only do this for fixedpoint that would be fine with me.

pkofod commented 5 years ago

Is applicable a Base function?

jlperla commented 5 years ago

Yeah

pkofod commented 5 years ago

TIL

arnavs commented 5 years ago

Opened https://github.com/JuliaNLSolvers/NLsolve.jl/pull/192 to incorporate this change (only for fixedpoint() for now). Also, it turns out it's actually just Base.applicable

arnavs commented 5 years ago

Closing because the PR #192 has been merged.