def coef_to_components(s, n):
    """ Convert percentage to number of components. """
    if isinstance(s, int):
        assert s < n
    elif isinstance(s, float):
        if s < 0 or s > 1:
            raise ValueError(s)
        s = int(s * n)
    else:
        raise TypeError(s)
    return s