def _apply_two_mode_gate(G, T, i, j):
    """In-place applies a two mode gate G into the process matrix T in modes i and j

    Args:
        G (array): 2x2 matrix for two mode gate
        T (array): passive transformation
        i (int): index of first mode of gate
        j (int): index of second mode of gate

    Returns:
        T (array): updated passive transformation
    """
    (T[i], T[j]) = (G[0, 0] * T[i] + G[0, 1] * T[j], G[1, 0] * T[i] + G[1, 1] * T[j])
    return T