

def convergents(contfrac):
    'Convergents of a continued fraction.\n\n    contfrac must yield an infinite sequence (n0, d0), (n1, d1), (n2,\n    d2), ..., representing the continued fraction\n\n                n0\n        ------------------\n                  n1\n        d0 + -------------\n                     n2\n             d1 + --------\n                  d2 + ...\n\n    The kth convergent is the continued fraction truncated at the kth\n    term, i.e. with zero instead of the rest in the ellipsis.\n    '
    cs = continuants(contfrac)
    (p0, q0) = cs.next()
    (yield (p0 / q0))
    for (p, q) in cs:
        if (p == 0):
            break
        (yield (p / q))
        (p0, q0) = (p, q)
    c = (p0 / q0)
    while True:
        (yield q0)

dataset/ETHPy150Open probcomp/bayeslite/src/math_util.py convergents/VarMisuse@100/296 `c`->`q0`