Skip to content
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

Merged
merged 15 commits into from
Jan 14, 2017
Merged

isapprox with nans keyword (issue 19936) #20022

merged 15 commits into from
Jan 14, 2017

Conversation

JeffreySarnoff
Copy link
Contributor

No description provided.

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

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

@StefanKarpinski
Copy link
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
Contributor Author

JeffreySarnoff commented Jan 13, 2017 via email

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

Introduces trailing white space, which is a failure.

@JeffreySarnoff
Copy link
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
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
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 .

@@ -59,3 +59,13 @@
@test [0,1] ≈ [1e-9, 1]
@test [0,Inf] ≈ [0,Inf]
@test [0,Inf] ≉ [0,-Inf]

# issue #19936
Copy link
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

@@ -59,3 +59,13 @@
@test [0,1] ≈ [1e-9, 1]
@test [0,Inf] ≈ [0,Inf]
@test [0,Inf] ≉ [0,-Inf]

# issue #19936
Copy link
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
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