-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Add sincosd function #30134
Conversation
If this just calls |
@KristofferC well, IMHO, it keeps the consistency, since we have |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with this, though we probably don't need too many more degree functions.
If there are no inputs where |
I think this is good when you want to compute the sine and cosine of a angle that is computed by a lot of terms, like:
Otherwise, or you use I use degree functions a lot, and I think this is the only trigonometric function without a “degree” version. That’s why I proposed it, to keep consistency. Btw, I applied all of your suggestions. Thanks for the review. |
Instead of adding another _d function, is it too late to have
Or whatever clever unitful way there is to go about this? |
Yeah, I guess that is an ok reason. |
Unitful.jl (and suppliments in UnitfulAngles.jl) already does basically this. |
Hi guys! Should I need to do something more here? |
Bump! :) |
return (oftype(x,NaN), oftype(x,NaN)) | ||
end | ||
|
||
# It turns out that calling those functions separately yielded better |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:
Line 208 in 8221c87
# There's no need to write specialized kernels, as inlining takes care of remo- |
That sounds suspicious --- are we sure the function is type stable etc.? |
Triage approves the addition of this function for the sake of consistency alone. Even if it's currently no faster than calling |
Me too. I checked everything I could (given my knowledge of how julia works, including type-stability) and I was not capable to come even close to what I got when calling those functions separated. But since you also think this can be improved, I will try more and then I submit a new PR, is it OK? |
|
||
""" | ||
function sincosd(x::Real) | ||
if isinf(x) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
With respect to "compat annotation" what should I do? Is it also necessary to add a new commit with the information in |
The function `sincosd` simultaneously computes the sine and cosine in which the input angle is in degrees.
Co-Authored-By: ronisbr <ronisbr@gmail.com>
Hi guys! Done :) Sorry for the delay, I am still learning... After some help (thanks @ararslan and @narendrakpatel), I could rebase everything, add NEWS and COMPAT annotation. Is everything fine now? |
I have no idea why the build failed in some cases... it does not seem related to this PR. |
Bump! :) |
Hi guys Is it possible to add this to 1.3.0? I saw that alpha was released. |
Co-Authored-By: Alex Arslan <ararslan@comcast.net>
Kicked off CI again. Triage says let's merge if green. |
@StefanKarpinski I have absolutely no idea why it failed on Windows. It does not seem related to this PR. Am I right? |
Can you rebase the PR and push it again? This seems like it might be unrelated and just happening because of some kind of old cruft on the version of master that this was based on. |
Sorry, I just had access to Github now. I saw this was already merged. Should I need to do something? |
No, it's fine. |
@StefanKarpinski and @KristofferC
This is the first PR as I was instructed. It only adds the
sincosd
function. After a lot of tests, it turns out that callingsind
andcosd
separately in an@inline
function yielded a much better performance than considering the cases separately.My first attempt was:
which was almost 10x slower than calling
sind
andcosd
for small angles (< 640).The current implementation has a very good performance:
and, by design, gives the same answer as
sind
andcosd
.