code: def distance_measure_common(A, func, alpha, R, k, epsilon):
      
      # create test vectors
      x = relaxation_vectors(A, R, k, alpha)
  
      # apply distance measure function to vectors
      d = func(x)
  
      # drop distances to self
      (rows, cols) = A.nonzero()
      weak = np.where(rows == cols)[0]
      d[weak] = 0
      C = sparse.csr_matrix((d, (rows, cols)), shape=A.shape)
      C.eliminate_zeros()
  
      # remove weak connections
      # removes entry e from a row if e > theta * min of all entries in the row
      amg_core.apply_distance_filter(C.shape[0], epsilon, C.indptr,
                                     C.indices, C.data)
      C.eliminate_zeros()
  
      # Standardized strength values require small values be weak and large
      # values be strong.  So, we invert the distances.
      C.data = 1.0 / C.data
  
      # Put an identity on the diagonal
      C = C + sparse.eye(C.shape[0], C.shape[1], format='csr')
  
      # Scale C by the largest magnitude entry in each row
      C = scale_rows_by_largest_entry(C)
  
      return C
docs: Create strength of connection matrixfrom a function applied to relaxation vectors.