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 documentation about failure cases of trig functions & return types #50855

Merged
merged 5 commits into from Feb 29, 2024

Conversation

Seelengrab
Copy link
Contributor

@Seelengrab Seelengrab commented Aug 9, 2023

This documents the failure cases of various trigonometric functions provided in Base, but is not exhaustive. In particular, there are still undocumented failure cases of the versions of these functions taking matrices, but this can be added at a later date. The failure cases where found with PropCheck.jl, checking if the property x -> f(x) isa T for the functions f in question and the types (Int8, Int16, Int32, Int64, Float16, Float32, Float64) holds (i.e., doesn't error and returns true). I can give a script reproducing the failures if requested.

I'd expect CI to be happy, unless someone somewhere is checking for the exact error message when a DomainError is thrown - some of the functions in here had a really bare bones error message, which I've also aligned with the formulation we use in other places.

I'm not 100% sure who best to review this, but since I know @oscardssmith and @stevengj have done plenty of numeric work on these functions in the past, have a ping :)

@Seelengrab Seelengrab added domain:docs This change adds or pertains to documentation domain:maths Mathematical functions domain:display and printing Aesthetics and correctness of printed representations of objects. labels Aug 9, 2023
@Seelengrab
Copy link
Contributor Author

Seelengrab commented Aug 9, 2023

The failures seem to be due to timeouts & some build cache failure, so should be unrelated to the doc change here.

@oscardssmith
Copy link
Member

This looks good to me.

base/special/trig.jl Outdated Show resolved Hide resolved
base/math.jl Outdated Show resolved Hide resolved
base/math.jl Outdated Show resolved Hide resolved
base/math.jl Outdated
@@ -488,10 +492,12 @@ asinh(x::Number)

# functions that return NaN on non-NaN argument for domain error
"""
sin(x)
sin(x::T) where T <: Number -> float(T)
Copy link
Member

Choose a reason for hiding this comment

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

I understand the rationale for writing it this way but IMO this is somewhat confusing to visually parse. I think something like

Suggested change
sin(x::T) where T <: Number -> float(T)
sin(x::Number) -> float(typeof(x))

would read a bit nicer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wrote it this way for consistency with the other functions, as well as for using the same T in the description of NaN behavior. We do also explicitly document the float(T) type version.

Copy link
Member

Choose a reason for hiding this comment

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

consistency with the other functions

Which other functions? AFAICT only getipaddr and getipaddrs have their method signature as shown in the docs written this way:

$ sift -e '\bwhere \w+\s*<:\s*\w+\s*->'
stdlib/Sockets/src/addrinfo.jl:246:    getipaddr(addr_type::Type{T}) where T<:IPAddr -> T
stdlib/Sockets/src/addrinfo.jl:280:    getipaddrs(addr_type::Type{T}=IPAddr; loopback::Bool=false) where T<:IPAddr -> Vector{T}

My original comment was intended to apply to all additions in this PR rather than just this particular one; apologies, I should have made that clear.

If the where is necessary then I think this minor reformatting would be easier would be easier to visually parse as it makes the logical grouping clearer:

Suggested change
sin(x::T) where T <: Number -> float(T)
sin(x::T) where {T<:Number} -> float(T)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's also givens and isascii, buit both of those use the curly braces version:

[sukera@tower julia]$ rg '\bwhere [\w\s<:{}]+->'
stdlib/Sockets/src/addrinfo.jl
246:    getipaddr(addr_type::Type{T}) where T<:IPAddr -> T
280:    getipaddrs(addr_type::Type{T}=IPAddr; loopback::Bool=false) where T<:IPAddr -> Vector{T}

stdlib/LinearAlgebra/src/givens.jl
270:    givens(f::T, g::T, i1::Integer, i2::Integer) where {T} -> (G::Givens, r::T)

base/strings/basic.jl
632:    isascii(cu::AbstractVector{CU}) where {CU <: Integer} -> Bool

I'll add the curly braces, so these are easier to visually distinguish from the intended return type.

Copy link
Member

Choose a reason for hiding this comment

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

I was going to make the same comment about the fact that the where syntax is quite heavy to read and hides the most useful information. I'd also find it better to use -> float(typeof(x)).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removing the T entirely will make it confusing where the T in T(NaN) came from further below in the docstring though.

base/math.jl Outdated Show resolved Hide resolved
@Seelengrab
Copy link
Contributor Author

The one non-"Allowed to fail" failure was a timeout in apple. Seems unrelated, though still bad..

@Krastanov
Copy link

Is this good to merge?

@oscardssmith
Copy link
Member

I think so

@Seelengrab
Copy link
Contributor Author

I'd wait on feedback regarding the missing discussion above - it is a bit weird to only call it out for one method, though adding missing support for everything else in this PR too seems a bit orthogonal.

@Seelengrab
Copy link
Contributor Author

Seelengrab commented Jan 30, 2024

Based on the thread above, I've removed the mention of missing from the one function I originally added it to, so that the missing behavior can be decided seperately from this doc improvement.

I've also rebased this onto the current master, so unless CI breaks things, please let me know if there is anything else that needs to be done.

@nsajko
Copy link
Contributor

nsajko commented Jan 30, 2024

I think something went wrong with the rebase: the Web UI says that there are conflicts that must be resolved, and it seems most of the commits now don't really belong to this PR?

@Seelengrab
Copy link
Contributor Author

Oh dear, that shouldn't have happened - let me fix that.

@Seelengrab
Copy link
Contributor Author

Fixed, thank you @nsajko for pointing it out!

@DilumAluthge DilumAluthge removed the request for review from a team January 30, 2024 14:14
@Seelengrab
Copy link
Contributor Author

This PR only touches docs, failures seem completely unrelated.

@Seelengrab
Copy link
Contributor Author

Rebased, since there were conflicts with master. I think this is good to go as-is, but there are still some unresolved comments about whether or not T should be used in the docstrings. Once those are decided upon (@nalimilan or @ararslan, since you had comments), this should be good to merge.

@oscardssmith oscardssmith added the status:merge me PR is reviewed. Merge when all tests are passing label Feb 27, 2024
Copy link
Sponsor Member

@inkydragon inkydragon left a comment

Choose a reason for hiding this comment

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

Fix whitespace

base/math.jl Outdated Show resolved Hide resolved
base/math.jl Outdated Show resolved Hide resolved
@IanButterworth IanButterworth merged commit fbcc99a into JuliaLang:master Feb 29, 2024
7 checks passed
@inkydragon inkydragon removed the status:merge me PR is reviewed. Merge when all tests are passing label Mar 1, 2024
# double-double numbers and returns the high double. References:
# [1] https://www.digizeitschriften.de/en/dms/img/?PID=GDZPPN001170007
# double-double numbers and return the high double. References:
# [1] http://www.digizeitschriften.de/en/dms/img/?PID=GDZPPN001170007
Copy link
Contributor

Choose a reason for hiding this comment

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

Was the 's' accidentally removed? The website works with https for me.

Copy link
Contributor Author

@Seelengrab Seelengrab Mar 1, 2024

Choose a reason for hiding this comment

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

Thanks for mentioning this! It did not work for me at the time of writing that commit; since that was more than half a year ago, things might have been fixed since then (an unfortunate sideeffect of PRs lingering). Note that the DOI link below still has its https protocol.

If I'm seeing it correctly, the http link for digizeitschriften.de redirects to the https version.

@Seelengrab
Copy link
Contributor Author

Thanks for the merge!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:display and printing Aesthetics and correctness of printed representations of objects. domain:docs This change adds or pertains to documentation domain:maths Mathematical functions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants