Skip to content

Commit 774bed8

Browse files
committed
Add NonuniformFFTs package extension for toeplitz operator
1 parent df14317 commit 774bed8

File tree

4 files changed

+58
-8
lines changed

4 files changed

+58
-8
lines changed

Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ AbstractNFFTs = "7f219486-4aa7-41d6-80a7-e08ef20ceed7"
3939
GPUArrays = "0c68f7d7-f131-5f86-a1c3-88cf8149b2d7"
4040
KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c"
4141
NFFT = "efe261a4-0d2b-5849-be55-fc731d526b0d"
42+
NonuniformFFTs = "cd96f58b-6017-4a02-bb9e-f4d81626177f"
4243
Wavelets = "29a6e085-ba6d-5f35-a997-948ac2efa89a"
4344
FFTW = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341"
4445
RadonKA = "86de8297-835b-47df-b249-c04e8db91db5"
@@ -48,6 +49,7 @@ test = ["Test", "FFTW", "Wavelets", "NFFT", "NonuniformFFTs", "JLArrays", "Radon
4849

4950
[extensions]
5051
LinearOperatorNFFTExt = ["AbstractNFFTs", "FFTW"]
52+
LinearOperatorNonuniformFFTsExt = ["AbstractNFFTs", "NonuniformFFTs", "FFTW"]
5153
LinearOperatorFFTWExt = "FFTW"
5254
LinearOperatorWaveletExt = "Wavelets"
5355
LinearOperatorGPUArraysExt = "GPUArrays"

ext/LinearOperatorNFFTExt/NFFTOp.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function LinearOperatorCollection.NFFTOp(::Type{T};
1919
return NFFTOpImpl(shape, nodes; toeplitz, oversamplingFactor, kernelSize, kargs... )
2020
end
2121

22-
mutable struct NFFTOpImpl{T, vecT, P <: AbstractNFFTPlan} <: NFFTOp{T}
22+
mutable struct NFFTOpImpl{T, vecT, P} <: NFFTOp{T, P}
2323
nrow :: Int
2424
ncol :: Int
2525
symmetric :: Bool
@@ -107,7 +107,7 @@ end
107107

108108
LinearOperators.storage_type(op::NFFTToeplitzNormalOp) = typeof(op.Mv5)
109109

110-
function NFFTToeplitzNormalOp(shape, W, fftplan, ifftplan, λ, xL1::matT, xL2::matT) where {T, D, matT <: AbstractArray{T, D}}
110+
function LinearOperatorCollection.NFFTToeplitzNormalOp(shape, W, fftplan, ifftplan, λ, xL1::matT, xL2::matT) where {T, D, matT <: AbstractArray{T, D}}
111111

112112
function produ!(y, shape, fftplan, ifftplan, λ, xL1, xL2, x)
113113
xL1 .= 0
@@ -130,7 +130,7 @@ function NFFTToeplitzNormalOp(shape, W, fftplan, ifftplan, λ, xL1::matT, xL2::m
130130
, shape, W, fftplan, ifftplan, λ, xL1, xL2)
131131
end
132132

133-
function NFFTToeplitzNormalOp(nfft::NFFTOp{T}, W=nothing; kwargs...) where {T}
133+
function LinearOperatorCollection.NFFTToeplitzNormalOp(nfft::NFFTOp{T}, W=nothing; kwargs...) where {T}
134134
shape = size_in(nfft.plan)
135135

136136
tmpVec = similar(nfft.Mv5, (2 .* shape)...)
@@ -161,12 +161,12 @@ function NFFTToeplitzNormalOp(nfft::NFFTOp{T}, W=nothing; kwargs...) where {T}
161161
xL1 = tmpVec
162162
xL2 = similar(xL1)
163163

164-
return NFFTToeplitzNormalOp(shape, W, fftplan, ifftplan, λ, xL1, xL2)
164+
return LinearOperatorCollection.NFFTToeplitzNormalOp(shape, W, fftplan, ifftplan, λ, xL1, xL2)
165165
end
166166

167167
function LinearOperatorCollection.normalOperator(S::NFFTOpImpl{T}, W = nothing; copyOpsFn = copy, kwargs...) where T
168168
if S.toeplitz
169-
return NFFTToeplitzNormalOp(S,W; kwargs...)
169+
return LinearOperatorCollection.NFFTToeplitzNormalOp(S,W; kwargs...)
170170
else
171171
return NormalOp(eltype(S); parent = S, weights = W)
172172
end
@@ -175,5 +175,5 @@ end
175175
function Base.copy(A::NFFTToeplitzNormalOp{T,D,W}) where {T,D,W}
176176
fftplan = plan_fft( zeros(T, 2 .* A.shape); flags=FFTW.MEASURE)
177177
ifftplan = plan_ifft(zeros(T, 2 .* A.shape); flags=FFTW.MEASURE)
178-
return NFFTToeplitzNormalOp(A.shape, A.weights, fftplan, ifftplan, A.λ, copy(A.xL1), copy(A.xL2))
178+
return LinearOperatorCollection.NFFTToeplitzNormalOp(A.shape, A.weights, fftplan, ifftplan, A.λ, copy(A.xL1), copy(A.xL2))
179179
end
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
module LinearOperatorNonuniformFFTsExt
2+
3+
using LinearOperatorCollection, AbstractNFFTs, NonuniformFFTs, NonuniformFFTs.Kernels, FFTW
4+
5+
function LinearOperatorCollection.NFFTToeplitzNormalOp(nfft::NFFTOp{T, P}, W=nothing; kwargs...) where {T, vecT, P <: NonuniformFFTs.NFFTPlan}
6+
shape = size_in(nfft.plan)
7+
8+
tmpVec = similar(nfft.Mv5, (2 .* shape)...)
9+
tmpVec .= zero(T)
10+
11+
# plan the FFTs
12+
fftplan = plan_fft(tmpVec; kwargs...)
13+
ifftplan = plan_ifft(tmpVec; kwargs...)
14+
15+
# TODO extend the following function by weights
16+
# λ = calculateToeplitzKernel(shape, nfft.plan.k; m = nfft.plan.params.m, σ = nfft.plan.params.σ, window = nfft.plan.params.window, LUTSize = nfft.plan.params.LUTSize, fftplan = fftplan)
17+
18+
shape_os = 2 .* shape
19+
baseArrayType = Base.typename(typeof(tmpVec)).wrapper # https://github.com/JuliaLang/julia/issues/35543
20+
21+
nufft = nfft.plan.p
22+
σ = nufft.σ
23+
m = Kernels.half_support(first(nufft.kernels))
24+
k = stack(nufft.points, dims = 1)
25+
26+
p = plan_nfft(baseArrayType, k, shape_os; m = m, σ = σ,
27+
precompute=AbstractNFFTs.POLYNOMIAL, fftflags=FFTW.ESTIMATE, blocking=true)
28+
tmpOnes = similar(tmpVec, size(k, 2))
29+
tmpOnes .= one(T)
30+
31+
if !isnothing(W)
32+
eigMat = adjoint(p) * ( W * tmpOnes)
33+
else
34+
eigMat = adjoint(p) * (tmpOnes)
35+
end
36+
37+
λ = fftplan * fftshift(eigMat)
38+
39+
xL1 = tmpVec
40+
xL2 = similar(xL1)
41+
42+
return LinearOperatorCollection.NFFTToeplitzNormalOp(shape, W, fftplan, ifftplan, λ, xL1, xL2)
43+
end
44+
45+
46+
end

src/LinearOperatorCollection.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,22 @@ end
3030

3131
export linearOperatorList, createLinearOperator
3232
export AbstractLinearOperatorFromCollection, WaveletOp, FFTOp, DCTOp, DSTOp, NFFTOp,
33-
SamplingOp, NormalOp, WeightingOp, GradientOp, RadonOp
33+
SamplingOp, NormalOp, WeightingOp, GradientOp, RadonOp, NFFTToeplitzNormalOp
3434

3535
abstract type AbstractLinearOperatorFromCollection{T} <: AbstractLinearOperator{T} end
3636
abstract type WaveletOp{T} <: AbstractLinearOperatorFromCollection{T} end
3737
abstract type FFTOp{T} <: AbstractLinearOperatorFromCollection{T} end
3838
abstract type DCTOp{T} <: AbstractLinearOperatorFromCollection{T} end
3939
abstract type DSTOp{T} <: AbstractLinearOperatorFromCollection{T} end
40-
abstract type NFFTOp{T} <: AbstractLinearOperatorFromCollection{T} end
40+
abstract type NFFTOp{T, P} <: AbstractLinearOperatorFromCollection{T} end
4141
abstract type SamplingOp{T} <: AbstractLinearOperatorFromCollection{T} end
4242
abstract type NormalOp{T,S} <: AbstractLinearOperatorFromCollection{T} end
4343
abstract type GradientOp{T} <: AbstractLinearOperatorFromCollection{T} end
4444
abstract type RadonOp{T} <: AbstractLinearOperatorFromCollection{T} end
4545

4646

47+
function NFFTToeplitzNormalOp end
48+
4749
"""
4850
returns a list of currently implemented `LinearOperator`s
4951
"""

0 commit comments

Comments
 (0)