def get_linearity_coeff(u, v):
    """
    Given the two 2-dimensional vectors ``u`` and ``v``, return ``a`` so that
    ``v = a*u``

    If the vectors are not colinear, a ``ValueError`` is raised.

    EXAMPLES::

        sage: from flatsurf.geometry.straight_line_trajectory import get_linearity_coeff

        sage: V = VectorSpace(QQ,2)
        sage: get_linearity_coeff(V((1,0)), V((2,0)))
        2
        sage: get_linearity_coeff(V((2,0)), V((1,0)))
        1/2
        sage: get_linearity_coeff(V((0,1)), V((0,2)))
        2
        sage: get_linearity_coeff(V((0,2)), V((0,1)))
        1/2
        sage: get_linearity_coeff(V((1,2)), V((-2,-4)))
        -2

        sage: get_linearity_coeff(V((1,1)), V((-1,1)))
        Traceback (most recent call last):
        ...
        ValueError: non colinear
    """
    if u[0]:
        a = v[0] / u[0]
        if v[1] != a * u[1]:
            raise ValueError('non colinear')
        return a
    elif v[0]:
        raise ValueError('non colinear')
    elif u[1]:
        return v[1] / u[1]
    else:
        raise ValueError('zero vector')
