Exemplo n.º 1
0
 def test_plan1d(self):
     from pyculib.fft.binding import Plan, CUFFT_C2C
     n = 10
     data = np.arange(n, dtype=np.complex64)
     orig = data.copy()
     d_data = cuda.to_device(data)
     fftplan = Plan.one(CUFFT_C2C, n)
     fftplan.forward(d_data, d_data)
     fftplan.inverse(d_data, d_data)
     d_data.copy_to_host(data)
     result = data / n
     self.assertTrue(np.allclose(orig, result.real))
Exemplo n.º 2
0
    arg3 = clip(max((-z + r1 + r2)*(z + r1 - r2)*(z - r1 + r2)*(z + r1 + r2), 0.),-1,1)

    if   (r1 <= r2 - z) : return math.pi*r1*r1							                              # planet completely overlaps stellar circle
    elif (r1 >= r2 + z) : return math.pi*r2*r2						                                  # stellar circle completely overlaps planet
    else                : return r1*r1*math.acos(arg1) + r2*r2*math.acos(arg2) - 0.5*math.sqrt(arg3)  # partial overlap



####################
# GPU functions
##################
if numba.cuda.is_available():

    # FFT plan
    from pyculib.fft.binding import Plan, CUFFT_C2C
    fftplan17 = Plan.one(CUFFT_C2C, 2**17)
    fftplan18 = Plan.one(CUFFT_C2C, 2**18)


    @numba.cuda.jit('float64(float64,float64,float64)', device=True, inline=True)
    def d_clip(a, b, c):
        if (a < b)   : return b
        elif (a > c) : return c
        else         : return a


    @numba.cuda.jit('float64(float64,float64,float64)', device=True, inline=True)
    def d_area(z, r1, r2):
        arg1 = d_clip((z*z + r1*r1 - r2*r2)/(2.*z*r1),-1,1)
        arg2 = d_clip((z*z + r2*r2 - r1*r1)/(2.*z*r2),-1,1)
        arg3 = d_clip(max((-z + r1 + r2)*(z + r1 - r2)*(z - r1 + r2)*(z + r1 + r2), 0.),-1,1)