-
Notifications
You must be signed in to change notification settings - Fork 154
Open
Labels
Description
The DiffResults documentation clearly states that whenever a DiffResult object is used, it must be realiased at the end of the function call:
result = do_stuff!(result, args...)See for instance the docstrings in https://juliadiff.org/DiffResults.jl/stable/#Mutating-a-DiffResult, or the issue DiffResults#17
This is not done by ForwardDiff, for instance here:
ForwardDiff.jl/src/gradient.jl
Lines 35 to 44 in 42b1554
| function gradient!(result::Union{AbstractArray,DiffResult}, f::F, x::AbstractArray, cfg::GradientConfig{T} = GradientConfig(f, x), ::Val{CHK}=Val{true}()) where {T, CHK, F} | |
| result isa DiffResult ? require_one_based_indexing(x) : require_one_based_indexing(result, x) | |
| CHK && checktag(T, f, x) | |
| if chunksize(cfg) == length(x) | |
| vector_mode_gradient!(result, f, x, cfg) | |
| else | |
| chunk_mode_gradient!(result, f, x, cfg) | |
| end | |
| return result | |
| end |
Am I right in deducing that it can lead to incorrectness?