From ed8444cc197a7ddbc27884e10af9b17b779da376 Mon Sep 17 00:00:00 2001 From: Oscar Dowson Date: Sat, 29 Jun 2019 12:41:36 -0500 Subject: [PATCH] Improve NLP documentation about ForwardDiff (#2000) --- docs/src/nlp.md | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/docs/src/nlp.md b/docs/src/nlp.md index 8ad9ec73f9a..59d574406ba 100644 --- a/docs/src/nlp.md +++ b/docs/src/nlp.md @@ -193,9 +193,21 @@ JuMP uses [ForwardDiff.jl](https://github.com/JuliaDiff/ForwardDiff.jl) to perform automatic differentiation; see the ForwardDiff.jl [documentation](http://www.juliadiff.org/ForwardDiff.jl/v0.10.2/user/limitations.html) for a description of how to write a function suitable for automatic -differentiation. The general guideline is to write code that is generic with -respect to the number type; don't assume that the input to the function is -`Float64`. To register a user-defined function with derivatives computed by +differentiation. + +!!! note + If you see method errors with `ForwardDiff.Duals`, see the guidelines at + [ForwardDiff.jl](http://www.juliadiff.org/ForwardDiff.jl/release-0.10/user/limitations.html). + The most common error is that your user-defined function is not generic with + respect to the number type, i.e., don't assume that the input to the function + is `Float64`. + ```julia + f(x::Float64) = 2 * x # This will not work. + f(x::Real) = 2 * x # This is good. + f(x) = 2 * x # This is also good. + ``` + +To register a user-defined function with derivatives computed by automatic differentiation, use the `register` method as in the following example: