Skip to content

Commit d19931e

Browse files
committed
Add DCT-I test plan to test real-to-real transforms
1 parent d64a878 commit d19931e

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

test/TestPlans.jl

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,4 +294,44 @@ Base.:*(p::WrapperTestPlan, x::AbstractArray) = p.plan * x
294294
AbstractFFTs.plan_inv(p::WrapperTestPlan) = WrapperTestPlan(AbstractFFTs.plan_inv(p.plan))
295295
Base.inv(p::WrapperTestPlan) = WrapperTestPlan(inv(p.plan))
296296

297+
#####
298+
# DCT tests, to test real-to-real plans.
299+
# We implement DCT-I by using its equivalence to an
300+
# fft applied to [x; reverse(x)[2:end-1]]
301+
####
302+
struct TestDCTIPlan{T,N,FFTPlan} <: Plan{T}
303+
fftplan::FFTPlan
304+
sz::NTuple{N,Int}
305+
function TestPlan{T}(fftplan::FFTPlan, sz::NTuple{N,Int}) where {T,N,FFTPlan}
306+
return new{T,N,FFTPlan}(fftplan, sz)
307+
end
308+
end
309+
310+
Base.size(p::TestDCTIPlan) = p.sz
311+
Base.ndims(::TestDCTIPlan{T,N}) where {T,N} = N
312+
313+
314+
_doublesize((n,)::Tuple{Int}, region) = (2n-2,)
315+
316+
function plan_dctI(x::AbstractArray{T}, region; kwargs...) where {T}
317+
return TestDCTIPlan{T}(plan_fft(Array{complex(float(T))}(undef, _doublesize(size(x), region)),region; kwargs...), size(x))
318+
end
319+
320+
Base.:*(p::TestDCTIPlan, x::AbstractArray) = mul!(similar(x, complex(float(eltype(x)))), p, x)
321+
function LinearAlgebra.mul!(
322+
y::AbstractArray{<:Real,N}, p::TestPlan, x::AbstractArray{<:Real,N}
323+
) where {N}
324+
size(y) == size(p) == size(x) || throw(DimensionMismatch())
325+
ret = Array{complex(float(eltype(y)))}(undef, size(p.fftplan))
326+
tmp = similar(ret)
327+
if N == 1
328+
tmp[1:length(x)] = x
329+
tmp[length(x)+1:end-1] = x[end-1:-1:2]
330+
mul!(ret, p.fftplan, tmp)
331+
copyto!(y, view(ret, 1:length(y)))
332+
else
333+
error("not implemented")
334+
end
335+
end
336+
297337
end

0 commit comments

Comments
 (0)