-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Closed
Closed
Copy link
Description
The AbstractArray
default ==
operator special-cases ranges:
function (==)(A::AbstractArray, B::AbstractArray)
if size(A) != size(B)
return false
end
if isa(A,Range) != isa(B,Range)
return false
end
for (a, b) in zip(A, B)
if !(a == b)
return false
end
end
return true
end
isequal
is defined in the same way.
This is obviously not great. A new array type is considered as equal to a standard Array
if their elements are all equal, but it is considered as different from a range containing the same elements. This inconsistency is visible even inside Base:
julia> sparse([1,2]) == [1,2]
true
julia> [1,2] == 1:2
false
So it's not clear whether two AbstractArrays
need to be of the same type or not to be ==
. I can see two consistent solutions:
- remove the special-case for ranges (i.e. return
true
when elements are equal) - change
if isa(A,Range) != isa(B,Range)
totypeof(A) !== typeof(B)
The second choice would clearly be much more disruptive than the first, and it would make ==
almost useless for arrays.
Metadata
Metadata
Assignees
Labels
breakingThis change will break codeThis change will break code