Threaded FFT in Enthought Python

前端 未结 3 2089
一个人的身影
一个人的身影 2021-02-10 00:43

Fast Fourier Transforms (FFTs) in Numpy/SciPy are not threaded. Enthought Python is shipped with the Intel MKL numerical library, which is capable of threaded FFTs. How does one

3条回答
  •  南方客
    南方客 (楼主)
    2021-02-10 01:34

    A cleaner version of my original answer is as follows:

    from ctypes import *
    
    mkl = cdll.LoadLibrary("mk2_rt.dll")
    c_double_p = POINTER(c_double)
    DFTI_COMPLEX = c_int(32)
    DFTI_DOUBLE = c_int(36)
    
    def fft2(a):
        Desc_Handle = c_void_p(0)
        dims = (c_int*2)(*a.shape)
    
        mkl.DftiCreateDescriptor(byref(Desc_Handle), DFTI_DOUBLE, DFTI_COMPLEX, 2, dims )
        mkl.DftiCommitDescriptor(Desc_Handle)
        mkl.DftiComputeForward(Desc_Handle, a.ctypes.data_as(c_void_p) )
        mkl.DftiFreeDescriptor(byref(Desc_Handle))
    
        return a
    
    def ifft2(a):
        Desc_Handle = c_void_p(0)
        dims = (c_int*2)(*a.shape)
    
        mkl.DftiCreateDescriptor(byref(Desc_Handle), DFTI_DOUBLE, DFTI_COMPLEX, 2, dims )
        mkl.DftiCommitDescriptor(Desc_Handle)
        mkl.DftiComputeBackward(Desc_Handle, a.ctypes.data_as(c_void_p) )
        mkl.DftiFreeDescriptor(byref(Desc_Handle))
    
        return a
    

提交回复
热议问题