original_docstring: 
      find a similar matrix of A with adjacency matrix equal to adj
      
docstring: find a similar matrix of A with adjacency matrix equal to adj
docstring_tokens: find a similar matrix of A with adjacency matrix equal to adj
code: def rotate_to_adj(A, adj, max_iter=1000, atol=1e-8):
      """
      find a similar matrix of A with adjacency matrix equal to adj
      """
      adj = adj.astype(np.int64)
      off_zero_mask = (adj==0)
      np.fill_diagonal(off_zero_mask, False)
  
      n = A.shape[0]
      A1 = A.copy()
      assert A.shape==adj.shape
      isconverged = False
      counter = 0
      while not isconverged:
          counter += 1
          for i in range(n):
              for j in range(i + 1, n):
                  if adj[i, j]==0:
                      jacobi_rotate(A1, i, j)
          if counter > max_iter:
              break
          isconverged = True
          for i in range(n):
              for j in range(i + 1, n):
                  if off_zero_mask[i, j] > 0 and np.abs(A1[i, j]) > atol:
                      isconverged = False
                  if not isconverged:
                      break
              if not isconverged:
                  break
          if isconverged:
              for i in range(n):
                  for j in range(i + 1, n):
                      if off_zero_mask[i, j]:
                          A1[i, j] = A1[j, i] = 0.0
  
      return A1, isconverged, counter
code_tokens: def rotate_to_adj ( A , adj , max_iter = 1000 , atol = 1e-8 ) : adj = adj . astype ( np . int64 ) off_zero_mask = ( adj == 0 ) np . fill_diagonal ( off_zero_mask , False ) n = A . shape [ 0 ] A1 = A . copy ( ) assert A . shape == adj . shape isconverged = False counter = 0 while not isconverged : counter += 1 for i in range ( n ) : for j in range ( i + 1 , n ) : if adj [ i , j ] == 0 : jacobi_rotate ( A1 , i , j ) if counter > max_iter : break isconverged = True for i in range ( n ) : for j in range ( i + 1 , n ) : if off_zero_mask [ i , j ] > 0 and np . abs ( A1 [ i , j ] ) > atol : isconverged = False if not isconverged : break if not isconverged : break if isconverged : for i in range ( n ) : for j in range ( i + 1 , n ) : if off_zero_mask [ i , j ] : A1 [ i , j ] = A1 [ j , i ] = 0.0 return A1 , isconverged , counter
short_docstring: find a similar matrix of A with adjacency matrix equal to adj
short_docstring_tokens: find a similar matrix of A with adjacency matrix equal to adj
comment: """
      find a similar matrix of A with adjacency matrix equal to adj
      """