def get_subquantizer_distortion(data, model):
    from .model import compute_residuals, project_residuals_to_local

    first_half, second_half = np.split(data, 2, axis=1)

    r1, a1 = compute_residuals(first_half, model.Cs[0])
    r2, a2 = compute_residuals(second_half, model.Cs[1])

    p1 = project_residuals_to_local(r1, a1, model.Rs[0], model.mus[0])
    p2 = project_residuals_to_local(r2, a2, model.Rs[1], model.mus[1])

    pall = np.concatenate((p1, p2), axis=1)
    suball = model.subquantizers[0] + model.subquantizers[1]

    dists = np.array([sum(np.linalg.norm(compute_residuals(d, c)[0], ord=2, axis=1) ** 2) for c, d in zip(suball, np.split(pall, 8, axis=1))])

    return dists / data.shape[0]
dataset/ETHPy150Open yahoo/lopq/python/lopq/eval.py/get_subquantizer_distortion/original