Skip to content

Commit

Permalink
Fix axes-of-axes indexing problem (fixes #11) (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
timholy authored Sep 15, 2019
1 parent f8bacce commit e3ee1ae
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions src/FFTViews.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
__precompile__(true)

module FFTViews

using Base: tail, unsafe_length, @propagate_inbounds
Expand All @@ -10,15 +8,30 @@ using FFTW
using CustomUnitRanges
include(CustomUnitRanges.filename_for_urange)

Base.checkindex(::Type{Bool}, inds::URange, ::Base.Slice) = true
Base.checkindex(::Type{Bool}, inds::URange, ::Base.LogicalIndex) = true
Base.checkindex(::Type{Bool}, inds::URange, ::Real) = true
Base.checkindex(::Type{Bool}, inds::URange, ::AbstractRange) = true
Base.checkindex(::Type{Bool}, inds::URange, ::AbstractVector{Bool}) = true
Base.checkindex(::Type{Bool}, inds::URange, ::AbstractArray{Bool}) = true
Base.checkindex(::Type{Bool}, inds::URange, ::AbstractArray) = true
@static if isdefined(Base, :IdentityUnitRange)
const indextypes = (URange, Base.IdentityUnitRange{<:URange})
const FFTVRange{T} = Union{URange{T}, Base.Slice{URange{T}}, Base.IdentityUnitRange{URange{T}}}
indrange(i) = Base.IdentityUnitRange(URange(first(i)-1, last(i)-1))
else
const indextypes = (URange, Base.Slice{<:URange})
const FFTVRange{T} = Union{URange{T}, Base.Slice{URange{T}}}
indrange(i) = Base.Slice(URange(first(i)-1, last(i)-1))
end

const FFTVRange{T} = Union{URange{T}, Base.Slice{URange{T}}, Base.IdentityUnitRange{URange{T}}}
for T in indextypes
@eval begin
Base.checkindex(::Type{Bool}, ::$T, ::Base.Slice) = true
Base.checkindex(::Type{Bool}, ::$T, ::Base.LogicalIndex) = true
Base.checkindex(::Type{Bool}, ::$T, ::Real) = true
Base.checkindex(::Type{Bool}, ::$T, ::AbstractRange) = true
Base.checkindex(::Type{Bool}, ::$T, ::AbstractVector{Bool}) = true
Base.checkindex(::Type{Bool}, ::$T, ::AbstractArray{Bool}) = true
Base.checkindex(::Type{Bool}, ::$T, ::AbstractArray) = true
end
if isdefined(Base, :IdentityUnitRange)
@eval Base.checkindex(::Type{Bool}, ::$T, ::Base.IdentityUnitRange) = true
end
end

export FFTView

Expand Down Expand Up @@ -50,7 +63,6 @@ end
Base.parent(F::AbstractFFTView) = F.parent
Base.axes(F::AbstractFFTView) = map(indrange, axes(parent(F)))
Base.size(F::AbstractFFTView) = size(parent(F))
indrange(i) = URange(first(i)-1, last(i)-1)

function Base.similar(A::AbstractArray, T::Type, shape::Tuple{FFTVRange,Vararg{FFTVRange}})
all(x->first(x)==0, shape) || throw(BoundsError("cannot allocate FFTView with the first element of the range non-zero"))
Expand Down

2 comments on commit e3ee1ae

@timholy
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/3550

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if Julia TagBot is installed, or can be done manually through the github interface, or via:

git tag -a v0.3.0 -m "<description of version>" e3ee1aeeb69acbacbbcb89d048e18bd352be5111
git push origin v0.3.0

Please sign in to comment.