isapprox with nans keyword (issue 19936)#20022
isapprox with nans keyword (issue 19936)#20022tkelman merged 15 commits intoJuliaLang:masterfrom JeffreySarnoff:js/isapprox
Conversation
StefanKarpinski
left a comment
There was a problem hiding this comment.
Maybe add a test for isapprox over arrays containing NaNs too?
test/floatfuncs.jl
Outdated
| for nan in (Float16,Float32,Float64) | ||
| nan = elty(NaN) | ||
| @test isapprox(nan, nan) == false | ||
| @test isapprox(nan, nan, nans=true) == true7 |
test/floatfuncs.jl
Outdated
|
|
||
| # isapprox | ||
| for nan in (Float16,Float32,Float64) | ||
| nan = elty(NaN) |
There was a problem hiding this comment.
I don't think these tests mean what you want them to mean anymore.
base/floatfuncs.jl
Outdated
| 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.
describe what the keyword argument does before saying what its default is?
There was a problem hiding this comment.
How about "Keyword argument nans (defaults to false) determines whether or not NaN values are considered equal to one another." ?
test/floatfuncs.jl
Outdated
| 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.
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. |
base/floatfuncs.jl
Outdated
| 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.
are there cases where it's faster to not short-circuit?
There was a problem hiding this comment.
I don't think this is a particularly performance-critical operation.
There was a problem hiding this comment.
almost certainly isn't, may as well be consistent with the other comparisons in this condition
There was a problem hiding this comment.
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>
.
|
base/linalg/uniformscaling.jl
Outdated
| 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.
there's trailing whitespace here (you can find these with make check-whitespace locally), otherwise lgtm
There was a problem hiding this comment.
That should do it .
test/floatapprox.jl
Outdated
| @test [0,Inf] ≈ [0,Inf] | ||
| @test [0,Inf] ≉ [0,-Inf] | ||
|
|
||
| # issue #19936 |
There was a problem hiding this comment.
also trailing whitespace here
test/floatapprox.jl
Outdated
| @test [0,Inf] ≈ [0,Inf] | ||
| @test [0,Inf] ≉ [0,-Inf] | ||
|
|
||
| # issue #19936 |
There was a problem hiding this comment.
also trailing whitespace here
tkelman
left a comment
There was a problem hiding this comment.
should be squashed on merge
No description provided.