def index(a, x, atol=None):
    """Locate the leftmost value exactly equal to x."""
    i = bs.bisect_left(a, x)
    if i != len(a):
        if atol is None:
            if a[i] == x: return i
        else:
            if abs(a[i] - x) < atol: return i
    raise ValueError
Locate the leftmost value exactly equal to x.