There is some useful (at least for me) discussion between @marius311 and I on this issue about when equality should hold between things.
It was a little surprising to me that in general A == B
between two arrays always follows from all(A .== B)
regardless of the types of A
and B
. Some examples of this are:
julia> [1 2 3] == [1, 2, 3]'
true
julia> [1, 2] == view([1, 2, 3], 1:2)
true
julia> using StaticArrays
julia> SVector(1, 2, 3) == [1, 2, 3]
true
While I can see where this would be a useful property, it makes things tricky when trying to implement equality for something like ComponentArray
s. It seems obvious that ComponentArray(a=1, b=2) != ComponentArray(x=1, y=2)
. However the whole point of ComponentArray
s is that they need to work in any library that expects an AbstractArray
. Since it seems to be part of the contract of AbstractArray
s that A == B
holds when the the elements of A
and B
are equal, I am hesitant to break from that. I just don’t have any way of guaranteeing that, say, DifferentialEquations.jl or Optim.jl isn’t using A == B
under the hood somewhere. And since hash(A) == hash(B)
needs to hold whenever A == B
, we can’t just implement equality between two dissimilar ComponentArray
s as a separate thing.
I assume equality between arrays (and things in general) has been discussed somewhere before. I would be curious to see the original rationale behind A == B
for arrays when their elements are equal.