The proper way is to do a PeriodicArray type like you said. If you can’t do it yourself yet then you just have to hope someone else does it.
In theory it should be quite simple, you just have to overload size, getindex and setindex! (c.f. https://docs.julialang.org/en/release-0.5/manual/interfaces/#indexing), but in practice it can get a bit complicated - like in the FFTViews case - when you do the general case and you want optimal performance.
getindex is the function that get called when you do x[1] (x[1] is the same as getindex(x,1)). setindex is the same thing for x[1] = pi (it calls setindex!(x,pi,1)). So all you need to do is to transform the index with a modulo to make it periodic.
I made a minimal implementation for 1D arrays, it seems to work, but it’s probably not very good:
module tmp
immutable CircularArray{T} <: AbstractArray{T,1}
data::AbstractArray{T,1}
end
circindex(i::Int,N::Int) = 1 + mod(i-1,N)
circindex(I,N::Int) = [circindex(i,N)::Int for i in I]
Base.size(A::CircularArray) = size(A.data)
Base.getindex(A::CircularArray, i::Int) = getindex(A.data, circindex(i,length(A.data)))
Base.getindex(A::CircularArray, I) = getindex(A.data, circindex(I,length(A.data)))
Base.setindex!(A::CircularArray, v, i::Int) = setindex!(A.data, v, circindex(i,length(A.data)))
Base.setindex!(A::CircularArray, v, I) = setindex!(A.data, v, circindex(I,length(A.data)))
end
c = tmp.CircularArray(rand(10))
@assert c[11] == c[1]
@assert c[-9:0] == c[1:10]