Skip to content

Commit 228b855

Browse files
beautification and added tests
1 parent e05a515 commit 228b855

17 files changed

+182
-141
lines changed

src/convolutions.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export plan_conv_buffer, plan_conv_psf_buffer
33

44

55
"""
6-
conv(u, v[, dims])
6+
conv(u, v[, dims])
77
88
Convolve `u` with `v` over `dims` dimensions with an FFT based method.
99
Note, that this method introduces wrap-around artifacts without
@@ -66,7 +66,7 @@ function conv(u::AbstractArray{<:Real, N}, v::AbstractArray{<:Real, M}, dims=ntu
6666
end
6767

6868
"""
69-
conv_psf(u, psf[, dims])
69+
conv_psf(u, psf[, dims])
7070
7171
`conv_psf` is a shorthand for `conv(u,ifftshift(psf))`. For examples see `conv`.
7272
"""
@@ -89,7 +89,7 @@ end
8989

9090

9191
"""
92-
plan_conv(u, v [, dims]; kwargs...)
92+
plan_conv(u, v [, dims]; kwargs...)
9393
9494
Pre-plan an optimized convolution for arrays shaped like `u` and `v` (based on pre-plan FFT)
9595
along the given dimenions `dims`.
@@ -157,7 +157,7 @@ function plan_conv(u::AbstractArray{T1, N}, v::AbstractArray{T2, M}, dims=ntuple
157157
end
158158

159159
"""
160-
plan_conv_buffer(u, v [, dims]; kwargs...)
160+
plan_conv_buffer(u, v [, dims]; kwargs...)
161161
162162
Similar to [`plan_conv`](@ref) but instead uses buffers to prevent memory allocations.
163163
Not AD friendly!
@@ -194,7 +194,7 @@ function plan_conv_buffer(u::AbstractArray{T1, N}, v::AbstractArray{T2, M}, dims
194194
end
195195

196196
"""
197-
plan_conv_psf_buffer(u, psf [, dims]; kwargs...) where {T, N}
197+
plan_conv_psf_buffer(u, psf [, dims]; kwargs...) where {T, N}
198198
199199
`plan_conv_psf_buffer` is a shorthand for `plan_conv_buffer(u, ifftshift(psf))`. For examples see `plan_conv`.
200200
"""
@@ -230,7 +230,7 @@ function ChainRulesCore.rrule(::typeof(p_conv_aux), P, P_inv, u, v)
230230
end
231231

232232
"""
233-
fft_or_rfft(T)
233+
fft_or_rfft(T)
234234
235235
Small helper function to decide whether a real
236236
or a complex valued FFT is appropriate.

src/correlations.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
export ccorr
22

3-
43
"""
5-
ccorr(u, v[, dims]; centered=false)
4+
ccorr(u, v[, dims]; centered=false)
65
76
Calculates the cross-correlation between `u` and `v` along `dims`.
87
`centered=true` moves the output of the cross-correlation to the Fourier center.
@@ -13,7 +12,6 @@ If either `u` or `v` is complex we use `fft` and output is hence complex.
1312
1413
Per default the correlation is performed along `min(ndims(u), ndims(v))`.
1514
16-
1715
```jldoctest
1816
julia> ccorr([1,1,0,0], [1,1,0,0], centered=true)
1917
4-element Vector{Float64}:

src/custom_fourier_types.jl

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
1-
## This View checks for the index to be L1 or the mirrored version (L2)
2-
# and then replaces the value by half of the parent at L1
3-
# do_split is a Bool that indicates whether this mechanism is active. It is needed for type stability reasons of functions returnting this type
1+
"""
2+
FourierSplit{T,N, AA<:AbstractArray{T, N}} <: AbstractArray{T,N}
3+
4+
This View checks for the index to be L1 or the mirrored version (L2)
5+
and then replaces the value by half of the parent at L1
6+
`do_split` is a Bool that indicates whether this mechanism is active.
7+
It is needed for type stability reasons of functions returnting this type.
8+
"""
49
struct FourierSplit{T,N, AA<:AbstractArray{T, N}} <: AbstractArray{T,N}
510
parent::AA # holds the data (or is another view)
611
D::Int # dimension along which to apply to copy
712
L1::Int # low index position to copy from (and half)
813
L2::Int # high index positon to copy to (and half)
914
do_split::Bool
1015

11-
# This version below is needed to avoid a split for the firs rft dimension but still return half the value
12-
# FFTs and other RFT dimension should use the version without L2
16+
"""
17+
FourierSplit(parent::AA, D::Int,L1::Int,L2::Int, do_split::Bool) where {T,N, AA<:AbstractArray{T, N}}
18+
19+
This version below is needed to avoid a split for the first rft dimension,
20+
but still return half the value FFTs and other RFT dimension should use the version without L2.
21+
"""
1322
function FourierSplit(parent::AA, D::Int,L1::Int,L2::Int, do_split::Bool) where {T,N, AA<:AbstractArray{T, N}}
1423
return new{T,N, AA}(parent, D, L1, L2, do_split)
1524
end
@@ -36,18 +45,26 @@ Base.size(A::FourierSplit) = size(parent(A))
3645
end
3746
end
3847

39-
## This View checks for the index to be L1
40-
# and then replaces the value by add the value at the mirrored position L2
41-
# do_join is a Bool that indicates whether this mechanism is active. It is needed for type stability reasons of functions returnting this type
48+
"""
49+
FourierJoin{T,N, AA<:AbstractArray{T, N}} <: AbstractArray{T, N}
50+
51+
This View checks for the index to be L1
52+
and then replaces the value by add the value at the mirrored position L2
53+
`do_join` is a Bool that indicates whether this mechanism is active.
54+
It is needed for type stability reasons of functions returnting this type
55+
"""
4256
struct FourierJoin{T,N, AA<:AbstractArray{T, N}} <: AbstractArray{T, N}
4357
parent::AA
4458
D::Int # dimension along which to apply to copy
4559
L1::Int # low index position to copy from (and half)
4660
L2::Int # high index positon to copy to (and half)
4761
do_join::Bool
4862

49-
# This version below is needed to avoid a split for the firs rft dimension but still return half the value
50-
# FFTs and other RFT dimension should use the version without L2
63+
"""
64+
This version below is needed to avoid a split for the
65+
first rft dimension but still return half the value
66+
FFTs and other RFT dimension should use the version without L2
67+
"""
5168
function FourierJoin(parent::AA, D::Int, L1::Int, L2::Int, do_join::Bool) where {T, N, AA<:AbstractArray{T, N}}
5269
return new{T, N, AA}(parent, D, L1, L2, do_join)
5370
end
@@ -58,6 +75,7 @@ struct FourierJoin{T,N, AA<:AbstractArray{T, N}} <: AbstractArray{T, N}
5875
return FourierJoin(parent, D, L1, L2, do_join)
5976
end
6077
end
78+
6179
Base.IndexStyle(::Type{FS}) where {FS<:FourierJoin} = IndexStyle(parenttype(FS))
6280
parenttype(::Type{FourierJoin{T,N,AA}}) where {T,N,AA} = AA
6381
parenttype(A::FourierJoin) = parenttype(typeof(A))

src/czt.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export czt, iczt
22

33
"""
4-
czt_1d(xin , scaled , d)
4+
czt_1d(xin , scaled , d)
55
66
Chirp z transform along a single direction d of an ND array `xin` into the ND array 'xout'.
77
Note that xin and xout can be the same array for inplace operations.
@@ -77,7 +77,8 @@ function czt_1d(xin, scaled, d)
7777
end
7878

7979
"""
80-
czt(xin , scale, dims=1:length(size(xin)))
80+
czt(xin , scale, dims=1:length(size(xin)))
81+
8182
Chirp z transform of the ND array `xin`
8283
This code is based on a 2D Matlab version of the CZT, written by H. Gross.
8384
The tuple `scale` defines the zoom factors in the Fourier domain. Each has to be bigger than one.
@@ -135,7 +136,8 @@ function czt(xin::Array{T,N}, scale, dims=1:length(size(xin)))::Array{complex(T)
135136
end
136137

137138
"""
138-
iczt(xin , scale, dims=1:length(size(xin)))
139+
iczt(xin , scale, dims=1:length(size(xin)))
140+
139141
Inverse chirp z transform of the ND array `xin`
140142
This code is based on a 2D Matlab version of the CZT, written by H. Gross.
141143
The tuple `scale` defines the zoom factors in the Fourier domain. Each has to be bigger than one.

src/damping.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ using IndexFunArrays, LinearAlgebra, NDTools
22
export damp_edge_outside
33

44
"""
5-
damp_edge_outside(img::AbstractArray{T,N}, border, mykernel, usepixels)
5+
damp_edge_outside(img::AbstractArray{T,N}, border, mykernel, usepixels)
66
77
Extrapolates the data by filling in blurred information outside the edges. This is a bit like DampEdge but using a normalized convolution with a kernel
88

src/fft_helpers.jl

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export ft2d,ift2d, rft2d, irft2d
55
export ffts2d, ffts2d!, iffts2d, rffts2d, irffts2d
66

77
"""
8-
optional_collect(a)
8+
optional_collect(a)
99
1010
Only collects certain arrays, for a pure `Array` there is no collect
1111
and it returns simply `a`.
@@ -27,7 +27,7 @@ end
2727

2828

2929
"""
30-
ffts(A [, dims])
30+
ffts(A [, dims])
3131
3232
Result is semantically equivalent to `fftshift(fft(A, dims), dims)`
3333
However, the shift is done with `ShiftedArrays` and therefore doesn't allocate memory.
@@ -41,7 +41,7 @@ end
4141

4242

4343
"""
44-
ffts!(A [, dims])
44+
ffts!(A [, dims])
4545
4646
Result is semantically equivalent to `fftshift(fft!(A, dims), dims)`.
4747
`A` is in-place modified.
@@ -55,7 +55,7 @@ function ffts!(mat::AbstractArray{T, N}, dims=ntuple(identity, Val(N))) where {T
5555
end
5656

5757
"""
58-
iffts(A [, dims])
58+
iffts(A [, dims])
5959
6060
Result is semantically equivalent to `ifft(ifftshift(A, dims), dims)`.
6161
`A` is in-place modified.
@@ -70,7 +70,7 @@ end
7070

7171

7272
"""
73-
rffts(A [, dims])
73+
rffts(A [, dims])
7474
7575
Calculates a `rfft(A, dims)` and then shift the frequencies to the center.
7676
`dims[1]` is not shifted, because there is no negative and positive frequency.
@@ -84,7 +84,7 @@ function rffts(mat::AbstractArray{T, N}, dims=ntuple(identity, Val(N))) where {T
8484
end
8585

8686
"""
87-
irffts(A, d, [, dims])
87+
irffts(A, d, [, dims])
8888
8989
Calculates a `irfft(A, d, dims)` and then shift the frequencies back to the corner.
9090
`dims[1]` is not shifted, because there is no negative and positive frequency.
@@ -100,7 +100,7 @@ end
100100

101101

102102
"""
103-
ft(A [, dims])
103+
ft(A [, dims])
104104
105105
Digital Fourier-transformation centered in both spaces.
106106
The result is semantically equivalent to `fftshift(fft(ifftshift(A, dims), dims), dims)`
@@ -129,7 +129,7 @@ end
129129

130130

131131
"""
132-
ift(A [, dims])
132+
ift(A [, dims])
133133
134134
Digital inverse Fourier-transformation centered in both spaces.
135135
The result is semantically equivalent to `fftshift(ifft(ifftshift(A, dims), dims), dims)`
@@ -160,7 +160,7 @@ end
160160

161161

162162
"""
163-
rft(A [, dims])
163+
rft(A [, dims])
164164
165165
Digital real-valued Fourier-transformation centered in both spaces.
166166
The result is semantically equivalent to `fftshift(rfft(ifftshift(A, dims), dims), dims)`
@@ -185,7 +185,7 @@ function rft(mat::AbstractArray{T, N}, dims=ntuple(identity, Val(N))) where {T,
185185
end
186186

187187
"""
188-
irft(A, d, [, dims])
188+
irft(A, d, [, dims])
189189
190190
Digital real-valued inverse Fourier-transformation centered in both spaces.
191191
The result is semantically equivalent to `fftshift(irfft(ifftshift(A, dims), dims), dims)`
@@ -212,23 +212,23 @@ end
212212

213213
## Short-hand versions of the ft functions
214214
"""
215-
ft2d(mat::AbstractArray{T, N}) where {T, N}
215+
ft2d(mat::AbstractArray{T, N}) where {T, N}
216216
217217
Only over `dims=(1,2)`.
218218
"""
219219
function ft2d(mat::AbstractArray{T, N}) where {T, N}
220220
ft(mat,(1,2))
221221
end
222222
"""
223-
ift2d(mat::AbstractArray{T, N}) where {T, N}
223+
ift2d(mat::AbstractArray{T, N}) where {T, N}
224224
225225
Only over `dims=(1,2)`.
226226
"""
227227
function ift2d(mat::AbstractArray{T, N}) where {T, N}
228228
ift(mat,(1,2))
229229
end
230230
"""
231-
rft2d(mat::AbstractArray{T, N}) where {T, N}
231+
rft2d(mat::AbstractArray{T, N}) where {T, N}
232232
233233
Only over `dims=(1,2)`.
234234
"""
@@ -237,7 +237,7 @@ function rft2d(mat::AbstractArray{T, N}) where {T, N}
237237
end
238238

239239
"""
240-
irft2d(mat::AbstractArray{T, N}, d) where {T, N}
240+
irft2d(mat::AbstractArray{T, N}, d) where {T, N}
241241
242242
Only over `dims=(1,2)`.
243243
"""
@@ -246,7 +246,7 @@ function irft2d(mat::AbstractArray{T, N}, d::Int) where {T, N}
246246
end
247247

248248
"""
249-
ft2d(mat::AbstractArray{T, N}) where {T, N}
249+
ft2d(mat::AbstractArray{T, N}) where {T, N}
250250
251251
Only over `dims=(1,2)`.
252252
"""
@@ -255,7 +255,7 @@ function ffts2d(mat::AbstractArray{T, N}) where {T, N}
255255
end
256256

257257
"""
258-
fft2ds!(mat::AbstractArray{T, N}) where {T, N}
258+
fft2ds!(mat::AbstractArray{T, N}) where {T, N}
259259
260260
Only over `dims=(1,2)`.
261261
"""
@@ -265,7 +265,7 @@ end
265265

266266

267267
"""
268-
iffts2d(mat::AbstractArray{T, N}) where {T, N}
268+
iffts2d(mat::AbstractArray{T, N}) where {T, N}
269269
270270
Only over `dims=(1,2)`.
271271
"""
@@ -282,7 +282,7 @@ function rffts2d(mat::AbstractArray{T, N}) where {T, N}
282282
end
283283

284284
"""
285-
riffts2d(mat::AbstractArray{T, N}, d) where {T, N}
285+
riffts2d(mat::AbstractArray{T, N}, d) where {T, N}
286286
287287
Only over `dims=(1,2)`.
288288
"""
@@ -293,15 +293,15 @@ end
293293

294294
## Short-hand versions of the fft functions
295295
"""
296-
fft2d(mat::AbstractArray{T, N}) where {T, N}
296+
fft2d(mat::AbstractArray{T, N}) where {T, N}
297297
298298
Only over `dims=(1,2)`.
299299
"""
300300
function fft2d(mat::AbstractArray{T, N}) where {T, N}
301301
fft(mat,(1,2))
302302
end
303303
"""
304-
ifft2d(mat::AbstractArray{T, N}) where {T, N}
304+
ifft2d(mat::AbstractArray{T, N}) where {T, N}
305305
306306
Only over `dims=(1,2)`.
307307
"""
@@ -310,7 +310,7 @@ function ifft2d(mat::AbstractArray{T, N}) where {T, N}
310310
end
311311

312312
"""
313-
rfft2d(mat::AbstractArray{T, N}) where {T, N}
313+
rfft2d(mat::AbstractArray{T, N}) where {T, N}
314314
315315
Only over `dims=(1,2)`.
316316
"""
@@ -319,7 +319,7 @@ function rfft2d(mat::AbstractArray{T, N}) where {T, N}
319319
end
320320

321321
"""
322-
irfft2d(mat::AbstractArray{T, N}, d) where {T, N}
322+
irfft2d(mat::AbstractArray{T, N}, d) where {T, N}
323323
324324
Only over `dims=(1,2)`.
325325
"""

0 commit comments

Comments
 (0)