Skip to content

Commit 7c6ce37

Browse files
committed
fixed bug in IRDFT
1 parent dddb844 commit 7c6ce37

File tree

4 files changed

+40
-17
lines changed

4 files changed

+40
-17
lines changed

src/linearoperators/IRDFT.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ function IRDFT(x::AbstractArray{Complex{T},N}, d::Int, dims::Int=1) where {T<:Nu
4242
dim_out = ()
4343
idx = ()
4444
for i = 1:N
45-
dim_out = i == dims ? (dim_out..., d) : (dim_out...,dim_in[i] )
46-
idx = i == dims ? (idx... ,2:dim_in[i]) : (idx... ,Colon() )
45+
dim_out = i == dims ? (dim_out..., d) : (dim_out...,dim_in[i] )
46+
idx = i == dims ? (idx... , 2:ceil(Int,d/2)) : (idx... ,Colon() )
4747
end
4848
At = plan_rfft(zeros(dim_out),dims)
4949
IRDFT{T,N,dims,typeof(A),typeof(At),typeof(idx)}(dim_in,dim_out,A,At,idx)

src/utilities/block.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ blockeltype(x::AbstractArray) = eltype(x)
3636
blocklength(x::Tuple) = sum(blocklength.(x))
3737
blocklength(x::AbstractArray) = length(x)
3838

39-
blockvecnorm(x::Tuple) = sqrt(blockvecdot(x, x))
39+
blockvecnorm(x::Tuple) = sqrt(real(blockvecdot(x, x)))
4040
blockvecnorm(x::AbstractArray{R}) where {R <: Number} = vecnorm(x)
4141

4242
blockmaxabs(x::Tuple) = maximum(blockmaxabs.(x))
@@ -55,8 +55,7 @@ blockset!(y::Tuple, x) = blockset!.(y, x)
5555
blockset!(y::AbstractArray, x) = (y .= x)
5656

5757
blockvecdot(x::T1, y::T2) where {T1 <: Tuple, T2 <: Tuple} = sum(blockvecdot.(x,y))
58-
blockvecdot(x::AbstractArray{R1}, y::AbstractArray{R2}) where {R1 <: Number, R2 <: Number} = real(vecdot(x, y))
59-
# inner product must be always real see section 4.2 of TFOCS manual
58+
blockvecdot(x::AbstractArray{R1}, y::AbstractArray{R2}) where {R1 <: Number, R2 <: Number} = vecdot(x, y)
6059

6160
blockzeros(t::Tuple, s::Tuple) = blockzeros.(t, s)
6261
blockzeros(t::Type, n::NTuple{N, Integer} where {N}) = zeros(t, n)

test/test_block.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ blockset!(yb,xb)
4848

4949
z = blockvecdot(x,x2)
5050
zb = blockvecdot(xb,x2b)
51-
@test z == real(vecdot(x,x2))
52-
@test zb == real(vecdot(xb[1],x2b[1])+vecdot(xb[2],x2b[2])+vecdot(xb[3],x2b[3]))
51+
@test z == vecdot(x,x2)
52+
@test zb == vecdot(xb[1],x2b[1])+vecdot(xb[2],x2b[2])+vecdot(xb[3],x2b[3])
5353

5454
y = blockzeros(x)
5555
yb = blockzeros(xb)

test/test_linear_operators.jl

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -207,19 +207,43 @@ op = RDFT(n,n)
207207
@test is_full_column_rank(op) == false
208208

209209
####### IRDFT ############
210-
n = 10
211-
op = IRDFT(Complex{Float64},(n,),19)
212-
x1 = rfft(randn(19))
213-
y1 = test_op(op, x1,irfft(randn(n),19), verb)
214-
y2 = irfft(x1,19)
210+
n = 12
211+
op = IRDFT(Complex{Float64},(div(n,2)+1,),n)
212+
x1 = rfft(randn(n))
213+
y1 = test_op(op, x1,irfft(randn(div(n,2)+1),n), verb)
214+
y2 = irfft(x1,n)
215215

216216
@test all(vecnorm.(y1 .- y2) .<= 1e-12)
217217

218-
n,m,l = 4,10,5
219-
op = IRDFT(Complex{Float64},(n,m,l),19,2)
220-
x1 = rfft(randn(n,19,l),2)
221-
y1 = test_op(op, x1, irfft(x1,19,2), verb)
222-
y2 = irfft(x1,19,2)
218+
n = 11
219+
op = IRDFT(Complex{Float64},(div(n,2)+1,),n)
220+
x1 = rfft(randn(n))
221+
y1 = test_op(op, x1,irfft(randn(div(n,2)+1),n), verb)
222+
y2 = irfft(x1,n)
223+
224+
@test all(vecnorm.(y1 .- y2) .<= 1e-12)
225+
226+
n,m,l = 4,19,5
227+
op = IRDFT(Complex{Float64},(n,div(m,2)+1,l),m,2)
228+
x1 = rfft(randn(n,m,l),2)
229+
y1 = test_op(op, x1, irfft(x1,m,2), verb)
230+
y2 = irfft(x1,m,2)
231+
232+
@test all(vecnorm.(y1 .- y2) .<= 1e-12)
233+
234+
n,m,l = 4,18,5
235+
op = IRDFT(Complex{Float64},(n,div(m,2)+1,l),m,2)
236+
x1 = rfft(randn(n,m,l),2)
237+
y1 = test_op(op, x1, irfft(x1,m,2), verb)
238+
y2 = irfft(x1,m,2)
239+
240+
@test all(vecnorm.(y1 .- y2) .<= 1e-12)
241+
242+
n,m,l = 5,18,5
243+
op = IRDFT(Complex{Float64},(div(n,2)+1,m,l),n,1)
244+
x1 = rfft(randn(n,m,l),1)
245+
y1 = test_op(op, x1, irfft(x1,n,1), verb)
246+
y2 = irfft(x1,n,1)
223247

224248
@test all(vecnorm.(y1 .- y2) .<= 1e-12)
225249

0 commit comments

Comments
 (0)