From 1e79b4f760cb23b6b787333ce5bc2d54e8bf45b1 Mon Sep 17 00:00:00 2001 From: Johnny Chen Date: Thu, 21 Oct 2021 00:11:43 +0800 Subject: [PATCH] fix deprecations: `unsafe_length` and `one` (#23) --- src/FFTViews.jl | 7 ++++++- test/runtests.jl | 10 +++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/FFTViews.jl b/src/FFTViews.jl index c53d941..b8747cc 100644 --- a/src/FFTViews.jl +++ b/src/FFTViews.jl @@ -86,6 +86,11 @@ 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) +if VERSION >= v"1.7.0-beta4" + # https://github.com/JuliaLang/julia/pull/40382 + modrange(i, rng::AbstractUnitRange) = mod(i-first(rng), length(rng))+first(rng) +else + modrange(i, rng::AbstractUnitRange) = mod(i-first(rng), unsafe_length(rng))+first(rng) +end end # module diff --git a/test/runtests.jl b/test/runtests.jl index 990d081..93845ab 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -2,9 +2,17 @@ using FFTViews using FFTW using Test +if VERSION < v"1.1" + # https://github.com/JuliaLang/julia/pull/29442 + _oneunit(::CartesianIndex{N}) where {N} = _oneunit(CartesianIndex{N}) + _oneunit(::Type{CartesianIndex{N}}) where {N} = CartesianIndex(ntuple(x -> 1, Val(N))) +else + const _oneunit = Base.oneunit +end + 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