JuliaApproximation / FastTransformsForwardDiff.jl

A Julia package to support forward-mode auto-differentiation for fast transforms
MIT License
13 stars 0 forks source link

Allow using existing plans #4

Open marius311 opened 1 year ago

marius311 commented 1 year ago

Great package, thanks, have been doing something similar recently. One thing which would be great to have here is to allow using existing non-Dual plans on Dual arrays. Sometimes you have a calculation with precomputed plans, then you later want to compute derivatives, e.g.

plan = plan_fft(Array{Float64}(undef, 10))
x = rand(10)
foo = A -> norm(plan * (A * x))
ForwardDiff.derivative(foo, 1) # ArgumentError: FFTW plan applied to wrong-size array

Should be possible to use the existing plan and manually loop over slices of the dual2array array (may need a copy, not sure if memory needs to be contiguous there, probably yes). This is probably less efficient than the single "batched" plan approach you have here when planning with Duals, but will allow this to work at least.

dlfivefifty commented 1 year ago

A previous version of the code (https://github.com/JuliaDiff/ForwardDiff.jl/pull/541) did something like this ... will accept a PR that brings it back

Note the code I wrote also does copies since FFTW doesn't recognise that a reshaped array is a strided

srivatsabprasad commented 1 month ago

Hi, could someone provide a working example of how to generate an FFTW plan with FastTransformsForwardDiff.jl that would allow me to do the example in the README or otherwise the problem in https://github.com/JuliaApproximation/FastTransformsForwardDiff.jl/issues/4#issue-1503699728? Without documentation for this package I am struggling to understand how to use it.