-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add compatibility for FFTW.jl and AbstractFFTs.jl (#2)
* Implement FFT methods * * src/fft.jl: fix fft pointing to wrong package * Add non-time tests and minor bump
- Loading branch information
Showing
5 changed files
with
198 additions
and
8 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 |
---|---|---|
@@ -1,10 +1,12 @@ | ||
name = "TimeAxes" | ||
uuid = "9a9fc9a6-283d-47e9-a2f6-b3a44e559ea3" | ||
authors = ["Zachary P. Christensen <[email protected]>"] | ||
version = "0.2.0" | ||
version = "0.2.1" | ||
|
||
[deps] | ||
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c" | ||
AxisIndices = "f52c9ee2-1b1c-4fd8-8546-6350938c7f11" | ||
FFTW = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341" | ||
IntervalSets = "8197267c-284f-5f27-9208-e0e47529a953" | ||
NamedDims = "356022a1-0364-5f58-8944-0da4b18d706f" | ||
Reexport = "189a3867-3050-52da-a836-e630ba90ab69" | ||
|
@@ -16,7 +18,6 @@ NamedDims = "0.2" | |
Reexport = "0.2" | ||
julia = "1" | ||
|
||
|
||
[extras] | ||
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" | ||
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d" |
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,98 @@ | ||
# TODO if FFTW functionality is merged int NamedDims then this code needs to be changed | ||
|
||
### | ||
### fft_axes | ||
### | ||
function fft_axis(fxn::Function, axis::AbstractAxis, inds::AbstractUnitRange) | ||
return assign_indices(axis, inds) # default | ||
end | ||
|
||
@inline function fft_axes(fxn::Function, axs::Tuple, inds::Tuple, dims::Tuple, cnt::Int=1) | ||
if first(dims) === cnt | ||
return (fft_axis(fxn, first(axs), first(inds)), | ||
fft_axes(fxn, tail(axs), tail(inds), tail(dims), cnt + 1)...) | ||
else | ||
return (assign_indices(first(axs), first(inds)), | ||
fft_axes(fxn, tail(axs), tail(inds), dims, cnt + 1)...) | ||
end | ||
end | ||
fft_axes(fxn::Function, axs::Tuple, inds::Tuple, dims::Tuple{}, cnt::Int=1) = map(assign_indices, axs, inds) | ||
fft_axes(fxn::Function, axs::Tuple{}, inds::Tuple{}, dims::Tuple{}, cnt::Int=1) = () | ||
|
||
|
||
### | ||
### fft_names | ||
### | ||
fft_name(fxn::Function, dname::Symbol) = dname # default is to do nothing | ||
@inline function fft_names(fxn::Function, dnames::NTuple{N,Symbol}, dims::Tuple{Vararg{Int}}) where {N} | ||
ntuple(Val(N)) do i | ||
if i in dims | ||
fft_name(fxn, getfield(dnames, i)) | ||
else | ||
getfield(dnames, i) | ||
end | ||
end | ||
end | ||
|
||
|
||
for f in (:fft, :ifft, :bfft) | ||
@eval begin | ||
function AbstractFFTs.$f(A::AbstractAxisArray, dims) | ||
p = AbstractFFTs.$f(parent(A), dims) | ||
axs = fft_axes(AbstractFFTs.$f, axes(A), axes(p), dims) | ||
return unsafe_reconstruct(A, p, axs) | ||
end | ||
|
||
function AbstractFFTs.$f(A::NamedDimsArray, dims::Union{Symbol,Integer}) | ||
return AbstractFFTs.$f(A, (NamedDims.dim(dimnames(A), dims),)) | ||
end | ||
|
||
function AbstractFFTs.$f(A::NamedDimsArray, dims::Tuple) | ||
if dims isa Tuple{Vararg{<:Integer}} | ||
dn = fft_names(AbstractFFTs.$f, dimnames(A), dims) | ||
return NamedDimsArray{dn}(AbstractFFTs.$f(parent(A), dims)) | ||
else | ||
return AbstractFFTs.$f(A, (NamedDims.dims(dimnames(A), dims),)) | ||
end | ||
end | ||
|
||
function AbstractFFTs.$f(A::NamedDimsArray{L,T,N}) where {L,T,N} | ||
if has_timedim(A) | ||
return AbstractFFTs.$f(A, (timedim(A),)) | ||
else | ||
return AbstractFFTs.$f(A, ntuple(+, Val(N))) | ||
end | ||
end | ||
end | ||
end | ||
|
||
for f in (:dct, :idct) | ||
@eval begin | ||
function FFTW.$f(A::AbstractAxisArray, dims) | ||
p = FFTW.$f(parent(A), dims) | ||
axs = fft_axes(FFTW.$f, axes(A), axes(p), dims) | ||
return unsafe_reconstruct(A, p, axs) | ||
end | ||
|
||
function FFTW.$f(A::NamedDimsArray, dims::Union{Symbol,Integer}) | ||
return FFTW.$f(A, (NamedDims.dim(dimnames(A), dims),)) | ||
end | ||
|
||
function FFTW.$f(A::NamedDimsArray, dims::Tuple) | ||
if dims isa Tuple{Vararg{<:Integer}} | ||
dn = fft_names(FFTW.$f, dimnames(A), dims) | ||
return NamedDimsArray{dn}(FFTW.$f(parent(A), dims)) | ||
else | ||
return FFTW.$f(A, (NamedDims.dim(dimnames(A), dims),)) | ||
end | ||
end | ||
|
||
function FFTW.$f(A::NamedDimsArray{L,T,N}) where {L,T,N} | ||
if has_timedim(A) | ||
return FFTW.$f(A, (timedim(A),)) | ||
else | ||
return FFTW.$f(A, ntuple(+, Val(N))) | ||
end | ||
end | ||
end | ||
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
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
ff55da2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register
ff55da2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request created: JuliaRegistries/General/16960
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via: