Skip to content

Commit ef163d1

Browse files
committed
rm Base.* wrapper for non OOp FunctionOperator
1 parent f169b36 commit ef163d1

File tree

2 files changed

+38
-33
lines changed

2 files changed

+38
-33
lines changed

docs/src/tutorials/fftw.md

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,22 @@ x = range(start=-L/2, stop=L/2-dx, length=n) |> Array
1919
u = @. sin(5x)cos(7x);
2020
du = @. 5cos(5x)cos(7x) - 7sin(5x)sin(7x);
2121
22-
k = rfftfreq(n, 2π*n/L) |> Array
23-
m = length(k)
24-
transform = plan_rfft(x)
22+
k = rfftfreq(n, 2π*n/L) |> Array
23+
m = length(k)
24+
P = plan_rfft(x)
25+
26+
F = FunctionOperator(fwd, x, im*k;
27+
T=ComplexF64,
2528
26-
T = FunctionOperator((du,u,p,t) -> mul!(du, transform, u), x, im*k;
27-
isinplace=true,
28-
T=ComplexF64,
29+
op_adjoint = bwd,
30+
op_inverse = bwd,
31+
op_adjoint_inverse = fwd,
2932
30-
op_adjoint = (du,u,p,t) -> ldiv!(du, transform, u),
31-
op_inverse = (du,u,p,t) -> ldiv!(du, transform, u),
32-
op_adjoint_inverse = (du,u,p,t) -> ldiv!(du, transform, u),
33-
)
33+
islinear=true,
34+
)
3435
3536
ik = im * DiagonalOperator(k)
36-
Dx = T \ ik * T
37+
Dx = F \ ik * F
3738
3839
Dx = cache_operator(Dx, x)
3940
@@ -79,18 +80,17 @@ Now we are ready to define our wrapper for the FFT object. To `FunctionOperator`
7980
pass the in-place forward application of the transform,
8081
`(du,u,p,t) -> mul!(du, transform, u)`, its inverse application,
8182
`(du,u,p,t) -> ldiv!(du, transform, u)`, as well as input and output prototype vectors.
82-
We also set the flag `isinplace` to `true` to signal that we intend to use the operator
83-
in a non-allocating way, and pass in the element-type and size of the operator.
8483

8584
```
86-
T = FunctionOperator((du,u,p,t) -> mul!(du, transform, u), x, im*k;
87-
isinplace=true,
88-
T=ComplexF64,
89-
90-
op_adjoint = (du,u,p,t) -> ldiv!(du, transform, u),
91-
op_inverse = (du,u,p,t) -> ldiv!(du, transform, u),
92-
op_adjoint_inverse = (du,u,p,t) -> ldiv!(du, transform, u),
93-
)
85+
F = FunctionOperator(fwd, x, im*k;
86+
T=ComplexF64,
87+
88+
op_adjoint = bwd,
89+
op_inverse = bwd,
90+
op_adjoint_inverse = fwd,
91+
92+
islinear=true,
93+
)
9494
```
9595

9696
After wrapping the FFT with `FunctionOperator`, we are ready to compose it with other
@@ -100,7 +100,7 @@ both in-place, and out-of-place by comparing its output to the analytical deriva
100100

101101
```
102102
ik = im * DiagonalOperator(k)
103-
Dx = T \ ik * T
103+
Dx = F \ ik * F
104104
105105
@show ≈(Dx * u, du; atol=1e-8)
106106
@show ≈(mul!(copy(u), Dx, u), du; atol=1e-8)

test/total.jl

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,25 @@ K = 12
1616
dx = L / n
1717
x = -L/2:dx:L/2-dx |> Array
1818

19-
k = rfftfreq(n, 2π*n/L) |> Array
20-
m = length(k)
21-
tr = plan_rfft(x)
19+
k = rfftfreq(n, 2π*n/L) |> Array
20+
m = length(k)
21+
P = plan_rfft(x)
2222

23-
ftr = FunctionOperator((du,u,p,t) -> mul!(du, tr, u), x, im*k;
24-
isinplace=true,
25-
T=ComplexF64,
23+
fwd(u, p, t) = P * u
24+
bwd(u, p, t) = P \ u
2625

27-
op_adjoint = (du,u,p,t) -> ldiv!(du, tr, u),
28-
op_inverse = (du,u,p,t) -> ldiv!(du, tr, u),
29-
op_adjoint_inverse = (du,u,p,t) -> ldiv!(du, tr, u),
26+
fwd(du, u, p, t) = mul!(du, P, u)
27+
bwd(du, u, p, t) = ldiv!(du, P, u)
3028

31-
islinear=true,
32-
)
29+
ftr = FunctionOperator(fwd, x, im*k;
30+
T=ComplexF64,
31+
32+
op_adjoint = bwd,
33+
op_inverse = bwd,
34+
op_adjoint_inverse = fwd,
35+
36+
islinear=true,
37+
)
3338

3439
@test size(ftr) == (length(k), length(x))
3540

0 commit comments

Comments
 (0)