Never mind, I have found the solution. The reason is that the type of S is 
restricted in AbstractTensor, and by not restricting S in the methods on 
line 3 and 6, the methods on line 4 and 7 are in some sense more 
restricted, and I guess that's why they were the ones being called. Adding 
S<:IndexSpace to line 3 and 6 fixes the problem.

On a related note, I noticed that even for AbstractArray, one gets
eltype(AbstractArray{Float64,3}) # -> Float64
eltype(AbstractArray{Float64}) # -> Any
because there is no method
eltype{T}(::Type{AbstractArray{T}})
I guess it is not used anywhere, but for completeness, would it be useful 
to add such a method?


Op vrijdag 1 augustus 2014 07:52:44 UTC+2 schreef Jutho:
>
> Dear julia users/developers,
>
> I am working on some toolbox for working with tensors (on a more rigorous 
> level, defined as elements of tensor products of vector spaces; see 
> https://github.com/Jutho/TensorToolbox.jl ), where the first few lines of 
> a new type hierarchy start as follows:
>
> abstract AbstractTensor{S<:IndexSpace,T,N}
> Base.eltype{S,T}(::AbstractTensor{S,T}) = T
> Base.eltype{S,T,N}(::Type{AbstractTensor{S,T,N}}) = T
> Base.eltype{TT<:AbstractTensor}(::Type{TT}) = eltype(super(TT))
> spacetype{S}(::AbstractTensor{S})=S
> spacetype{S,T,N}(::Type{AbstractTensor{S,T,N}})=S
> spacetype{TT<:AbstractTensor}(::Type{TT})=spacetype(super(TT))
>
> similar to some of the first lines in abstractarray.jl. The only 
> difference is that there is an extra parameter. In the method table 
> (methods(eltype) or methods(spacetype)) the order of the methods on line 3 
> and 4 (for eltype) and of line 6 and 7 (for spacetype) is reversed. As a 
> consequence, 
> @which eltype(AbstractTensor{ComplexSpace,Float64,3})
> is caught by line 4 instead of line 3, and returns Any, whereas clearly 
> this should be Float64. Is there anything I do not understand of how this 
> works for AbstractArray and that I am doing differently, or should I file 
> an issue? Is there a way to force the order in which methods are added to 
> the method table?
>
> Thanks,
>
> Jutho
>
>

Reply via email to