code: def _maybe_halve_diagonal(m, condition):
      """Halves all items in the diagonal of the given SciPy sparse matrix in
      coo mode *if* and *only if* the given condition is True.
  
      Returns the row, column and data arrays.
      """
      data_array = m.data
      if condition:
          # We can't do data_array[m.row == m.col] /= 2 here because we would be
          # modifying the array in-place and the end user wouldn't like if we
          # messed with their matrix. So we make a copy.
          data_array = data_array.copy()
          (idxs,) = (m.row == m.col).nonzero()
          for i in idxs:
              data_array[i] /= 2
  
      return m.row, m.col, data_array
  
imports: from __future__ import with_statement
  from operator import add
  from igraph._igraph import ADJ_DIRECTED, ADJ_UNDIRECTED, ADJ_MAX, ADJ_MIN, ADJ_PLUS, ADJ_UPPER, ADJ_LOWER
label_desc: Use image node_id 2 for calling a global function with example usage: _maybe_halve_diagonal(m, condition) and returns: m,  m,  data_array