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