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

Add single argument version of isapprox #32305

Merged
merged 10 commits into from
Jan 31, 2020
Merged

Add single argument version of isapprox #32305

merged 10 commits into from
Jan 31, 2020

Conversation

asinghvi17
Copy link
Contributor

Adds a single argument version of isapprox or ≈, in the same vein as the single argument version of ==.

@asinghvi17
Copy link
Contributor Author

@fredrikekre, why are you confused?

Copy link
Sponsor 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.

Looks good to me. Could you add some tests and a NEWS entry?

asinghvi17 and others added 3 commits June 14, 2019 09:51
Adds a single argument version of isapprox or ≈, in the same vein as the single argument version of `==`.
NEWS.md Outdated Show resolved Hide resolved

Create a function that compares its argument to x using ≈, i.e. a function equivalent to y -> y ≈ x.

The keyword arguments supported here are the same as those in [`isapprox`](@ref).
Copy link
Member

Choose a reason for hiding this comment

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

The Documenter ref there is self-referential. Probably doesn't matter a whole lot, but you could have it point to the other method specifically.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How do you do that - with the method signature? So something like [\isapprox(1, 2)`]`?

Copy link
Member

Choose a reason for hiding this comment

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

I'm not 100% on the syntax, but I think it'd be something like

[`isapprox`](@ref Base.isapprox(::Any, ::Any))

You'd probably want to build the documentation locally to verify.

Copy link
Sponsor Member

Choose a reason for hiding this comment

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

Or just say "The keyword arguments supported are the same as those in 2-argument isapprox."

base/floatfuncs.jl Outdated Show resolved Hide resolved
test/floatfuncs.jl Outdated Show resolved Hide resolved
asinghvi17 and others added 2 commits June 17, 2019 05:36
Co-Authored-By: Alex Arslan <[email protected]>
@asinghvi17
Copy link
Contributor Author

Thanks for the review, @ararslan!

NEWS.md Outdated Show resolved Hide resolved
@nickrobinson251
Copy link
Contributor

I'm surprised not to find this pattern - like all(≈(x), xs) - in the base test code more. A quick search suggested it is only used once

@test all(x->x 10.0, ratio(collect(ExponentialBackOff(n=10, max_delay=Inf, factor=10, jitter=0.0))))

@codecov-io
Copy link

Codecov Report

❗ No coverage uploaded for pull request base (master@7e7a30f). Click here to learn what that means.
The diff coverage is 84.09%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master   #32305   +/-   ##
=========================================
  Coverage          ?   75.74%           
=========================================
  Files             ?      380           
  Lines             ?    66442           
  Branches          ?        0           
=========================================
  Hits              ?    50326           
  Misses            ?    16116           
  Partials          ?        0
Impacted Files Coverage Δ
base/util.jl 48.72% <ø> (ø)
base/coreio.jl 50% <ø> (ø)
base/operators.jl 87.7% <ø> (ø)
base/initdefs.jl 54.95% <ø> (ø)
base/deprecated.jl 9.3% <ø> (ø)
base/refpointer.jl 65.9% <ø> (ø)
base/special/log.jl 94.95% <ø> (ø)
base/sort.jl 94.25% <ø> (ø)
base/logging.jl 87.66% <ø> (ø)
base/grisu/grisu.jl 16.82% <ø> (ø)
... and 81 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7e7a30f...52f93fa. Read the comment docs.

Copy link
Contributor

@nickrobinson251 nickrobinson251 left a comment

Choose a reason for hiding this comment

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

thanks! I would find this useful :)

Is there any reason not to use the Fix2 machinery, same as with isequal?

NEWS.md Outdated Show resolved Hide resolved
base/floatfuncs.jl Show resolved Hide resolved
Co-Authored-By: Nick Robinson <[email protected]>
@StefanKarpinski StefanKarpinski added the status:triage This should be discussed on a triage call label Nov 27, 2019
@StefanKarpinski
Copy link
Sponsor Member

StefanKarpinski commented Jan 30, 2020

I'm surprised not to find this pattern - like all(≈(x), xs) - in the base test code more.

If the intention is approximate numerical equality, then x ≈ xs is more appropriate as well as more convenient: it checks that norm(x .- xs) is less than an appropriate error bound.

@JeffBezanson
Copy link
Sponsor Member

Ready to merge.

@nickrobinson251
Copy link
Contributor

If the intention is approximate numerical equality, then x ≈ xs is more appropriate as well as more convenient: it checks that norm(x .- xs) is less than an appropriate error bound.

Thanks. Good point :) Somewhat off topic here (sorry), but I was thinking of the case where x is scalar, xs is Vector (in which case x ≈ xs is a MethodError, and all(≈(x), xs) may be what one wants).

@JeffBezanson JeffBezanson merged commit ab5b40a into JuliaLang:master Jan 31, 2020
@asinghvi17 asinghvi17 deleted the patch-1 branch January 31, 2020 19:29
@Keno Keno removed the status:triage This should be discussed on a triage call label Feb 27, 2020
KristofferC pushed a commit that referenced this pull request Apr 11, 2020
Adds a single argument version of isapprox or ≈, in the same vein as the single argument version of `==`.
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.

None yet

8 participants