@staticmethod
def _to_triplet(mat, ids=None):
    """Covert a 2d array into sparse triplet format.

        Parameters
        ----------
        mat: 2d array, required
            A Numpy 2d array of integers.
        ids: list, optional, default: None
            A list of ids (or labels) of the objects to be used in the output triplet matrix.

        Returns
        -------
        A set corresponding to the sparse triplet representation of mat.
        """
    tuples = set()
    n = mat.shape[0]
    k = mat.shape[1]
    if ids is None:
        ids = range(n)
    for n_ in range(n):
        for k_ in range(k):
            j = int(mat[n_, k_])
            tuples.add((ids[n_], ids[j], 1.0))
    return tuples
