Shuffle sparse matrix encoded as a SciPy coo matrix.

  Args:
    sparse_matrix: a SciPy coo sparse matrix.
    dropout_rate: if dropout_rate > 0 then non-zero elements of the input matrix
      will be droped uniformly at random.
    min_dropout_rate: minimum value for the dropout rate. If None
      FLAGS.min_dropout_rate is used.
    max_dropout_rate: minimum value for the dropout rate. If None
      FLAGS.max_dropout_rate is used.

  Returns:
    A SciPy csr_matrix entailing the randomized interactions.

def shuffle_sparse_coo_matrix(sparse_matrix, dropout_rate=0.0,
                              min_dropout_rate=None, max_dropout_rate=None):
  """Shuffle sparse matrix encoded as a SciPy coo matrix.

  Args:
    sparse_matrix: a SciPy coo sparse matrix.
    dropout_rate: if dropout_rate > 0 then non-zero elements of the input matrix
      will be droped uniformly at random.
    min_dropout_rate: minimum value for the dropout rate. If None
      FLAGS.min_dropout_rate is used.
    max_dropout_rate: minimum value for the dropout rate. If None
      FLAGS.max_dropout_rate is used.

  Returns:
    A SciPy csr_matrix entailing the randomized interactions.
  """

  if (dropout_rate < 0.0) or (dropout_rate >= 1.0):
    raise ValueError("Dropout rate should be in [0, 1) but is %f"
                     % dropout_rate)

  (num_rows, num_cols) = sparse_matrix.shape
  shuffled_rows = shuffle(np.arange(num_rows))
  shuffled_cols = shuffle(np.arange(num_cols))

  if dropout_rate > 0.0:
    sparse_matrix = _dropout_sparse_coo_matrix(
        sparse_matrix, dropout_rate, min_dropout_rate, max_dropout_rate)

  new_row = np.take(shuffled_rows, sparse_matrix.row)
  new_col = np.take(shuffled_cols, sparse_matrix.col)

  return sparse.csr_matrix(
      (sparse_matrix.data, (new_row, new_col)), shape=(num_rows, num_cols))