Support for Complex-valued CuArray

It seems the support for complex -valued CuArray is not yet in place. Or, I may miss something here. Thanks.

using GPUArrays, CuArrays
x = randn(Float32, 3,3);
x = complex(x);
cx = cu(x);
y = map(sin, cx)

ERROR: MethodError: no method matching sin(::Complex{Float32})
You may have intended to import Base.sin

[1] _broadcast_getindex_evalf at .\broadcast.jl:574 [inlined]
[2] _broadcast_getindex at .\broadcast.jl:547 [inlined]
[3] getindex at .\broadcast.jl:507 [inlined]
[4] copy at .\broadcast.jl:758 [inlined]
[5] materialize(::Base.Broadcast.Broadcasted{Base.Broadcast.ArrayStyle{CuArray},Nothing,typeof(CUDAnative.sin),Tuple{CuArray{Complex{Float32},2}}}) at .\broadcast.jl:724

Julia 1.0.0
CuArrays V0.8.0

CUDAnative.sin isn’t implemented for complex numbers. At the same time, the base implementation that presumably calls sin(::Real) somewhere down the road isn’t usable because that would end up dispatching to an incompatible version of sin for CPUs. Not sure there’s an easy fix here, ideally we use Base.sin everywhere and ultimately replace calls to openlibm with CUDA-specific ones using Cassette, but that’s not for tomorrow. Implementing CUDAnative.sin(::Complex) seems like a lot of code duplication, but maybe CuArrays.jl could provide these workaround definitions for now.

Feel free to open an issue on CuArrays.jl.

@Tim, thanks a lot. A related issue is Julia will crash and quits if one wants to run command exp(cx), where cx is a cuarray containing complex numbers.