-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
numeric equality ignoring type with NaNs equal #5314
Comments
The whole issue can be reduced to the fact that there's no equality operation such that julia> NaN == NaN32
false
julia> isequal(NaN,NaN32)
false
julia> NaN === NaN32
false |
Maybe we should try again here. We could have every type generally implement
It would be nice for Also, I'm not sure it's necessary for every data structure to have |
Fucking |
That's what makes me want to push NaN into a corner where it only matters for Most operations that can give NaN should throw errors instead; the only problem is performance-critical functions like Then there is also the issue of signed zero. Switching briefly to ordering, some other types, like sets, also have a canonical strictly-partial order. Currently |
FWIW, MATLAB has a function Reference: http://www.mathworks.com/help/matlab/ref/isequaln.html |
@lindahua I believe we had that function for a while (I may have even added it). It may also have been renamed. I seem to recall a discussion along those lines. |
This function doesn't live in Julia base though. |
Yeah, it didn't make the transition out of |
|
If a=[1.0, NaN] and == is changed to call isequal elementwise and isequal is changed to become true on NaNs, then a==a != all(a.==a) |
Numeric arrays are also fairly "number-like" and so would probably decide to call |
FWIW, there's a very similar issue when dealing with NAs in |
As a side thing, in general, it would be cool if arbitrary data structures The reason is probably that if it the structure were to have circular On Tue, Jan 7, 2014 at 12:50 AM, Milan Bouchet-Valat <
Michael |
Note that it's not just |
That is settled; we're thinking of |
I want to point out that there is no equality predicate that always does what you want. All we can do is provide some reasonable primitives, and in specific cases you must reason about what kind of equality you need. For example, this exact same issue could have been filed about sign bits instead of NaN (a comparison like |
Perhaps |
How does this help? isequal(Complex(1e0,1e0),Complex(1f0,1f0)) ==> false
isequal(Complex(NaN,NaN),Complex(NaN32,NaN32)) ==> true Clearly you can't satisfy everyone, but this is a case that is particularly nasty to express generically. The more I think about it, the more I think that making I also think this is bit of a mistake: julia> 1 == "foo"
false
julia> 1 < "foo"
ERROR: no method isless(ASCIIString, Int64)
in < at operators.jl:18 It seems to me that |
I do think there is a non-arbitrary intermediate between It's really helpful for |
Unfortunately, that definition is not at all what people expect hashing to do. To play devil's advocate, currently it's unclear whether you should write |
I agree that one can argue that definition is not useful. The first example I always think of is that string encoding shouldn't matter for hash keys. But for numeric types I'm not so sure. It's a tough call. It is always nice to trap questionable operations like comparing totally unrelated things, but (1) a lot of people want to just use |
I think that not defining |
Fair enough. That's really a tangential issue. |
Fixed by #6624 |
One thing I find highly objectionable about the current state of affairs with
==
,isequal
and===
is that there is no way to compare numeric values of different types so that type doesn't matter and NaNs are equal. I was trying to do this test of the fidelity of thea + b*im
construct on mysk/imaginary
branch and there's just no obvious way to check thata + b*im
andComplex(a,b)
are the same value even if they are different types, wherea
and/orb
may beNaN
.The text was updated successfully, but these errors were encountered: