def to_pymetis_format(adj_mat):
    """Transform an adjacency matrix into the pymetis format.

    Parameter
    ---------
    adj_mat: Adjacency matrix.

    Returns
    -------
    xadj, adjncy, eweights: Parameters for pymetis.
    """
    xadj = [0]
    adjncy = []
    eweights = []
    n_rows = adj_mat.shape[0]
    adj_mat = adj_mat.tolil()

    for i in range(n_rows):
        row = adj_mat.getrow(i)
        idx_row, idx_col = row.nonzero()
        val = row[idx_row, idx_col]
        adjncy += list(idx_col)
        eweights += list(val.toarray()[0])
        xadj.append(len(adjncy))

    return xadj, adjncy, eweights