Skip to content
This repository was archived by the owner on May 27, 2021. It is now read-only.

Commit 3ecd33e

Browse files
committed
Add some more complex operations
1 parent 027e707 commit 3ecd33e

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/device/cuda/math.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@
103103
@inline ldexp(x::Float64, y::Int32) = @wrap __nv_ldexp(x::double, y::i32)::double
104104
@inline ldexp(x::Float32, y::Int32) = @wrap __nv_ldexpf(x::float, y::i32)::float
105105

106+
@inline exp(x::Complex{Float64}) = exp(x.re) * (cos(x.im) + 1.0im * sin(x.im))
107+
@inline exp(x::Complex{Float32}) = exp(x.re) * (cos(x.im) + 1.0im * sin(x.im))
108+
@inline exp_fast(x::Complex{Float32}) = exp_fast(x.re) * (cos_fast(x.im) + 1.0im * sin_fast(x.im))
106109

107110
## error
108111

@@ -170,6 +173,8 @@
170173
@inline abs(f::Float32) = @wrap __nv_fabsf(f::float)::float
171174
@inline abs(x::Int64) = @wrap __nv_llabs(x::i64)::i64
172175

176+
@inline abs(x::Complex{Float64}) = hypot(x.re, x.im)
177+
@inline abs(x::Complex{Float32}) = hypot(x.re, x.im)
173178

174179
## roots and powers
175180

@@ -192,6 +197,9 @@
192197
@inline pow(x::Float32, y::Int32) = @wrap __nv_powif(x::float, y::i32)::float
193198
@inline pow(x::Union{Float32, Float64}, y::Int64) = pow(x, Int32(y))
194199

200+
@inline abs2(x::Complex{Float64}) = x.re * x.re + x.im * x.im
201+
@inline abs2(x::Complex{Float32}) = x.re * x.re + x.im * x.im
202+
195203
## rounding and selection
196204

197205
# TODO: differentiate in return type, map correctly

0 commit comments

Comments
 (0)