如何使numxepr与complex64一起使用?

时间:2019-11-04 06:25:41

标签: python numpy optimization numexpr

我正在尝试执行以下代码:

import numpy as np
import numexpr as ne

def julia(h, w, maxit=20, a=0.0):
    x = np.linspace(-1.8, 1.8, w, dtype=np.float32)
    y = np.linspace(-1.8, 1.8, h, dtype=np.float32)
    xv, yv = np.meshgrid(x, y)
    c = xv+yv*1j
    z = c
    divtime = maxit + np.zeros(z.shape, dtype=np.uint8)
    q = np.complex64(0.7885*np.exp(1j*a))

    for i in range(maxit):
        ne.evaluate('z*z + q', out=z) # line with error
        diverge = z*np.conj(z) > 4
        div_now = diverge & (divtime == maxit)
        divtime[div_now] = i
        z[diverge] = 2
    return divtime

julia(100, 100)

变量zq均为complex64类型,但numexpr返回complex128。有没有办法使它与complex64值一起使用以提高性能?

0 个答案:

没有答案