-
-
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
Use sincos
from libm in cis
#21589
Use sincos
from libm in cis
#21589
Conversation
base/complex.jl
Outdated
%res = load [2 x float], [2 x float]* %pres | ||
ret [2 x float] %res | ||
""", Tuple{Float32,Float32}, Tuple{Float32,Ptr{Void}}, v, cglobal((:sincosf, libm_name))) | ||
if !isnan(v) && (isnan(s) || isnan(c)) |
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.
would &
and |
be faster here?
base/fastmath.jl
Outdated
@@ -273,6 +273,36 @@ atan2_fast(x::Float64, y::Float64) = | |||
|
|||
# explicit implementations | |||
|
|||
# FIXME: Change to `ccall((:sincos, libm_name))` when `Ref` calling convention can be | |||
# stack allocated. Also in `complex.jl` | |||
@inline function cis_fast(v::Float64) |
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.
Could cis
just call cis_fast
to avoid the code duplication?
Hmm, why is @stevengj 's comment not showing up..... probably being mis-identified as bot by @github ? Anyway, I changed the complex.jl version to use the fastmath.jl version which I didn't do before since it was not available yet (shouldn't matter in practice as long as no one actually calls Also noticed that I can just use the complex version of |
Looks like it is fixed now? |
YAY! I'm so relieved to see you back, @stevengj!! |
d5a3d02
to
fa1e3c3
Compare
So apart from the off topic discussion that I started myself.... Any other comments about the actual PR? |
base/complex.jl
Outdated
function cis(v::Union{Float64,Float32}) | ||
res = FastMath.cis_fast(v) # Note: not yet defined at this point | ||
return Math.nan_dom_err(res, v) | ||
end |
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.
Should maybe define cis(v::Float16) = Complex{Float16}(cis(Float32(v)))
, both to use cis_fast
and to avoid the double conversion of v
to Float32
?
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.
Note that MPFR defines mpfr_sin_cos
, which we can use for the BigFloat
version of this method.
base/complex.jl
Outdated
# compute exp(im*theta) | ||
cis(theta::Real) = Complex(cos(theta),sin(theta)) | ||
cis(theta::AbstractFloat) = Complex(cos(theta),sin(theta)) |
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.
Do we have test coverage of this method now that there are specialized Float32 and Float64 versions?
2512e39
to
3228cf9
Compare
Addressed most comments. Since we've branched. I decided to just implement This does no include @nanosoldier |
Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @jrevels |
@@ -405,6 +405,7 @@ export | |||
significand, | |||
sin, | |||
sinc, | |||
sincos, |
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.
needs a docstring, and to be added to the stdlib
Test and doc added. |
Should this be mentioned in NEWS.md? |
Have added the "needs news" tag, @yuyichao, could you write an entry? |
I came up with this implementation for my research code last week that doesn't need heap allocation and is almost as good as the ccall version apart from the PLT entry part (so one more branch than an actual ccall in sysimg) so I guess people might be interested.
I don't think #10442 can be closed by this since it's too late to add another function in 0.6.
Do we have benchmarks for
cis
on nanosoldier?Anyway, local benchmarks (the code_warntype and code_llvm are just to check that the invoke is correctly optimized)