-
-
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
isapprox with nans keyword (issue 19936) #20022
Conversation
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.
Maybe add a test for isapprox over arrays containing NaNs too?
for nan in (Float16,Float32,Float64) | ||
nan = elty(NaN) | ||
@test isapprox(nan, nan) == false | ||
@test isapprox(nan, nan, nans=true) == true7 |
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.
typo:true7
?
|
||
# isapprox | ||
for nan in (Float16,Float32,Float64) | ||
nan = elty(NaN) |
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 don't think these tests mean what you want them to mean anymore.
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.
oops
|
||
Inexact equality comparison: `true` if `norm(x-y) <= atol + rtol*max(norm(x), norm(y))`. The | ||
default `atol` is zero and the default `rtol` depends on the types of `x` and `y`. | ||
default `atol` is zero and the default `rtol` depends on the types of `x` and `y`. The default | ||
`nans` is false, meaning `isapprox(NaN,NaN) == false`; call with `nans=true` to have `isapprox(NaN,NaN) == true`. |
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.
describe what the keyword argument does before saying what its default is?
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.
How about "Keyword argument nans
(defaults to false) determines whether or not NaN
values are considered equal to one another." ?
for elty in (Float16,Float32,Float64) | ||
nan = elty(NaN) | ||
half = elty(0.5) | ||
@test isapprox(nan, nan) == false |
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'd just @test !isapprox(nan, nan)
instead of comparing to true/false
There's some trailing whitespace added here, otherwise it looks good! |
I would not add a new test file unless there are a lot of tests. You've also forgotten to git add the test file. |
That test file already existed -- I just found it
https://github.com/JeffreySarnoff/julia/edit/js/isapprox/test/floatapprox.jl
…On Fri, Jan 13, 2017 at 6:37 PM, Stefan Karpinski ***@***.***> wrote:
I would not add a new test file unless there are a lot of tests. You've
also forgotten to git add the test file.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#20022 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABmqxnCd01QGiFgD-Vum9Sathre2RD6Oks5rSAq_gaJpZM4LjVXb>
.
|
Ah, ok. I see you added the tests back now. Carry on. |
function isapprox(x::Number, y::Number; rtol::Real=rtoldefault(x,y), atol::Real=0) | ||
x == y || (isfinite(x) && isfinite(y) && abs(x-y) <= atol + rtol*max(abs(x), abs(y))) | ||
function isapprox(x::Number, y::Number; rtol::Real=rtoldefault(x,y), atol::Real=0, nans::Bool=false) | ||
x == y || (isfinite(x) && isfinite(y) && abs(x-y) <= atol + rtol*max(abs(x), abs(y))) || (nans && (isnan(x) & isnan(y))) |
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.
are there cases where it's faster to not short-circuit?
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 don't think this is a particularly performance-critical operation.
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.
almost certainly isn't, may as well be consistent with the other comparisons in this condition
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.
what do you suggest doing?
Introduces trailing white space, which is a failure. |
do you mean (nans && isnan(x) && isnan(y))?
…On Fri, Jan 13, 2017 at 10:03 PM, Tony Kelman ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In base/floatfuncs.jl <#20022>:
> @@ -188,8 +189,8 @@ approximately equal component-wise.
The binary operator `≈` is equivalent to `isapprox` with the default arguments, and `x ≉ y`
is equivalent to `!isapprox(x,y)`.
"""
-function isapprox(x::Number, y::Number; rtol::Real=rtoldefault(x,y), atol::Real=0)
- x == y || (isfinite(x) && isfinite(y) && abs(x-y) <= atol + rtol*max(abs(x), abs(y)))
+function isapprox(x::Number, y::Number; rtol::Real=rtoldefault(x,y), atol::Real=0, nans::Bool=false)
+ x == y || (isfinite(x) && isfinite(y) && abs(x-y) <= atol + rtol*max(abs(x), abs(y))) || (nans && (isnan(x) & isnan(y)))
almost certainly isn't, may as well be consistent with the other
comparisons in this condition
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#20022>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABmqxmfJ8oOg-ErmQkhBCn9PrBprsg1Hks5rSDrzgaJpZM4LjVXb>
.
|
function isapprox{T<:Number,S<:Number}(J1::UniformScaling{T}, J2::UniformScaling{S}; | ||
rtol::Real=Base.rtoldefault(T,S), atol::Real=0, nans::Bool=false) | ||
isapprox(J1.λ, J2.λ, rtol=rtol, atol=atol, nans=nans) | ||
end |
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's trailing whitespace here (you can find these with make check-whitespace
locally), otherwise lgtm
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.
That should do it .
@@ -59,3 +59,13 @@ | |||
@test [0,1] ≈ [1e-9, 1] | |||
@test [0,Inf] ≈ [0,Inf] | |||
@test [0,Inf] ≉ [0,-Inf] | |||
|
|||
# issue #19936 |
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.
also trailing whitespace here
@@ -59,3 +59,13 @@ | |||
@test [0,1] ≈ [1e-9, 1] | |||
@test [0,Inf] ≈ [0,Inf] | |||
@test [0,Inf] ≉ [0,-Inf] | |||
|
|||
# issue #19936 |
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.
also trailing whitespace here
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.
should be squashed on merge
No description provided.