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 sincosd function #30134

Merged
merged 7 commits into from
Aug 9, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Apply suggestions from code review
Co-Authored-By: ronisbr <[email protected]>
oxinabox and ronisbr committed May 28, 2019
commit 8905370ff4b1538d42218103c993a777efb5db3d
4 changes: 2 additions & 2 deletions base/special/trig.jl
Original file line number Diff line number Diff line change
@@ -1083,12 +1083,12 @@ Simultaneously compute the sine and cosine of `x`, where `x` is in degrees.
if isinf(x)
Copy link
Member

Choose a reason for hiding this comment

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

Isn't these conditions checked in sind and cosd? Why check here?

Copy link
Member Author

@ronisbr ronisbr Apr 13, 2019

Choose a reason for hiding this comment

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

Because without it, then the user will see an error on the function sind if Inf is passed. I though it could lead to confusion.

With respect of NaN, it can be removed. Do you want me to remove it? This was added when I was trying to make a function faster than calling both separated.

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 we do error checking like that elsewhere though.

return throw(DomainError(x, "sincosd(x) is only defined for finite `x`."))
elseif isnan(x)
return ( oftype(x,NaN), oftype(x,NaN) )
return (oftype(x,NaN), oftype(x,NaN))
end

# It turns out that calling those functions separately yielded better
Copy link
Contributor

Choose a reason for hiding this comment

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

This is pretty surprising, any idea why? Part of the point of sincos, is it avoid the double cost of calling sin and cos on the same argument.

Copy link
Member Author

@ronisbr ronisbr Mar 29, 2019

Choose a reason for hiding this comment

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

I think the compiler is clever enough to remove those duplicated executions.

Copy link
Member Author

Choose a reason for hiding this comment

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

In fact, the sincos_kernel use the same approach and it has a comment saying that inlining takes care of duplicated computations:

# There's no need to write specialized kernels, as inlining takes care of remo-

# performance than considering each case and calling `sincos_kernel`.
( sind(x), cosd(x) )
return (sind(x), cosd(x))
end

sincosd(::Missing) = (missing, missing)