-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
20df36d
commit 17e9b0a
Showing
5 changed files
with
140 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ author = ["Tim Holy <[email protected]>", "Jan Weidner <[email protected]>"] | |
version = "0.7.8" | ||
|
||
[deps] | ||
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c" | ||
CatIndices = "aafaddc9-749c-510e-ac4f-586e18779b91" | ||
ComputationalResources = "ed09eef8-17a6-5b46-8889-db040fac31e3" | ||
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" | ||
|
@@ -13,8 +14,8 @@ ImageBase = "c817782e-172a-44cc-b673-b171935fbb9e" | |
ImageCore = "a09fc81d-aa75-5fe9-8630-4744c3626534" | ||
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" | ||
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881" | ||
Reexport = "189a3867-3050-52da-a836-e630ba90ab69" | ||
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a" | ||
Reexport = "189a3867-3050-52da-a836-e630ba90ab69" | ||
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" | ||
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" | ||
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" | ||
|
@@ -29,8 +30,8 @@ FFTW = "0.3, 1" | |
ImageBase = "0.1.5" | ||
ImageCore = "0.10" | ||
OffsetArrays = "1.9" | ||
Reexport = "1.1" | ||
PrecompileTools = "1" | ||
Reexport = "1.1" | ||
StaticArrays = "0.10, 0.11, 0.12, 1.0" | ||
TiledIteration = "0.2, 0.3, 0.4, 0.5" | ||
julia = "1.6" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
module RFFT | ||
|
||
using FFTW, LinearAlgebra | ||
|
||
export RCpair, plan_rfft!, plan_irfft!, rfft!, irfft!, normalization | ||
|
||
import Base: real, complex, copy, copy! | ||
|
||
mutable struct RCpair{T<:AbstractFloat,N,RType<:AbstractArray{T,N},CType<:AbstractArray{Complex{T},N}} | ||
R::RType | ||
C::CType | ||
region::Vector{Int} | ||
end | ||
|
||
function RCpair{T}(::UndefInitializer, realsize::Dims{N}, region=1:length(realsize)) where {T<:AbstractFloat,N} | ||
sz = [realsize...] | ||
firstdim = region[1] | ||
sz[firstdim] = realsize[firstdim]>>1 + 1 | ||
sz2 = copy(sz) | ||
sz2[firstdim] *= 2 | ||
R = Array{T,N}(undef, (sz2...,)::Dims{N}) | ||
C = unsafe_wrap(Array, convert(Ptr{Complex{T}}, pointer(R)), (sz...,)::Dims{N}) # work around performance problems of reinterpretarray | ||
RCpair(view(R, map(n->1:n, realsize)...), C, [region...]) | ||
end | ||
|
||
RCpair(A::Array{T}, region=1:ndims(A)) where {T<:AbstractFloat} = copy!(RCpair{T}(undef, size(A), region), A) | ||
|
||
real(RC::RCpair) = RC.R | ||
complex(RC::RCpair) = RC.C | ||
|
||
copy!(RC::RCpair, A::AbstractArray{T}) where {T<:Real} = (copy!(RC.R, A); RC) | ||
function copy(RC::RCpair{T,N}) where {T,N} | ||
C = copy(RC.C) | ||
R = reshape(reinterpret(T, C), size(parent(RC.R))) | ||
RCpair(view(R, RC.R.indices...), C, copy(RC.region)) | ||
end | ||
|
||
# New API | ||
rplan_fwd(R, C, region, flags, tlim) = | ||
FFTW.rFFTWPlan{eltype(R),FFTW.FORWARD,true,ndims(R)}(R, C, region, flags, tlim) | ||
rplan_inv(R, C, region, flags, tlim) = | ||
FFTW.rFFTWPlan{eltype(R),FFTW.BACKWARD,true,ndims(R)}(R, C, region, flags, tlim) | ||
function plan_rfft!(RC::RCpair{T}; flags::Integer = FFTW.ESTIMATE, timelimit::Real = FFTW.NO_TIMELIMIT) where T | ||
p = rplan_fwd(RC.R, RC.C, RC.region, flags, timelimit) | ||
return Z::RCpair -> begin | ||
FFTW.assert_applicable(p, Z.R, Z.C) | ||
FFTW.unsafe_execute!(p, Z.R, Z.C) | ||
return Z | ||
end | ||
end | ||
function plan_irfft!(RC::RCpair{T}; flags::Integer = FFTW.ESTIMATE, timelimit::Real = FFTW.NO_TIMELIMIT) where T | ||
p = rplan_inv(RC.C, RC.R, RC.region, flags, timelimit) | ||
return Z::RCpair -> begin | ||
FFTW.assert_applicable(p, Z.C, Z.R) | ||
FFTW.unsafe_execute!(p, Z.C, Z.R) | ||
rmul!(Z.R, 1 / prod(size(Z.R)[Z.region])) | ||
return Z | ||
end | ||
end | ||
function rfft!(RC::RCpair{T}) where T | ||
p = rplan_fwd(RC.R, RC.C, RC.region, FFTW.ESTIMATE, FFTW.NO_TIMELIMIT) | ||
FFTW.unsafe_execute!(p, RC.R, RC.C) | ||
return RC | ||
end | ||
function irfft!(RC::RCpair{T}) where T | ||
p = rplan_inv(RC.C, RC.R, RC.region, FFTW.ESTIMATE, FFTW.NO_TIMELIMIT) | ||
FFTW.unsafe_execute!(p, RC.C, RC.R) | ||
rmul!(RC.R, 1 / prod(size(RC.R)[RC.region])) | ||
return RC | ||
end | ||
|
||
@deprecate RCpair(realtype::Type{T}, realsize, region=1:length(realsize)) where T<:AbstractFloat RCpair{T}(undef, realsize, region) | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters