I recently implemented a similar transformation for array-like objects 
<https://github.com/tlycken/Interpolations.jl/pull/47>, in which I decided 
to create functions bounds(A, dim) = (lbound(A, dim), ubound(A, dim)) which 
return the end points of the indexing axes; without those, it was really 
hard to deduce what indices things should map to.

It might be that these should actually be included in Base and used by the 
colon indexing implementation for AbstractArrays (bounds(A, dim) = (1, 
size(A, dim)) for all Arrays, so could probably be inlined at no runtime 
cost). If so, you could use them too and have your FArray type return e.g. (-2, 
8), which would allow the default colon indexing implementation to Just 
Work™.

// T

On Monday, September 21, 2015 at 9:54:38 AM UTC+2, Mauro wrote:

I seem to recall that this was discussed recently, probably by Matt, but 
> cannot find it.  I did however find this gist: 
> https://gist.github.com/alsam/8283205, maybe of help. 
>
>
> On Mon, 2015-09-21 at 06:38, 'Greg Plowman' via julia-users <
> julia...@googlegroups.com <javascript:>> wrote: 
> > To further clarify, I thought I could specialise getindex / setindex! on 
> colon 
> > type argument. 
> > 
> > see below, getindex2 is being called, but getindex is not being called. 
> > A[:] calls getindex(A::AbstractArray{T,N},I::AbstractArray{T,N}) at 
> > abstractarray.jl:380 
> > presumably after [:] has been converted to [1:8] 
> > 
> > 
> > 
> > julia> getindex(A::FArray, ::Colon) = A[start(A) : endof(A)] 
> > getindex (generic function with 177 methods) 
> > 
> > julia> getindex2(A::FArray, ::Colon) = A[start(A) : endof(A)] 
> > getindex2 (generic function with 1 method) 
> > 
> > julia> A = FZeros(Int, -2:8) 
> > 11-element FArray{Int64,1} (-2:8,) 
> > 
> > julia> A[:] 
> > 8-element Array{Int64,1}: 
> >  0 
> >  0 
> >  0 
> >  0 
> >  0 
> >  0 
> >  0 
> >  0 
> > 
> > julia> @which A[:] 
> > getindex(A::AbstractArray{T,N},I::AbstractArray{T,N}) at 
> > abstractarray.jl:380 
> > 
> > julia> getindex2(A, :) 
> > 11-element Array{Int64,1}: 
> >  0 
> >  0 
> >  0 
> >  0 
> >  0 
> >  0 
> >  0 
> >  0 
> >  0 
> >  0 
> >  0 
> > 
> > julia> 
>
> ​

Reply via email to