def mode_2_prod_rotated(A, B, adjoint_a=False):
    """
    For a 3D tensor A(r1,i,r2) and B(r3,i) a matrix, this implements
    the mode 2 product so that  we return C(r3,r1,r2) = sum_{i}{A*B}

    Note that we change the order of dimensions in this case (hence
    the name rotated). Now r3 becomes a "batch dim". This is useful
    for subsequent operations
    """
    S = A.shape
    uA = A.permute(1, 0, 2).reshape(S[1], S[0] * S[2])
    if adjoint_a:
        r = B.transpose(-2, -1).conj() @ uA
    else:
        r = B @ uA
    return r.reshape(-1, S[0], S[2])