@@ -77,8 +77,8 @@ function plan_nufft3{T<:AbstractFloat}(x::AbstractVector{T}, ω::AbstractVector{
77
77
NUFFTPlan {3, eltype(U), typeof(p)} (U, V, p, t, temp, temp2, Ones)
78
78
end
79
79
80
- function (* ){N,T,V}(p:: NUFFTPlan{N,T} , x :: AbstractVector {V} )
81
- A_mul_B! (zeros (promote_type (T,V), length (x )), p, x )
80
+ function (* ){N,T,V}(p:: NUFFTPlan{N,T} , c :: AbstractArray {V} )
81
+ A_mul_B! (zeros (promote_type (T,V), size (c )), p, c )
82
82
end
83
83
84
84
function Base. A_mul_B! {T} (f:: AbstractVector{T} , P:: NUFFTPlan{1,T} , c:: AbstractVector{T} )
@@ -96,13 +96,24 @@ function Base.A_mul_B!{T}(f::AbstractVector{T}, P::NUFFTPlan{1,T}, c::AbstractVe
96
96
f
97
97
end
98
98
99
- function Base. A_mul_B! {T} (F:: Matrix{T} , P:: NUFFTPlan{1 ,T} , C:: Matrix{T} )
99
+ function Base. A_mul_B! {N, T} (F:: Matrix{T} , P:: NUFFTPlan{N ,T} , C:: Matrix{T} )
100
100
for J = 1 : size (F, 2 )
101
101
A_mul_B_col_J! (F, P, C, J)
102
102
end
103
103
F
104
104
end
105
105
106
+ function broadcast_col_J! (f, temp:: Matrix , C:: Matrix , U:: Matrix , J:: Int )
107
+ N = size (C, 1 )
108
+ COLSHIFT = N* (J- 1 )
109
+ @inbounds for j = 1 : size (temp, 2 )
110
+ for i = 1 : N
111
+ temp[i,j] = f (C[i+ COLSHIFT],U[i,j])
112
+ end
113
+ end
114
+ temp
115
+ end
116
+
106
117
function A_mul_B_col_J! {T} (F:: Matrix{T} , P:: NUFFTPlan{1,T} , C:: Matrix{T} , J:: Int )
107
118
U, V, p, t, temp, temp2, Ones = P. U, P. V, P. p, P. t, P. temp, P. temp2, P. Ones
108
119
@@ -119,17 +130,6 @@ function A_mul_B_col_J!{T}(F::Matrix{T}, P::NUFFTPlan{1,T}, C::Matrix{T}, J::Int
119
130
F
120
131
end
121
132
122
- function broadcast_col_J! (f, temp:: Matrix , C:: Matrix , U:: Matrix , J:: Int )
123
- N = size (C, 1 )
124
- COLSHIFT = N* (J- 1 )
125
- @inbounds for j = 1 : size (temp, 2 )
126
- for i = 1 : N
127
- temp[i,j] = f (C[i+ COLSHIFT],U[i,j])
128
- end
129
- end
130
- temp
131
- end
132
-
133
133
function Base. A_mul_B! {T} (f:: AbstractVector{T} , P:: NUFFTPlan{2,T} , c:: AbstractVector{T} )
134
134
U, V, p, t, temp, temp2, Ones = P. U, P. V, P. p, P. t, P. temp, P. temp2, P. Ones
135
135
@@ -142,6 +142,19 @@ function Base.A_mul_B!{T}(f::AbstractVector{T}, P::NUFFTPlan{2,T}, c::AbstractVe
142
142
f
143
143
end
144
144
145
+ function A_mul_B_col_J! {T} (F:: Matrix{T} , P:: NUFFTPlan{2,T} , C:: Matrix{T} , J:: Int )
146
+ U, V, p, t, temp, temp2, Ones = P. U, P. V, P. p, P. t, P. temp, P. temp2, P. Ones
147
+
148
+ broadcast_col_J! (* , temp, C, V, J)
149
+ p* temp
150
+ reindex_temp! (temp, t, temp2)
151
+ broadcast! (* , temp, U, temp2)
152
+ COLSHIFT = size (C, 1 )* (J- 1 )
153
+ A_mul_B! (F, temp, Ones, 1 + COLSHIFT, 1 )
154
+
155
+ F
156
+ end
157
+
145
158
function Base. A_mul_B! {T} (f:: AbstractVector{T} , P:: NUFFTPlan{3,T} , c:: AbstractVector{T} )
146
159
U, V, p, t, temp, temp2, Ones = P. U, P. V, P. p, P. t, P. temp, P. temp2, P. Ones
147
160
@@ -202,6 +215,59 @@ nufft3{T<:AbstractFloat}(c::AbstractVector, x::AbstractVector{T}, ω::AbstractVe
202
215
const nufft = nufft3
203
216
const plan_nufft = plan_nufft3
204
217
218
+
219
+ doc"""
220
+ Pre-computes a 2D nonuniform fast Fourier transform.
221
+
222
+ For best performance, choose the right number of threads by `FFTW.set_num_threads(4)`, for example.
223
+ """
224
+ immutable NUFFT2DPlan{T,P1,P2} <: Base.DFT.Plan{T}
225
+ p1:: P1
226
+ p2:: P2
227
+ temp:: Vector{T}
228
+ end
229
+
230
+ doc"""
231
+ Pre-computes a 2D nonuniform fast Fourier transform of type II-II.
232
+ """
233
+ function plan_nufft2 {T<:AbstractFloat} (x:: AbstractVector{T} , y:: AbstractVector{T} , ϵ:: T )
234
+ p1 = plan_nufft2 (x, ϵ)
235
+ p2 = plan_nufft2 (y, ϵ)
236
+ temp = zeros (Complex{T}, length (y))
237
+
238
+ NUFFT2DPlan (p1, p2, temp)
239
+ end
240
+
241
+ function (* ){T,V}(p:: NUFFT2DPlan{T} , C:: Matrix{V} )
242
+ A_mul_B! (zeros (promote_type (T,V), size (C)), p, C)
243
+ end
244
+
245
+ function Base. A_mul_B! {T} (F:: Matrix{T} , P:: NUFFT2DPlan{T} , C:: Matrix{T} )
246
+ p1, p2, temp = P. p1, P. p2, P. temp
247
+
248
+ # Apply 1D x-plan to all columns
249
+ A_mul_B! (F, p1, C)
250
+
251
+ # Apply 1D y-plan to all rows
252
+ for i = 1 : size (C, 1 )
253
+ @inbounds for j = 1 : size (F, 2 ) temp[j] = F[i,j] end
254
+ A_mul_B! (temp, p2, temp)
255
+ @inbounds for j = 1 : size (F, 2 ) F[i,j] = temp[j] end
256
+ end
257
+
258
+ F
259
+ end
260
+
261
+ doc"""
262
+ Computes a 2D nonuniform fast Fourier transform of type II-II:
263
+
264
+ ```math
265
+ f_{j_1,j_2} = \s um_{k_1=1}^M\s um_{k_2=1}^N C_{k_1,k_2} e^{-2\p i{\r m i} (x_{j_1}(k_1-1) + x_{j_2}(k_2-1))},\q uad{\r m for}\q uad 1 \l e j_1 \l e M,\q uad 1 \l e j_2 \l e N.
266
+ ```
267
+ """
268
+ nufft2 {T<:AbstractFloat} (C:: Matrix , x:: AbstractVector{T} , y:: AbstractVector{T} , ϵ:: T ) = plan_nufft2 (x, y, ϵ)* C
269
+
270
+
205
271
FindK {T<:AbstractFloat} (γ:: T , ϵ:: T ) = Int (ceil (5 * γ* exp (lambertw (log (10 / ϵ)/ γ/ 7 ))))
206
272
AssignClosestEquispacedGridpoint {T<:AbstractFloat} (x:: AbstractVector{T} ):: AbstractVector{T} = round .([Int], size (x, 1 )* x)
207
273
AssignClosestEquispacedFFTpoint {T<:AbstractFloat} (x:: AbstractVector{T} ):: Array{Int,1} = mod .(round .([Int], size (x, 1 )* x), size (x, 1 )) + 1
0 commit comments