def rss_line_segment(params, ols_data):
    """
    For the line model defined by:
        y = v + m(x-u)

    For data {x_i, y_i}, computes the RSS (residual sum of squares), defined
    as

        Sum[ y_i -v - m(x_i - u) ]

    For OLS, this is the complete RSS.  For bkpt models, we can add these over
    each linear segment.
    """

    u, v, m = params

    num_data = ols_data[0]
    sum_x = ols_data[1]
    sum_y = ols_data[2]
    sum_xx = ols_data[3]
    sum_yy = ols_data[4]
    sum_xy = ols_data[5]

    term = (v - m * u)

    return (sum_yy - 2.0 * term * sum_y - 2.0 * m * sum_xy
            + m * m * sum_xx + 2.0 * m * term * sum_x + term * term * num_data)