Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RFC: Immediately return true for equality checks if is(A,B)
Perhaps I'm missing something but why not immediately return true from these checks if the two objects are identical? If this is valid there are likely other places this could happen too...but I thought I would first check. Thanks, Glen
- Loading branch information
f1cdc93
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There do exist cases where
is
does not imply==
:f1cdc93
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, that's a good point. NaNs are the only case where
==
is stricter than any other comparison.f1cdc93
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IEEE 754 specifies that
NaN
is NOT equal to itself. Therefore any array that containsNaN
is not equal to itself.f1cdc93
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For numeric correctness, I think we should revert this commit.
f1cdc93
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it depends if
Array == Array
is checking that the arrays are equal or is it checking if all the elements are the elements inside the array are equal? This isn't an element-wise check so I would argue that it is checking if the arrays are equal (not element by element). For the other case you could useall(A .== B)
. If NaNs bubble up then any composite type that has a NaN would compare false against itself -- that sounds hard to stomach. This change doesn't change the meaning of how two NaNs are compared. Thoughts?f1cdc93
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only thing that seems justifiable is that
A == B
means the same thing asall(A .== B)
but short circuits. I don't see that arrays containing NaNs being self-non-equal is any worse than NaNs being self-non-equal in the first place. As for composite types, I think those should really not be defined by default in general (see #4648). If you want to check array equality, you should useisequal
instead.f1cdc93
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think that's OK since usually an array of numbers is itself considered a numeric object. Other containers might be a bit different, for instance:
I'd say this is correct, since
isequal
is all that matters for dict keys, but==
would be expected to call itself for contained values.