Skip to content

isapprox with nans keyword (issue 19936)#20022

Merged
tkelman merged 15 commits intoJuliaLang:masterfrom
JeffreySarnoff:js/isapprox
Jan 14, 2017
Merged

isapprox with nans keyword (issue 19936)#20022
tkelman merged 15 commits intoJuliaLang:masterfrom
JeffreySarnoff:js/isapprox

Conversation

@JeffreySarnoff
Copy link
Copy Markdown
Contributor

No description provided.

Copy link
Copy Markdown
Member

@StefanKarpinski StefanKarpinski left a 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
Copy link
Copy Markdown
Member

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)
Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown
Contributor Author

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`.
Copy link
Copy Markdown
Contributor

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?

Copy link
Copy Markdown
Contributor

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
Copy link
Copy Markdown
Contributor

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

@StefanKarpinski
Copy link
Copy Markdown
Member

There's some trailing whitespace added here, otherwise it looks good!

@StefanKarpinski
Copy link
Copy Markdown
Member

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.

@JeffreySarnoff
Copy link
Copy Markdown
Contributor Author

JeffreySarnoff commented Jan 13, 2017 via email

@StefanKarpinski
Copy link
Copy Markdown
Member

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)))
Copy link
Copy Markdown
Contributor

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?

Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor Author

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?

@StefanKarpinski
Copy link
Copy Markdown
Member

Introduces trailing white space, which is a failure.

@JeffreySarnoff
Copy link
Copy Markdown
Contributor Author

JeffreySarnoff commented Jan 14, 2017 via email

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
Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should do it .

@test [0,Inf] ≈ [0,Inf]
@test [0,Inf] ≉ [0,-Inf]

# issue #19936
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also trailing whitespace here

@test [0,Inf] ≈ [0,Inf]
@test [0,Inf] ≉ [0,-Inf]

# issue #19936
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also trailing whitespace here

Copy link
Copy Markdown
Contributor

@tkelman tkelman left a 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

@tkelman tkelman merged commit 2680a01 into JuliaLang:master Jan 14, 2017
@JeffreySarnoff JeffreySarnoff deleted the js/isapprox branch January 14, 2017 21:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants