Numba code slower than pure python

前端 未结 2 1582
栀梦
栀梦 2021-02-01 06:54

I\'ve been working on speeding up a resampling calculation for a particle filter. As python has many ways to speed it up, I though I\'d try them all. Unfortunately, the numba ve

2条回答
  •  無奈伤痛
    2021-02-01 07:33

    Faster numpy version (10x speedup compared to numpy_resample)

    def numpy_faster(qs, xs, rands):
        lookup = np.cumsum(qs)
        mm = lookup[None,:]>rands[:,None]
        I = np.argmax(mm,1)
        return xs[I]
    

提交回复
热议问题