def is_sparse(X):
    """Checks whether input tensor is sparse.

    Implements a heuristic definition of sparsity.

    A tensor is considered sparse if:

    M = number of modes
    S = number of entries
    I = number of non-zero entries

            N > M(I + 1)
    """
    M = X.ndim
    S = X.size
    I = X.nonzero()[0].size
    return S > (I + 1) * M