def __spread__(y, yy, n, x, m):
    """
    Given an array yy(0:n-1), extrapolate (spread) a value y into
    m actual array elements that best approximate the "fictional"
    (i.e., possible noninteger) array element number x. The weights
    used are coefficients of the Lagrange interpolating polynomial
    """
    nfac = [0, 1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880]
    if m > 10. :
        print 'factorial table too small in spread'
        return

    ix = long(x)
    if x == float(ix): 
        yy[ix] = yy[ix]+y
    else:
        ilo = long(x - 0.5*float(m) + 1.0)
        ilo = min(max(ilo, 1), n - m + 1) 
        ihi = ilo + m - 1
        nden = nfac[m]
        
        fac = x - ilo
        for j in range(ilo + 1, ihi + 1): fac = fac*(x - j)
        
        yy[ihi] = yy[ihi] + y*fac/(nden*(x - ihi))
        for j in range(ihi - 1, ilo - 1, -1):
            nden = (nden/(j + 1 - ilo))*(j - ihi)
            yy[j] = yy[j] + y*fac/(nden*(x - j))
dataset/ETHPy150Open dwkim78/upsilon/upsilon/extract_features/period_LS_pyfftw.py/__spread__/original