def bin_sparse(M, subsampling_factor=<NUM_LIT:3>):
try:<EOL><INDENT>from scipy.sparse import coo_matrix<EOL><DEDENT>except ImportError as e:<EOL><INDENT>print(str(e))<EOL>print("<STR_LIT>")<EOL>return bin_dense(M.todense())<EOL><DEDENT>N = M.tocoo()<EOL>n, m = N.shape<EOL>row, col, data = N.row, N.col, N.data<EOL>binned_row = row // subsampling_factor<EOL>binned_col = col // subsampling_factor<EOL>binned_n = n // subsampling_factor<EOL>binned_m = m // subsampling_factor<EOL>binned_row[binned_row >= binned_n] -= n % subsampling_factor<EOL>binned_col[binned_col >= binned_m] -= m % subsampling_factor<EOL>result = coo_matrix((data, (binned_row, binned_col)),<EOL>shape=(binned_n, binned_m))<EOL>return result<EOL>
Perform the bin_dense procedure for sparse matrices. Remaining rows
    and cols are lumped with the rest at the end.