ITADN

Repeted evaluation of `fx0` when computing forward differences for gradients

#202Openjunyuan-chen 创建于 2025-08-15
J
junyuan-chencommented
For `f` that maps a vector of length `N` to a scalar, I am expecting `f` to be evaluated for only `N+1` times with `fdtype == Val(:forward)`. What actually happens is that the same `fx0 = f(x)` is evaluated for `N` times as iterating across all elements of the input vector. Hence, `f` is called `2N` times! See the line below that should be pulled out of the loop: https://github.com/JuliaDiff/FiniteDiff.jl/blob/83ff37e01afd56c61703a870581c095b5a2e5c4c/src/gradients.jl#L383
0 条评论