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: