Skip to content

Instantly share code, notes, and snippets.

@tclements
Created February 14, 2019 19:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tclements/02ae40dc26571292c909cc624a8943f5 to your computer and use it in GitHub Desktop.
Save tclements/02ae40dc26571292c909cc624a8943f5 to your computer and use it in GitHub Desktop.
sin, cos, exp with complex numbers on GPU with Julia
using GPUArrays
using CuArrays
import Base.sin, Base.cos, Base.exp
function sin(A::GPUArray{ComplexF64})
return sin.(real(A)) .* cosh.(imag(A)) .+ im .* cos.(real(A)) .* sinh.(imag(A))
end
function cos(A::GPUArray{ComplexF64})
return cos.(real(A)) .* cosh.(imag(A)) .- im .* sin.(real(A)) .* sinh.(imag(A))
end
function exp(A::GPUArray{ComplexF64})
return exp.(real(A)) .* (cos.(imag(A)) .+ im .* sin.(imag(A)))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment