Skip to content

Commit

Permalink
fix deprecations: unsafe_length and one (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnychen94 authored Oct 20, 2021
1 parent 75f8eb9 commit 1e79b4f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/FFTViews.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 9 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1e79b4f

Please sign in to comment.