AxisIndices.jl icon indicating copy to clipboard operation
AxisIndices.jl copied to clipboard

Problem with definition of `similar`

Open grahamas opened this issue 4 years ago • 1 comments

Currently (maybe nothing; something is very wrong):

  • Fixes precompilation error arising from ambiguous dispatch (has a formal name that I forget, but basically when two methods only differ in argument types ::Tuple{AbstractType1} and ::Tuple{AbstractType2} where AbstractType1 <: AbstractType2 so you think one supersedes the other, but what you really want is ::Tuple{<:AbstractType1} and ::Tuple{<:AbstractType2} to make the dispatch system happy)

Want:

  • to fix #62

grahamas avatar Jan 08 '21 18:01 grahamas

I've "fixed" the problem. But I'm overriding a function in Base without understanding why it acts the way it does. In Base, base/abstractarray.jl:753 defines to_shape(r::AbstractUnitRange) = r, but I don't understand why it's that way instead of to_shape(r::AbstractUnitRange) = length(r).

I probably don't understand this because I don't understand when a base array would ever try to use AbstractUnitArray in the dims argument. In fact, when I try to use Base's definition of this method via similar (via similar(Array{Float64}, 1:3, 1:4)), I get a MethodError. I'm evidently missing something veeeery obvious, because one of the "closest candidates" is similar(::Type{T}, ::Union{Integer, AbstractUnitRange}...) where T<:AbstractArray at abstractarray.jl:777.

grahamas avatar Jan 08 '21 22:01 grahamas