On Friday, September 11, 2015 at 3:11:48 AM UTC-4, Leonardo wrote:
>
> I like to have a *unique* type that contains only a specified type and 
> that can handle any dimension, but only during object instancing (not 
> during subsequent lifecycle of object, also if both phases are at runtime), 
> than parametrized dimension (the N in AbstractArray{T,N}) is not useful 
> for me.


You can have a constructor that deals with the parameter for you:

MyArr(number_of_dimensions::Int) = MyArr{Any, number_of_dimensions}()

I'm afraid I still don't understand why you want to do this, so my answers 
probably aren't all that helpful.

But - if I understood your indications - there is no way to do this without 
> redefine a bunch of methods.
> At least, can I find somewhere a minimal list of these methods?
>

That's correct.  Omitting the dimensionality isn't a supported way to 
subtype AbstractArray.  I suppose you can still do it, but being 
unsupported means that you're on your own to figure out what all needs to 
be re-implemented.  And unfortunately, I'm afraid that the list isn't so 
minimal.  It's a part of the AbstractArray definition that is very heavily 
leveraged in the base code to improve performance and specify behavior.

You can start to get a sense of how heavily these parameters are used by 
looking at the methods defined for AbstractArray{T,1} (AbstractVector) and 
AbstractArray{T,2} (AbstractMatrix):

julia> methodswith(AbstractVector)
151-element Array{Method,1}: …

julia> methodswith(AbstractMatrix)
164-element Array{Method,1}: …

Those don't even include methods defined for arbitrary dimensionality but 
still require N to be defined, like `ndims{T,N}(A::AbstractArray{T,N}) = N`.

Reply via email to