def cauchy_conj(v, z, w, num=2, denom=2):
    """
    Pykeops version
    Args:
        v (torch.tensor): (..., N, N)
        z (torch.tensor): (..., N, L)
        w (torch.tensor): (..., N, L)
        num (int): (..., N, L)
        denom (int): (..., N, L)
    """
    if num == 1:
        expr_num = 'z * ComplexReal(v) - Real2Complex(ComplexReal(v)*ComplexReal(w) + ComplexImag(v)*ComplexImag(w))'
    elif num == 2:
        expr_num = 'z * ComplexReal(v) - Real2Complex(Sum(v * w))'
    else:
        raise NotImplementedError

    if denom == 1:
        expr_denom = 'ComplexMult(z-Real2Complex(ComplexReal(w)),' \
                     ' z-Real2Complex(ComplexReal(w))) + Real2Complex(Square(ComplexImag(w)))'
    elif denom == 2:
        expr_denom = 'ComplexMult(z-w, z-Conj(w))'
    else:
        raise NotImplementedError

    cauchy_mult = Genred(
        f'ComplexDivide({expr_num}, {expr_denom})',
        # expr_num,
        # expr_denom,
        [
            'v = Vj(2)',
            'z = Vi(2)',
            'w = Vj(2)',
        ],
        reduction_op='Sum',
        axis=1,
        dtype='float32' if v.dtype == torch.cfloat else 'float64',
    )

    v, z, w = _broadcast_dims(v, z, w)
    v = torch.view_as_real(v)
    z = torch.view_as_real(z)
    w = torch.view_as_real(w)

    r = 2*cauchy_mult(v, z, w, backend='CPU')
    return torch.view_as_complex(r)
Pykeops version
Args:
v (torch.tensor): (..., N, N)
z (torch.tensor): (..., N, L)
w (torch.tensor): (..., N, L)
num (int): (..., N, L)
denom (int): (..., N, L)
towhee/models/vis4mer/utils.py