diff --git a/src/FFTViews.jl b/src/FFTViews.jl index c53d941..83eece9 100644 --- a/src/FFTViews.jl +++ b/src/FFTViews.jl @@ -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 @@ -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 @@ -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 diff --git a/test/runtests.jl b/test/runtests.jl index 990d081..4e0a292 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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 @@ -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 @@ -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))