Hi Greg, This doesn’t answer your question directly, but I recommend you check out the Interfaces <http://docs.julialang.org/en/latest/manual/interfaces/#indexing> chapter of the manual for some good info on creating your own array type. To get indexing working the most important parts are:
1. subtype AbstractArray 2. implement the Base.linearindexing(Type) method 3. implement either getindex(A, i::Int) or getindex(A, i1::Int, ..., iN::Int), (and the setindex! versions) depending on step 2. Then the various indexing behaviors (ranges, etc.) should work for your type, as under-the-hood they boil down to the more basic indexing method that you define in step 3. One thing to note that’s not spelled out super clearly in the manual yet is that if you want the results of range indexing to be wrapped in your type, you should also implement `similar`. There’s some more details on that in this pr <https://github.com/JuliaLang/julia/pull/13212/files>. OT: something about the way your email client is configured is causing you to show up as [email protected] <mailto:[email protected]> where for other users I see their names (at least in my email client), so it’s a bit hard to see who you are in lists of thread participant names. -s > On Sep 20, 2015, at 9:34 PM, 'Greg Plowman' via julia-users > <[email protected]> wrote: > > Hi, > > I'm trying to define a custom Array type that can be indexed using arbitrary > ranges. > > e.g. A = MyArray(Int, 3:8) would define a 6-element vector with indexes > ranging from 3 to 8, rather than the default 1 to 6. > > I've made some progress, but am now stuck on how to handle colon indexing. > > A[4:6] works by defining appropriate getindex and setindex! > > e.g. setindex!{T,S<:Real}(A::MyArray{T,1}, value, I::AbstractVector{S}) = ... > > but A[:] = 0 seems to get translated to A[1:6] before dispatch on setindex!, > so I can't hijack the call. > > From subarray.jl, the code below suggests I can specialise on the Colon type, > but this doesn't seem to work for me. Colon appears to be converted to > UnitRange before calling setindex! > > sub(A::AbstractArray, I::Union(RangeIndex, Colon)...) = sub(A, > ntuple(length(I), i-> isa(I[i], Colon) ? (1:size(A,i)) : I[i])...) > > > Is there a way around this? > Should I be able to specialise on the colon argument? > > -- Greg
