Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some depwarns and ambiguities #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/FFTViews.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module FFTViews

using Base: tail, unsafe_length, @propagate_inbounds
using Base: tail, @propagate_inbounds
using FFTW

# A custom rangetype that will be used for indices and never throws a
Expand Down Expand Up @@ -69,9 +69,9 @@ function Base.similar(A::AbstractArray, T::Type, shape::Tuple{FFTVRange,Vararg{F
FFTView(similar(A, T, map(length, shape)))
end

function Base.similar(f::Union{Function,Type}, shape::Tuple{FFTVRange,Vararg{FFTVRange}})
function Base.similar(::Type{AA}, shape::Tuple{FFTVRange,Vararg{FFTVRange}}) where AA<:AbstractArray
all(x->first(x)==0, shape) || throw(BoundsError("cannot allocate FFTView with the first element of the range non-zero"))
FFTView(similar(f, map(length, shape)))
FFTView(similar(AA, map(length, shape)))
end

Base.reshape(F::FFTView{_,N}, ::Type{Val{N}}) where {_,N} = F
Expand All @@ -86,6 +86,6 @@ FFTW.rfft(F::FFTView, dims; kwargs...) = rfft(parent(F), dims; kwargs...)
reindex(::Type{V}, ::Tuple{}, ::Tuple{}) where {V} = ()
_reindex(::Type{FFTView}, ind, i) = modrange(i+1, ind)

modrange(i, rng::AbstractUnitRange) = mod(i-first(rng), unsafe_length(rng))+first(rng)
modrange(i, rng::AbstractUnitRange) = mod(i-first(rng), length(rng))+first(rng)

end # module
9 changes: 6 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
using FFTViews
using FFTW
using OffsetArrays
using Test

@test isempty(detect_ambiguities(FFTViews))

function test_approx_eq_periodic(a::FFTView, b)
for I in CartesianIndices(axes(b))
@test a[I-one(I)] ≈ b[I]
@test a[I-oneunit(I)] ≈ b[I]
end
nothing
end
Expand Down Expand Up @@ -42,6 +45,8 @@ end
@test reshape(a, Val{2}) === a
@test reshape(a, Val{1}) == FFTView(convert(Vector{Float64}, collect(1:35)))
@test axes(reshape(a, Val{3})) == (0:4,0:6,0:0)
# issue #20
@test FFTView(ones((3))) .+ 1 == FFTView(fill(2, 3))
end

@testset "convolution-shift" begin
Expand Down Expand Up @@ -78,8 +83,6 @@ end
end
end

using OffsetArrays

@testset "convolution-offset" begin
for l2 in (8,9), l1 in (8,9)
a = OffsetArray(zeros(l1,l2), (-2,-3))
Expand Down