cuComplex.h and exp()

前端 未结 2 998
滥情空心
滥情空心 2021-01-21 11:02

Q0:

Is exp() supported by cuComplex.h?

Q1:

How to write A = B * exp(i * C), where A, B, C are same size arrays of real numbers? Is this right?

ma

2条回答
  •  北海茫月
    2021-01-21 11:22

    cuComplex.h only offers some basic operations on cuComplex (principally those used inside the CUBLAS and CUFFT libraries), the exponential function is not supported.

    You can implement the exponential yourself using component-wise arithmetic. cuComplex stores the real part of a complex number in the x component and the imaginary part in the y component. Given a complex number z = x + i*y, the exponent can be computed as:

    exp(z) = exp(x) * (cos(y) + i * sin(y))

    This leads to the following CUDA code (untested):

    cuComplex my_complex_exp (cuComplex arg)
    {
       cuComplex res;
       float s, c;
       float e = expf(arg.x);
       sincosf(arg.y, &s, &c);
       res.x = c * e;
       res.y = s * e;
       return res;
    }
    

提交回复
热议问题