def _compare_graphlets(am1, am2):
    adj_mat1 = am1
    adj_mat2 = am2
    np.fill_diagonal(adj_mat1, 1)
    np.fill_diagonal(adj_mat2, 1)
    k = np.array(adj_mat1).shape[0]
    if k == 3:
        # the number of edges determines isomorphism of graphs of size 3.
        return np.array(adj_mat1).sum() == np.array(adj_mat2).sum()
    else:
        # (k-1) graphlet count determines graph isomorphism for small graphs
        # return (_count_graphlets(adj_mat1, k-1, graphlet3_array, None) ==
        #         _count_graphlets(adj_mat2, k-1, graphlet3_array, None)).all()
        if not np.array(adj_mat1).sum() == np.array(adj_mat2).sum():
            return False
        if np.array(adj_mat1).sum() in (4, 6, 14, 16):
            # 0, 1, 5 or 6 edges
            return True
        if np.array(adj_mat1).sum() == 8:
            # 2 edges - two pairs or 2-path
            return 3.0 in [adj_mat.sum() for adj_mat in adj_mat1] == \
                   3.0 in [adj_mat.sum() for adj_mat in adj_mat2]
        if np.array(adj_mat1).sum() == 10:
            # 3 edges - 3-star, 3-path or 3-cycle
            sums1 = [adj_mat.sum() for adj_mat in adj_mat1]
            sums2 = [adj_mat.sum() for adj_mat in adj_mat2]
            if (_is_3star(adj_mat1) + _is_3star(adj_mat2))%2 == 1:
                return False
            if _is_3star(adj_mat1) and _is_3star(adj_mat2):
                return True
            return (1 in sums1) == (1 in sums2)
        if np.array(adj_mat1).sum() == 12:
            # 4 edges - a simple cycle or something containing 3-star
            return _4_graphlet_contains_3star(adj_mat1) == \
                   _4_graphlet_contains_3star(adj_mat2)

    return False
Normalize the structure of nova security group rules
dataset/ETHPy150Open gmum/pykernels/pykernels/graph/allgraphlets.py/_compare_graphlets--crossover with--dataset/ETHPy150Open openstack-infra/shade/shade/_utils.py/normalize_nova_secgroup_rules