-
Notifications
You must be signed in to change notification settings - Fork 9
Description
Currently, the package does two things:
-
support an interface for retrieving values with derivatives; as the former are calculated anyway
-
allow preallocated buffers for results.
In my own benchmarks, I find the allocation cost dwarfed by the actual calculations. It can also lead to bugs, eg if the MutableDiffResult
is accidentally reused. With the introduction of StaticArrays
(JuliaAttic/DiffBase.jl@1f15e9c) the interface became even more complicated, because they don't share structure, yet use an interface which pretends to modify its arguments.
Also, the relevant subtype of DiffResult
is determined by the input type. It is conceivable that a function could take a StaticVector
yet return a Vector
.
Perhaps it would be better to use an interface which just takes an abstract type which tells a single evaluator function (eg in ForwardDiff.jl
) what the user wants calculated, and returns that, eg
resulttype = DiffResult(; value = true, jacobian = true) # type information saves these
value_and_deriv = ForwardDiff.evaluate(resulttype, f, x) # result based in 1st argument
I came across this when writing a simple wrapper that just takes a function, and returns a function which returns value & derivative (short source here), and found it very complicated to support everything.