-
-
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
Array isapprox behavior when the norm is NaN #17650
Comments
If you look at an array as a collection of random stuff then element-wise seems sensible. If you look at an array as an element of a vector space then Maybe there should be |
will we get that automatically from #17623? |
@KristofferC Definitely a good point. I don't see why checking for exact equality in an approximate comparison when the vector norm is |
That seems reasonable to me. |
Okay, cool! Thanks so much for the feedback, @KristofferC, I appreciate it. If there's support for that approach then I can put together a PR. I'd be interested to hear from @stevengj and @timholy too. |
The question in any approximate comparison is "small difference compared to what?" For almost any function that produces a vector, elementwise isapprox is too strong a condition, and some kind of vector norm is more appropriate. For example, imagine comparing ifft(fft(x)) to x when one of the elements of x is zero. It's not completely clear what you want to do if one of the elements is Inf; maybe there is no good default here. If you want elementwise isapprox, very soon (in 0.6) you'll be able to use all(...) with the dotted isapprox operator. |
And it should already work now as |
Yes |
Not as strong as |
Fair enough, as a fallback it wouldn't be terrible. |
Do you think it at least makes more sense as a fallback than |
Yeah, sure. |
Okay, I'll put together a PR then. Thanks for your help, @stevengj, I appreciate it! |
When using
isapprox
to compare arrays, the current definition, introduced in #12472, seems to have some (IMHO) unideal behavior in the presence ofNaN
s:This is how
isapprox
is currently defined for arrays:Whenever
norm
evaluates toNaN
, which happens for example whenx
andy
both haveInf
in a corresponding index, the comparison falls back to checking exact equality using==
. That will be false if there are finite, approximately equal floating point values in other corresponding indices inx
andy
. This is causing a test failure in HypothesisTests.jl.@stevengj was against checking approximate equality element-wise for arrays but I'm not entirely clear on why. Is there anything that can or should be changed in the current implementation, or is there some other way I can get around the test failure?
The text was updated successfully, but these errors were encountered: