Skip to content

Commit

Permalink
Fix some depwarns and ambiguities
Browse files Browse the repository at this point in the history
Fixes #20
  • Loading branch information
timholy committed Aug 18, 2021
1 parent 75f8eb9 commit 62de34b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
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

0 comments on commit 62de34b

Please sign in to comment.