nolta/Calendar.jl

Ambiguous method definition for -()

Closed this issue · 5 comments

Since a few days I get the following warning when using Calendar. Could you please take a look, I am not sure what the best solution is.

cc @jiahao, as I believe you know the code in diagonal.jl well

Thanks!

Warning: New definition 
    -(AbstractArray{T1<:Union(AbstractCalendarDuration,CalendarTime),N},AbstractArray{T2<:Union(AbstractCalendarDuration,CalendarTime),N}) at operators.jl:318
is ambiguous with: 
    -(Diagonal{T},AbstractArray{T,2}) at linalg/diagonal.jl:26.
To fix, define 
    -(Diagonal{_<:Union(AbstractCalendarDuration,CalendarTime)},AbstractArray{_<:Union(AbstractCalendarDuration,CalendarTime),2})
before the new definition.
Warning: New definition 
    -(AbstractArray{T1<:Union(AbstractCalendarDuration,CalendarTime),N},AbstractArray{T2<:Union(AbstractCalendarDuration,CalendarTime),N}) at operators.jl:318
is ambiguous with: 
    -(AbstractArray{T,2},Diagonal{T}) at linalg/diagonal.jl:27.
To fix, define 
    -(AbstractArray{_<:Union(AbstractCalendarDuration,CalendarTime),2},Diagonal{_<:Union(AbstractCalendarDuration,CalendarTime)})
before the new definition.
Warning: New definition 
    -(AbstractArray{T1<:CalendarTime,N},AbstractArray{T2<:CalendarTime,N}) at operators.jl:318
is ambiguous with: 
    -(Diagonal{T},AbstractArray{T,2}) at linalg/diagonal.jl:26.
To fix, define 
    -(Diagonal{_<:CalendarTime},AbstractArray{_<:CalendarTime,2})
before the new definition.
Warning: New definition 
    -(AbstractArray{T1<:CalendarTime,N},AbstractArray{T2<:CalendarTime,N}) at operators.jl:318
is ambiguous with: 
    -(AbstractArray{T,2},Diagonal{T}) at linalg/diagonal.jl:27.
To fix, define 
    -(AbstractArray{_<:CalendarTime,2},Diagonal{_<:CalendarTime})
before the new definition.

I recently added -{T}(D::Diagonal{T}, M::AbstractMatrix{T}) and -{T}(M::AbstractMatrix{T}, D::Diagonal{T}) methods, as it was previously not possible to do matrix subtraction directly when one of the matrices is Diagonal.

If you edit base/linalg/diagonal.jl and replace on lines 26 and 27 AbstractMatrix with Matrix, does that remove the ambiguity warnings?

Yes, that fixes it! And make test for Julia passes.

Ok, I will go ahead and make that change.

Cross-referencing relevant julia-users discussion.

Should be resolved by JuliaLang/julia@a448e08