From 7c8e97346951b9ad89d097ac931c2a48e60f9c2e Mon Sep 17 00:00:00 2001 From: Qingyu Qu <52615090+ErikQQY@users.noreply.github.com> Date: Mon, 11 Dec 2023 16:48:57 +0800 Subject: [PATCH 1/6] Fix forward and inverse application in FFTW tutorial --- docs/src/tutorials/fftw.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/docs/src/tutorials/fftw.md b/docs/src/tutorials/fftw.md index eb92bc8c..d8ce5864 100644 --- a/docs/src/tutorials/fftw.md +++ b/docs/src/tutorials/fftw.md @@ -23,6 +23,12 @@ k = rfftfreq(n, 2π*n/L) |> Array m = length(k) P = plan_rfft(x) +fwd(u, p, t) = P * u +bwd(u, p, t) = P \ u + +fwd(du, u, p, t) = mul!(du, P, u) +bwd(du, u, p, t) = ldiv!(du, P, u) + F = FunctionOperator(fwd, x, im*k; T=ComplexF64, @@ -82,6 +88,11 @@ pass the in-place forward application of the transform, `(du,u,p,t) -> ldiv!(du, transform, u)`, as well as input and output prototype vectors. ``` +fwd(u, p, t) = P * u +bwd(u, p, t) = P \ u + +fwd(du, u, p, t) = mul!(du, P, u) +bwd(du, u, p, t) = ldiv!(du, P, u) F = FunctionOperator(fwd, x, im*k; T=ComplexF64, From 6a7ea1200e6b7e966d08b866dc9b9b4c80998efe Mon Sep 17 00:00:00 2001 From: Qingyu Qu <52615090+ErikQQY@users.noreply.github.com> Date: Mon, 11 Dec 2023 19:25:59 +0800 Subject: [PATCH 2/6] Add example docs environment --- docs/src/tutorials/fftw.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/src/tutorials/fftw.md b/docs/src/tutorials/fftw.md index d8ce5864..5eeb50bf 100644 --- a/docs/src/tutorials/fftw.md +++ b/docs/src/tutorials/fftw.md @@ -7,7 +7,7 @@ derivative of a function. ## Copy-Paste Code -``` +```@example fft using SciMLOperators using LinearAlgebra, FFTW @@ -56,7 +56,7 @@ in the West), a common Fourier transform library. Next, we define an equispaced trivial example, we already know the derivative, `du`, and write it down to later test our FFT wrapper. -``` +```@example fft_explanation using SciMLOperators using LinearAlgebra, FFTW @@ -76,7 +76,7 @@ object that can be applied to inputs that are like `x` as follows: `xhat = trans and `LinearAlgebra.mul!(xhat, transform, x)`. We also get `k`, the frequency modes sampled by our finite grid, via the function `rfftfreq`. -``` +```@example fft_explanation k = rfftfreq(n, 2π*n/L) |> Array m = length(k) tr = plan_rfft(x) @@ -87,7 +87,7 @@ pass the in-place forward application of the transform, `(du,u,p,t) -> mul!(du, transform, u)`, its inverse application, `(du,u,p,t) -> ldiv!(du, transform, u)`, as well as input and output prototype vectors. -``` +```@example fft_explanation fwd(u, p, t) = P * u bwd(u, p, t) = P \ u @@ -109,7 +109,7 @@ SciMLOperators. Below, we form the derivative operator, and cache it via the fun `cache_operator` that requires an input prototype. We can test our derivative operator both in-place, and out-of-place by comparing its output to the analytical derivative. -``` +```@example fft_explanation ik = im * DiagonalOperator(k) Dx = F \ ik * F @@ -117,7 +117,7 @@ Dx = F \ ik * F @show ≈(mul!(copy(u), Dx, u), du; atol=1e-8) ``` -``` +```@example fft_explanation ≈(Dx * u, du; atol = 1.0e-8) = true ≈(mul!(copy(u), Dx, u), du; atol = 1.0e-8) = true ``` From 1f3d0cccc62181bdaf333a319be463c80c8e33c9 Mon Sep 17 00:00:00 2001 From: Qingyu Qu <52615090+ErikQQY@users.noreply.github.com> Date: Mon, 11 Dec 2023 19:34:08 +0800 Subject: [PATCH 3/6] Update Project.toml --- docs/Project.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/Project.toml b/docs/Project.toml index 704810b6..65284347 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -1,7 +1,9 @@ [deps] Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" +FFTW = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341" SciMLOperators = "c0aeaf25-5076-4817-a8d5-81caf7dfa961" [compat] Documenter = "0.27, 1" +FFTW = "1.7" SciMLOperators = "0.2, 0.3" From f6b0d9b138cd8a7558eb1524e04c2d7a9721228b Mon Sep 17 00:00:00 2001 From: Qingyu Qu <52615090+ErikQQY@users.noreply.github.com> Date: Mon, 11 Dec 2023 20:04:35 +0800 Subject: [PATCH 4/6] Update fftw.md --- docs/src/tutorials/fftw.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/tutorials/fftw.md b/docs/src/tutorials/fftw.md index 5eeb50bf..7d5465d2 100644 --- a/docs/src/tutorials/fftw.md +++ b/docs/src/tutorials/fftw.md @@ -79,7 +79,7 @@ our finite grid, via the function `rfftfreq`. ```@example fft_explanation k = rfftfreq(n, 2π*n/L) |> Array m = length(k) -tr = plan_rfft(x) +P = plan_rfft(x) ``` Now we are ready to define our wrapper for the FFT object. To `FunctionOperator`, we From 42e1130bc09732a6350897a9c65ee1cbbc5cdd5e Mon Sep 17 00:00:00 2001 From: Qingyu Qu <52615090+ErikQQY@users.noreply.github.com> Date: Mon, 11 Dec 2023 21:44:44 +0800 Subject: [PATCH 5/6] fix cache_operator in fft tutorials --- docs/src/tutorials/fftw.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/src/tutorials/fftw.md b/docs/src/tutorials/fftw.md index 7d5465d2..bdf3044e 100644 --- a/docs/src/tutorials/fftw.md +++ b/docs/src/tutorials/fftw.md @@ -113,6 +113,8 @@ both in-place, and out-of-place by comparing its output to the analytical deriva ik = im * DiagonalOperator(k) Dx = F \ ik * F +Dx = cache_operator(Dx, x) + @show ≈(Dx * u, du; atol=1e-8) @show ≈(mul!(copy(u), Dx, u), du; atol=1e-8) ``` From b03b0bebc30274a5b4e3f120fe830ede7fddfe75 Mon Sep 17 00:00:00 2001 From: Qingyu Qu <52615090+ErikQQY@users.noreply.github.com> Date: Mon, 11 Dec 2023 21:52:00 +0800 Subject: [PATCH 6/6] Update fftw.md --- docs/src/tutorials/fftw.md | 5 ----- 1 file changed, 5 deletions(-) diff --git a/docs/src/tutorials/fftw.md b/docs/src/tutorials/fftw.md index bdf3044e..69bb1499 100644 --- a/docs/src/tutorials/fftw.md +++ b/docs/src/tutorials/fftw.md @@ -118,8 +118,3 @@ Dx = cache_operator(Dx, x) @show ≈(Dx * u, du; atol=1e-8) @show ≈(mul!(copy(u), Dx, u), du; atol=1e-8) ``` - -```@example fft_explanation -≈(Dx * u, du; atol = 1.0e-8) = true -≈(mul!(copy(u), Dx, u), du; atol = 1.0e-8) = true -```