[Numpy-discussion] Fast sizes for FFT

Sturla Molden sturla.molden at gmail.com
Wed Dec 24 07:13:25 EST 2014


On 24/12/14 13:07, Sturla Molden wrote:

> v
>
> cdef intp_t checksize(intp_t n):
>       while not (n % 5): n /= 5
>       while not (n % 3): n /= 3
>       while not (n % 2): n /= 2
>       return (1 if n == 1 else 0)
>
> def _next_regular(target):
>       cdef intp_t n = target
>       while not checksize(n):
>           n += 1
>       return n


Blah, old code, with current Cython this should be:


from numpy cimport intp_t
cimport cython

@cython.cdivision(True)
cdef intp_t checksize(intp_t n):
      while not (n % 5): n //= 5
      while not (n % 3): n //= 3
      while not (n % 2): n //= 2
      return (1 if n == 1 else 0)

def _next_regular(target):
      cdef intp_t n = target
      while not checksize(n):
          n += 1
      return n



Sturla








More information about the NumPy-Discussion mailing list