(coo)
Given a sparse matrix in COO format, filter out any entry at location
    (i, j) strictly below the diagonal if the entry at (j, i) is also
    stored. Return row, column and data information for an upper diagonal
    COO matrix.
Given a sparse matrix in COO format, filter out any entry at location
    (i, j) strictly below the diagonal if the entry at (j, i) is also
    stored. Return row, column and data information for an upper diagonal
    COO matrix.
Given a sparse matrix in COO format filter out any entry at location ( i j ) strictly below the diagonal if the entry at ( j i ) is also stored . Return row column and data information for an upper diagonal COO matrix .
def _resolve_symmetry_conflicts(coo):
    """Given a sparse matrix in COO format, filter out any entry at location
    (i, j) strictly below the diagonal if the entry at (j, i) is also
    stored. Return row, column and data information for an upper diagonal
    COO matrix."""
    _row, _col, _data = coo.row, coo.col, coo.data

    below_diag = _col < _row
    # Check if there is anything below the main diagonal
    if below_diag.any():
        # Initialize filtered COO data with information in the upper triangle
        in_upper_triangle = np.logical_not(below_diag)
        row = _row[in_upper_triangle]
        col = _col[in_upper_triangle]
        data = _data[in_upper_triangle]

        # Filter out entries below the diagonal for which entries at
        # transposed positions are already available
        upper_triangle_indices = set(zip(row, col))
        additions = tuple(
            zip(*((j, i, x) for (i, j, x) in zip(_row[below_diag],
                                                 _col[below_diag],
                                                 _data[below_diag])
                  if (j, i) not in upper_triangle_indices))
            )
        # Add surviving entries below the diagonal to final COO data
        if additions:
            row_add, col_add, data_add = additions
            row = np.concatenate([row, row_add])
            col = np.concatenate([col, col_add])
            data = np.concatenate([data, data_add])

        return row, col, data
    else:
        return _row, _col, _data
def _resolve_symmetry_conflicts ( coo ) : _row , _col , _data = coo . row , coo . col , coo . data below_diag = _col < _row # Check if there is anything below the main diagonal if below_diag . any ( ) : # Initialize filtered COO data with information in the upper triangle in_upper_triangle = np . logical_not ( below_diag ) row = _row [ in_upper_triangle ] col = _col [ in_upper_triangle ] data = _data [ in_upper_triangle ] # Filter out entries below the diagonal for which entries at # transposed positions are already available upper_triangle_indices = set ( zip ( row , col ) ) additions = tuple ( zip ( * ( ( j , i , x ) for ( i , j , x ) in zip ( _row [ below_diag ] , _col [ below_diag ] , _data [ below_diag ] ) if ( j , i ) not in upper_triangle_indices ) ) ) # Add surviving entries below the diagonal to final COO data if additions : row_add , col_add , data_add = additions row = np . concatenate ( [ row , row_add ] ) col = np . concatenate ( [ col , col_add ] ) data = np . concatenate ( [ data , data_add ] ) return row , col , data else : return _row , _col , _data