def l2_torus_dissimilarity(a, b):
    """See `paper by Ebisu et al. <https://www.semanticscholar.org/paper/TorusE%3A-Knowledge-Graph-Embedding-on-a-Lie-Group-Ebisu-Ichise/990334cf76845e2da64d3baa10b0a671e433d4b6>`_
    for details about the definition of this dissimilarity function.

    """
    assert len(a.shape) == len(b.shape)
    return 4 * min((a - b) ** 2, 1 - (a - b) ** 2).sum(dim=-1)
