-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Description
Hey Julianners,
I faced with dimension errors a lot of time during my workflow.
ERROR: LoadError: DimensionMismatch("dimensions must match: a has dims (Base.OneTo(3), Base.OneTo(2)), b has dims (Base.OneTo(3), Base.OneTo(4)), mismatch at 2")
I checked the source code why is this happening and I see this is a little bit too general solution to catch the error in case of Array:
function promote_shape(a::AbstractArray, b::AbstractArray)
promote_shape(axes(a), axes(b))
end
We have the function that could handle the "Array{T}" specific case: promote_shape(size(a), size(b))
We had a open discussion about this here: julia discourse on promote_shape
I would ask if it is possible to change the code to this which is cleaner and has better prompt, also it is considered a little bit faster at compilation even if it is minor:
function promote_shape(a::Array{A}, b::Array{B}) where {A,B}
promote_shape(size(a), size(b))
end
function promote_shape(a::AbstractArray, b::AbstractArray)
promote_shape(axes(a), axes(b))
end
the error from this: ERROR: LoadError: DimensionMismatch("dimensions must match: a has dims (Base.OneTo(3), Base.OneTo(2)), b has dims (Base.OneTo(3), Base.OneTo(4)), mismatch at 2")
to this: ERROR: LoadError: DimensionMismatch("dimensions must match: a has dims (3, 2), b has dims (3, 4)")
I think it is cleaner and help each new developer to handle dimension problems more easily.
To reproduce the issue:
q=randn(3,4)
p=randn(3,2)
p+q