Skip to content

Commit d97bd79

Browse files
v1.0.0: Add RCpair copy! for complex. Rename region->dims. Remove deprecation. (#17)
* add RCpair copy! for complex * version bump * Update CI.yml * remove deprecated func * `region` -> `dims` * breaking change version bump * fix PR coverage * fixes * suggestions
1 parent 4245504 commit d97bd79

File tree

6 files changed

+29
-25
lines changed

6 files changed

+29
-25
lines changed

.github/workflows/CI.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ jobs:
1313
fail-fast: false
1414
matrix:
1515
version:
16-
- '1.1'
17-
# - 'nightly'
16+
- '1.6'
17+
- '1'
1818
os:
1919
- ubuntu-latest
20+
- windows-latest
21+
- macOS-latest
2022
arch:
2123
- x64
2224
steps:

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
Manifest.toml

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "RFFT"
22
uuid = "3bd9afcd-55df-531a-9b34-dc642dce7b95"
33
authors = ["Tim Holy <[email protected]>"]
4-
version = "0.1.0"
4+
version = "1.0.0"
55

66
[deps]
77
FFTW = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341"

REQUIRE

-1
This file was deleted.

src/RFFT.jl

+17-18
Original file line numberDiff line numberDiff line change
@@ -9,66 +9,65 @@ import Base: real, complex, copy, copy!
99
mutable struct RCpair{T<:AbstractFloat,N,RType<:AbstractArray{T,N},CType<:AbstractArray{Complex{T},N}}
1010
R::RType
1111
C::CType
12-
region::Vector{Int}
12+
dims::Vector{Int}
1313
end
1414

15-
function RCpair{T}(::UndefInitializer, realsize::Dims{N}, region=1:length(realsize)) where {T<:AbstractFloat,N}
15+
function RCpair{T}(::UndefInitializer, realsize::Dims{N}, dims=1:length(realsize)) where {T<:AbstractFloat,N}
1616
sz = [realsize...]
17-
firstdim = region[1]
17+
firstdim = dims[1]
1818
sz[firstdim] = realsize[firstdim]>>1 + 1
1919
sz2 = copy(sz)
2020
sz2[firstdim] *= 2
2121
R = Array{T,N}(undef, (sz2...,)::Dims{N})
2222
C = unsafe_wrap(Array, convert(Ptr{Complex{T}}, pointer(R)), (sz...,)::Dims{N}) # work around performance problems of reinterpretarray
23-
RCpair(view(R, map(n->1:n, realsize)...), C, [region...])
23+
RCpair(view(R, map(n->1:n, realsize)...), C, [dims...])
2424
end
2525

26-
RCpair(A::Array{T}, region=1:ndims(A)) where {T<:AbstractFloat} = copy!(RCpair{T}(undef, size(A), region), A)
26+
RCpair(A::Array{T}, dims=1:ndims(A)) where {T<:AbstractFloat} = copy!(RCpair{T}(undef, size(A), dims), A)
2727

2828
real(RC::RCpair) = RC.R
2929
complex(RC::RCpair) = RC.C
3030

3131
copy!(RC::RCpair, A::AbstractArray{T}) where {T<:Real} = (copy!(RC.R, A); RC)
32+
copy!(RC::RCpair, A::AbstractArray{T}) where {T<:Complex} = (copy!(RC.C, A); RC)
3233
function copy(RC::RCpair{T,N}) where {T,N}
3334
C = copy(RC.C)
3435
R = reshape(reinterpret(T, C), size(parent(RC.R)))
35-
RCpair(view(R, RC.R.indices...), C, copy(RC.region))
36+
RCpair(view(R, RC.R.indices...), C, copy(RC.dims))
3637
end
3738

3839
# New API
39-
rplan_fwd(R, C, region, flags, tlim) =
40-
FFTW.rFFTWPlan{eltype(R),FFTW.FORWARD,true,ndims(R)}(R, C, region, flags, tlim)
41-
rplan_inv(R, C, region, flags, tlim) =
42-
FFTW.rFFTWPlan{eltype(R),FFTW.BACKWARD,true,ndims(R)}(R, C, region, flags, tlim)
40+
rplan_fwd(R, C, dims, flags, tlim) =
41+
FFTW.rFFTWPlan{eltype(R),FFTW.FORWARD,true,ndims(R)}(R, C, dims, flags, tlim)
42+
rplan_inv(R, C, dims, flags, tlim) =
43+
FFTW.rFFTWPlan{eltype(R),FFTW.BACKWARD,true,ndims(R)}(R, C, dims, flags, tlim)
4344
function plan_rfft!(RC::RCpair{T}; flags::Integer = FFTW.ESTIMATE, timelimit::Real = FFTW.NO_TIMELIMIT) where T
44-
p = rplan_fwd(RC.R, RC.C, RC.region, flags, timelimit)
45+
p = rplan_fwd(RC.R, RC.C, RC.dims, flags, timelimit)
4546
return Z::RCpair -> begin
4647
FFTW.assert_applicable(p, Z.R, Z.C)
4748
FFTW.unsafe_execute!(p, Z.R, Z.C)
4849
return Z
4950
end
5051
end
5152
function plan_irfft!(RC::RCpair{T}; flags::Integer = FFTW.ESTIMATE, timelimit::Real = FFTW.NO_TIMELIMIT) where T
52-
p = rplan_inv(RC.C, RC.R, RC.region, flags, timelimit)
53+
p = rplan_inv(RC.C, RC.R, RC.dims, flags, timelimit)
5354
return Z::RCpair -> begin
5455
FFTW.assert_applicable(p, Z.C, Z.R)
5556
FFTW.unsafe_execute!(p, Z.C, Z.R)
56-
rmul!(Z.R, 1 / prod(size(Z.R)[Z.region]))
57+
rmul!(Z.R, 1 / prod(size(Z.R)[Z.dims]))
5758
return Z
5859
end
5960
end
6061
function rfft!(RC::RCpair{T}) where T
61-
p = rplan_fwd(RC.R, RC.C, RC.region, FFTW.ESTIMATE, FFTW.NO_TIMELIMIT)
62+
p = rplan_fwd(RC.R, RC.C, RC.dims, FFTW.ESTIMATE, FFTW.NO_TIMELIMIT)
6263
FFTW.unsafe_execute!(p, RC.R, RC.C)
6364
return RC
6465
end
6566
function irfft!(RC::RCpair{T}) where T
66-
p = rplan_inv(RC.C, RC.R, RC.region, FFTW.ESTIMATE, FFTW.NO_TIMELIMIT)
67+
p = rplan_inv(RC.C, RC.R, RC.dims, FFTW.ESTIMATE, FFTW.NO_TIMELIMIT)
6768
FFTW.unsafe_execute!(p, RC.C, RC.R)
68-
rmul!(RC.R, 1 / prod(size(RC.R)[RC.region]))
69+
rmul!(RC.R, 1 / prod(size(RC.R)[RC.dims]))
6970
return RC
7071
end
7172

72-
@deprecate RCpair(realtype::Type{T}, realsize, region=1:length(realsize)) where T<:AbstractFloat RCpair{T}(undef, realsize, region)
73-
7473
end

test/runtests.jl

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import RFFT
22
using Test, FFTW, LinearAlgebra
33

4-
@testset begin
5-
for region in (1:2, 1, 2)
4+
@testset "RFFT.jl" begin
5+
for dims in (1:2, 1, 2)
66
for sz in ((5,6), (6,5))
7-
pair = RFFT.RCpair{Float64}(undef, sz, region)
7+
pair = RFFT.RCpair{Float64}(undef, sz, dims)
88
r = @inferred(real(pair))
99
c = @inferred(complex(pair))
1010
b = rand(eltype(r), size(r))
11+
pair = RFFT.RCpair(b, dims)
1112
copyto!(r, b)
13+
copy!(pair, c) # for coverage
1214
RFFT.rfft!(pair)
1315
RFFT.irfft!(pair)
1416
@test r b

0 commit comments

Comments
 (0)