passagemath-graphs 10.6.1rc1__cp310-cp310-musllinux_1_2_aarch64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- passagemath_graphs-10.6.1rc1.dist-info/METADATA +292 -0
- passagemath_graphs-10.6.1rc1.dist-info/RECORD +260 -0
- passagemath_graphs-10.6.1rc1.dist-info/WHEEL +5 -0
- passagemath_graphs-10.6.1rc1.dist-info/top_level.txt +2 -0
- passagemath_graphs.libs/libgcc_s-69c45f16.so.1 +0 -0
- passagemath_graphs.libs/libgmp-8e78bd9b.so.10.5.0 +0 -0
- passagemath_graphs.libs/libstdc++-1f1a71be.so.6.0.33 +0 -0
- sage/all__sagemath_graphs.py +39 -0
- sage/combinat/abstract_tree.py +2723 -0
- sage/combinat/all__sagemath_graphs.py +34 -0
- sage/combinat/binary_tree.py +5306 -0
- sage/combinat/cluster_algebra_quiver/all.py +22 -0
- sage/combinat/cluster_algebra_quiver/cluster_seed.py +5208 -0
- sage/combinat/cluster_algebra_quiver/interact.py +124 -0
- sage/combinat/cluster_algebra_quiver/mutation_class.py +625 -0
- sage/combinat/cluster_algebra_quiver/mutation_type.py +1555 -0
- sage/combinat/cluster_algebra_quiver/quiver.py +2290 -0
- sage/combinat/cluster_algebra_quiver/quiver_mutation_type.py +2468 -0
- sage/combinat/designs/MOLS_handbook_data.py +570 -0
- sage/combinat/designs/all.py +58 -0
- sage/combinat/designs/bibd.py +1655 -0
- sage/combinat/designs/block_design.py +1071 -0
- sage/combinat/designs/covering_array.py +269 -0
- sage/combinat/designs/covering_design.py +530 -0
- sage/combinat/designs/database.py +5615 -0
- sage/combinat/designs/design_catalog.py +122 -0
- sage/combinat/designs/designs_pyx.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/combinat/designs/designs_pyx.pxd +21 -0
- sage/combinat/designs/designs_pyx.pyx +993 -0
- sage/combinat/designs/difference_family.py +3951 -0
- sage/combinat/designs/difference_matrices.py +279 -0
- sage/combinat/designs/evenly_distributed_sets.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/combinat/designs/evenly_distributed_sets.pyx +661 -0
- sage/combinat/designs/ext_rep.py +1064 -0
- sage/combinat/designs/gen_quadrangles_with_spread.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/combinat/designs/gen_quadrangles_with_spread.pyx +339 -0
- sage/combinat/designs/group_divisible_designs.py +361 -0
- sage/combinat/designs/incidence_structures.py +2357 -0
- sage/combinat/designs/latin_squares.py +581 -0
- sage/combinat/designs/orthogonal_arrays.py +2244 -0
- sage/combinat/designs/orthogonal_arrays_build_recursive.py +1780 -0
- sage/combinat/designs/orthogonal_arrays_find_recursive.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/combinat/designs/orthogonal_arrays_find_recursive.pyx +967 -0
- sage/combinat/designs/resolvable_bibd.py +815 -0
- sage/combinat/designs/steiner_quadruple_systems.py +1306 -0
- sage/combinat/designs/subhypergraph_search.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/combinat/designs/subhypergraph_search.pyx +530 -0
- sage/combinat/designs/twographs.py +306 -0
- sage/combinat/finite_state_machine.py +14874 -0
- sage/combinat/finite_state_machine_generators.py +2006 -0
- sage/combinat/graph_path.py +448 -0
- sage/combinat/interval_posets.py +3908 -0
- sage/combinat/nu_tamari_lattice.py +269 -0
- sage/combinat/ordered_tree.py +1446 -0
- sage/combinat/posets/all.py +46 -0
- sage/combinat/posets/bubble_shuffle.py +247 -0
- sage/combinat/posets/cartesian_product.py +493 -0
- sage/combinat/posets/d_complete.py +182 -0
- sage/combinat/posets/elements.py +273 -0
- sage/combinat/posets/forest.py +30 -0
- sage/combinat/posets/hasse_cython.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/combinat/posets/hasse_cython.pyx +174 -0
- sage/combinat/posets/hasse_diagram.py +3672 -0
- sage/combinat/posets/hochschild_lattice.py +158 -0
- sage/combinat/posets/incidence_algebras.py +794 -0
- sage/combinat/posets/lattices.py +5117 -0
- sage/combinat/posets/linear_extension_iterator.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/combinat/posets/linear_extension_iterator.pyx +292 -0
- sage/combinat/posets/linear_extensions.py +1037 -0
- sage/combinat/posets/mobile.py +275 -0
- sage/combinat/posets/moebius_algebra.py +776 -0
- sage/combinat/posets/poset_examples.py +2178 -0
- sage/combinat/posets/posets.py +9360 -0
- sage/combinat/rooted_tree.py +1070 -0
- sage/combinat/shard_order.py +239 -0
- sage/combinat/tamari_lattices.py +384 -0
- sage/combinat/yang_baxter_graph.py +923 -0
- sage/databases/all__sagemath_graphs.py +1 -0
- sage/databases/knotinfo_db.py +1231 -0
- sage/ext_data/all__sagemath_graphs.py +1 -0
- sage/ext_data/graphs/graph_plot_js.html +330 -0
- sage/ext_data/kenzo/CP2.txt +45 -0
- sage/ext_data/kenzo/CP3.txt +349 -0
- sage/ext_data/kenzo/CP4.txt +4774 -0
- sage/ext_data/kenzo/README.txt +49 -0
- sage/ext_data/kenzo/S4.txt +20 -0
- sage/graphs/all.py +42 -0
- sage/graphs/asteroidal_triples.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/asteroidal_triples.pyx +320 -0
- sage/graphs/base/all.py +1 -0
- sage/graphs/base/boost_graph.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/base/boost_graph.pxd +106 -0
- sage/graphs/base/boost_graph.pyx +3045 -0
- sage/graphs/base/c_graph.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/base/c_graph.pxd +106 -0
- sage/graphs/base/c_graph.pyx +5096 -0
- sage/graphs/base/dense_graph.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/base/dense_graph.pxd +28 -0
- sage/graphs/base/dense_graph.pyx +801 -0
- sage/graphs/base/graph_backends.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/base/graph_backends.pxd +5 -0
- sage/graphs/base/graph_backends.pyx +797 -0
- sage/graphs/base/overview.py +85 -0
- sage/graphs/base/sparse_graph.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/base/sparse_graph.pxd +90 -0
- sage/graphs/base/sparse_graph.pyx +1653 -0
- sage/graphs/base/static_dense_graph.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/base/static_dense_graph.pxd +5 -0
- sage/graphs/base/static_dense_graph.pyx +1032 -0
- sage/graphs/base/static_sparse_backend.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/base/static_sparse_backend.pxd +27 -0
- sage/graphs/base/static_sparse_backend.pyx +1583 -0
- sage/graphs/base/static_sparse_graph.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/base/static_sparse_graph.pxd +37 -0
- sage/graphs/base/static_sparse_graph.pyx +1375 -0
- sage/graphs/bipartite_graph.py +2732 -0
- sage/graphs/centrality.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/centrality.pyx +1038 -0
- sage/graphs/cographs.py +519 -0
- sage/graphs/comparability.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/comparability.pyx +851 -0
- sage/graphs/connectivity.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/connectivity.pxd +157 -0
- sage/graphs/connectivity.pyx +4813 -0
- sage/graphs/convexity_properties.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/convexity_properties.pxd +16 -0
- sage/graphs/convexity_properties.pyx +870 -0
- sage/graphs/digraph.py +4754 -0
- sage/graphs/digraph_generators.py +1993 -0
- sage/graphs/distances_all_pairs.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/distances_all_pairs.pxd +12 -0
- sage/graphs/distances_all_pairs.pyx +2938 -0
- sage/graphs/domination.py +1363 -0
- sage/graphs/dot2tex_utils.py +100 -0
- sage/graphs/edge_connectivity.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/edge_connectivity.pyx +1215 -0
- sage/graphs/generators/all.py +1 -0
- sage/graphs/generators/basic.py +1769 -0
- sage/graphs/generators/chessboard.py +538 -0
- sage/graphs/generators/classical_geometries.py +1611 -0
- sage/graphs/generators/degree_sequence.py +235 -0
- sage/graphs/generators/distance_regular.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/generators/distance_regular.pyx +2846 -0
- sage/graphs/generators/families.py +4759 -0
- sage/graphs/generators/intersection.py +565 -0
- sage/graphs/generators/platonic_solids.py +262 -0
- sage/graphs/generators/random.py +2623 -0
- sage/graphs/generators/smallgraphs.py +5741 -0
- sage/graphs/generators/world_map.py +724 -0
- sage/graphs/generic_graph.py +26867 -0
- sage/graphs/generic_graph_pyx.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/generic_graph_pyx.pxd +34 -0
- sage/graphs/generic_graph_pyx.pyx +1673 -0
- sage/graphs/genus.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/genus.pyx +622 -0
- sage/graphs/graph.py +9645 -0
- sage/graphs/graph_coloring.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/graph_coloring.pyx +2284 -0
- sage/graphs/graph_database.py +1177 -0
- sage/graphs/graph_decompositions/all.py +1 -0
- sage/graphs/graph_decompositions/bandwidth.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/graph_decompositions/bandwidth.pyx +428 -0
- sage/graphs/graph_decompositions/clique_separators.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/graph_decompositions/clique_separators.pyx +616 -0
- sage/graphs/graph_decompositions/cutwidth.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/graph_decompositions/cutwidth.pyx +753 -0
- sage/graphs/graph_decompositions/fast_digraph.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/graph_decompositions/fast_digraph.pxd +13 -0
- sage/graphs/graph_decompositions/fast_digraph.pyx +212 -0
- sage/graphs/graph_decompositions/graph_products.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/graph_decompositions/graph_products.pyx +508 -0
- sage/graphs/graph_decompositions/modular_decomposition.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/graph_decompositions/modular_decomposition.pxd +27 -0
- sage/graphs/graph_decompositions/modular_decomposition.pyx +1536 -0
- sage/graphs/graph_decompositions/slice_decomposition.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/graph_decompositions/slice_decomposition.pxd +18 -0
- sage/graphs/graph_decompositions/slice_decomposition.pyx +1106 -0
- sage/graphs/graph_decompositions/tree_decomposition.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/graph_decompositions/tree_decomposition.pxd +17 -0
- sage/graphs/graph_decompositions/tree_decomposition.pyx +1996 -0
- sage/graphs/graph_decompositions/vertex_separation.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/graph_decompositions/vertex_separation.pxd +5 -0
- sage/graphs/graph_decompositions/vertex_separation.pyx +1963 -0
- sage/graphs/graph_editor.py +82 -0
- sage/graphs/graph_generators.py +3314 -0
- sage/graphs/graph_generators_pyx.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/graph_generators_pyx.pyx +95 -0
- sage/graphs/graph_input.py +812 -0
- sage/graphs/graph_latex.py +2064 -0
- sage/graphs/graph_list.py +410 -0
- sage/graphs/graph_plot.py +1756 -0
- sage/graphs/graph_plot_js.py +338 -0
- sage/graphs/hyperbolicity.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/hyperbolicity.pyx +1704 -0
- sage/graphs/hypergraph_generators.py +364 -0
- sage/graphs/independent_sets.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/independent_sets.pxd +13 -0
- sage/graphs/independent_sets.pyx +402 -0
- sage/graphs/isgci.py +1033 -0
- sage/graphs/isoperimetric_inequalities.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/isoperimetric_inequalities.pyx +489 -0
- sage/graphs/line_graph.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/line_graph.pyx +743 -0
- sage/graphs/lovasz_theta.py +77 -0
- sage/graphs/matching.py +1633 -0
- sage/graphs/matching_covered_graph.py +3590 -0
- sage/graphs/orientations.py +1489 -0
- sage/graphs/partial_cube.py +459 -0
- sage/graphs/path_enumeration.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/path_enumeration.pyx +2040 -0
- sage/graphs/pq_trees.py +1129 -0
- sage/graphs/print_graphs.py +201 -0
- sage/graphs/schnyder.py +865 -0
- sage/graphs/spanning_tree.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/spanning_tree.pyx +1457 -0
- sage/graphs/strongly_regular_db.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/strongly_regular_db.pyx +3340 -0
- sage/graphs/traversals.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/traversals.pxd +9 -0
- sage/graphs/traversals.pyx +1872 -0
- sage/graphs/trees.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/trees.pxd +15 -0
- sage/graphs/trees.pyx +310 -0
- sage/graphs/tutte_polynomial.py +713 -0
- sage/graphs/views.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/views.pyx +794 -0
- sage/graphs/weakly_chordal.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/graphs/weakly_chordal.pyx +604 -0
- sage/groups/all__sagemath_graphs.py +1 -0
- sage/groups/perm_gps/all__sagemath_graphs.py +1 -0
- sage/groups/perm_gps/partn_ref/all__sagemath_graphs.py +1 -0
- sage/groups/perm_gps/partn_ref/refinement_graphs.cpython-310-aarch64-linux-gnu.so +0 -0
- sage/groups/perm_gps/partn_ref/refinement_graphs.pxd +38 -0
- sage/groups/perm_gps/partn_ref/refinement_graphs.pyx +1666 -0
- sage/knots/all.py +6 -0
- sage/knots/free_knotinfo_monoid.py +507 -0
- sage/knots/gauss_code.py +291 -0
- sage/knots/knot.py +682 -0
- sage/knots/knot_table.py +284 -0
- sage/knots/knotinfo.py +2900 -0
- sage/knots/link.py +4715 -0
- sage/sandpiles/all.py +13 -0
- sage/sandpiles/examples.py +225 -0
- sage/sandpiles/sandpile.py +6365 -0
- sage/topology/all.py +22 -0
- sage/topology/cell_complex.py +1214 -0
- sage/topology/cubical_complex.py +1976 -0
- sage/topology/delta_complex.py +1806 -0
- sage/topology/filtered_simplicial_complex.py +744 -0
- sage/topology/moment_angle_complex.py +823 -0
- sage/topology/simplicial_complex.py +5160 -0
- sage/topology/simplicial_complex_catalog.py +92 -0
- sage/topology/simplicial_complex_examples.py +1680 -0
- sage/topology/simplicial_complex_homset.py +205 -0
- sage/topology/simplicial_complex_morphism.py +836 -0
- sage/topology/simplicial_set.py +4102 -0
- sage/topology/simplicial_set_catalog.py +55 -0
- sage/topology/simplicial_set_constructions.py +2954 -0
- sage/topology/simplicial_set_examples.py +865 -0
- sage/topology/simplicial_set_morphism.py +1464 -0
@@ -0,0 +1,13 @@
|
|
1
|
+
# sage_setup: distribution = sagemath-graphs
|
2
|
+
from libc.stdint cimport uint8_t
|
3
|
+
|
4
|
+
cdef class FastDigraph:
|
5
|
+
cdef uint8_t n
|
6
|
+
cdef int * graph
|
7
|
+
cdef list int_to_vertices
|
8
|
+
cdef int * degree
|
9
|
+
|
10
|
+
cdef int compute_out_neighborhood_cardinality(FastDigraph, int) noexcept
|
11
|
+
|
12
|
+
cdef int popcount32(int) noexcept
|
13
|
+
cdef int slow_popcount32(int) noexcept
|
@@ -0,0 +1,212 @@
|
|
1
|
+
# sage_setup: distribution = sagemath-graphs
|
2
|
+
r"""
|
3
|
+
Compact structure for fast operations on less than 32 vertices
|
4
|
+
|
5
|
+
This module implements a digraph structure meant to be used in Cython in
|
6
|
+
**highly enumerative** algorithms. It can store graphs on less than
|
7
|
+
``sizeof(int)`` vertices and perform several basic operations **quickly**
|
8
|
+
(add/remove arcs, count the out-neighborhood of a set of vertices or return its
|
9
|
+
cardinality).
|
10
|
+
|
11
|
+
**Sets and integers :**
|
12
|
+
|
13
|
+
In the following code, sets are represented as integers, where the `i`-th bit is
|
14
|
+
set if element `i` belongs to the set.
|
15
|
+
"""
|
16
|
+
from cysignals.memory cimport check_allocarray, check_calloc, sig_free
|
17
|
+
|
18
|
+
|
19
|
+
cdef class FastDigraph:
|
20
|
+
|
21
|
+
def __cinit__(self, D, vertex_list=None):
|
22
|
+
r"""
|
23
|
+
Constructor for ``FastDigraph``.
|
24
|
+
|
25
|
+
If the input parameter ``D`` is a Graph, it is handled as a symmetric
|
26
|
+
DiGraph.
|
27
|
+
|
28
|
+
INPUT:
|
29
|
+
|
30
|
+
- ``D`` -- a (Di)Graph
|
31
|
+
|
32
|
+
- ``vertex_list`` -- list (default: ``None``); specifies a mapping
|
33
|
+
between `[0..n-1]` and the set of vertices of the input (Di)Graph,
|
34
|
+
``list(D)`` by default
|
35
|
+
|
36
|
+
EXAMPLES::
|
37
|
+
|
38
|
+
sage: cython_code = [
|
39
|
+
....: 'from sage.graphs.graph import Graph',
|
40
|
+
....: 'from sage.graphs.graph_decompositions.fast_digraph cimport FastDigraph',
|
41
|
+
....: 'G = Graph([(0, 1), (1, 2)])',
|
42
|
+
....: 'cdef FastDigraph F = FastDigraph(G)',
|
43
|
+
....: 'cdef int i',
|
44
|
+
....: 'print([F.degree[i] for i in range(F.n)])']
|
45
|
+
sage: cython(os.linesep.join(cython_code)) # needs sage.misc.cython
|
46
|
+
[1, 2, 1]
|
47
|
+
"""
|
48
|
+
if D.order() > 8*sizeof(int):
|
49
|
+
raise OverflowError("Too many vertices. This structure can only "
|
50
|
+
"encode digraphs on at most "
|
51
|
+
"%i vertices" % (8 * sizeof(int)))
|
52
|
+
|
53
|
+
self.n = D.order()
|
54
|
+
self.graph = <int *>check_calloc(self.n, sizeof(int))
|
55
|
+
|
56
|
+
cdef int i
|
57
|
+
cdef int tmp
|
58
|
+
|
59
|
+
# When the vertices are not consecutive integers
|
60
|
+
if vertex_list is None:
|
61
|
+
self.int_to_vertices = list(D)
|
62
|
+
elif len(vertex_list) == self.n and not set(vertex_list).symmetric_difference(D):
|
63
|
+
self.int_to_vertices = list(vertex_list)
|
64
|
+
else:
|
65
|
+
raise ValueError("the input vertex_list is incorrect")
|
66
|
+
cdef dict vertices_to_int = {v: i for i, v in enumerate(self.int_to_vertices)}
|
67
|
+
|
68
|
+
if D.is_directed():
|
69
|
+
for u in D:
|
70
|
+
tmp = 0
|
71
|
+
for v in D.neighbors_out(u):
|
72
|
+
tmp |= 1 << vertices_to_int[v]
|
73
|
+
self.graph[vertices_to_int[u]] = tmp
|
74
|
+
else:
|
75
|
+
for u in D:
|
76
|
+
tmp = 0
|
77
|
+
for v in D.neighbors(u):
|
78
|
+
tmp |= 1 << vertices_to_int[v]
|
79
|
+
self.graph[vertices_to_int[u]] = tmp
|
80
|
+
|
81
|
+
self.degree = <int *>check_allocarray(self.n, sizeof(int))
|
82
|
+
for i in range(self.n):
|
83
|
+
self.degree[i] = popcount32(self.graph[i])
|
84
|
+
|
85
|
+
def __dealloc__(self):
|
86
|
+
r"""
|
87
|
+
Destructor.
|
88
|
+
"""
|
89
|
+
sig_free(self.graph)
|
90
|
+
sig_free(self.degree)
|
91
|
+
|
92
|
+
def print_adjacency_matrix(self):
|
93
|
+
r"""
|
94
|
+
Display the adjacency matrix of ``self``.
|
95
|
+
|
96
|
+
EXAMPLES::
|
97
|
+
|
98
|
+
sage: cython_code = [
|
99
|
+
....: 'from sage.graphs.graph import Graph',
|
100
|
+
....: 'from sage.graphs.graph_decompositions.fast_digraph cimport FastDigraph',
|
101
|
+
....: 'FastDigraph(Graph([(0, 1), (1, 2)])).print_adjacency_matrix()']
|
102
|
+
sage: cython(os.linesep.join(cython_code)) # needs sage.misc.cython
|
103
|
+
010
|
104
|
+
101
|
105
|
+
010
|
106
|
+
"""
|
107
|
+
cdef int i, j
|
108
|
+
for i in range(self.n):
|
109
|
+
for j in range(self.n):
|
110
|
+
print(((self.graph[i] >> j) & 1), end="")
|
111
|
+
print("")
|
112
|
+
|
113
|
+
cdef inline int compute_out_neighborhood_cardinality(FastDigraph g, int S) noexcept:
|
114
|
+
r"""
|
115
|
+
Return the cardinality of `N^+(S)\S`.
|
116
|
+
|
117
|
+
INPUT:
|
118
|
+
|
119
|
+
- ``g`` -- a FastDigraph
|
120
|
+
|
121
|
+
- ``S`` -- integer describing the set
|
122
|
+
|
123
|
+
EXAMPLES::
|
124
|
+
|
125
|
+
sage: cython_code = [
|
126
|
+
....: 'from sage.graphs.graph import Graph',
|
127
|
+
....: 'from sage.graphs.graph_decompositions.fast_digraph cimport FastDigraph',
|
128
|
+
....: 'from sage.graphs.graph_decompositions.fast_digraph cimport compute_out_neighborhood_cardinality',
|
129
|
+
....: 'cdef FastDigraph F = FastDigraph(Graph([(0, 1), (1, 2)]))',
|
130
|
+
....: 'cdef int i',
|
131
|
+
....: 'print([compute_out_neighborhood_cardinality(F, 1<<i) for i in range(F.n)])']
|
132
|
+
sage: cython(os.linesep.join(cython_code)) # needs sage.misc.cython
|
133
|
+
[1, 2, 1]
|
134
|
+
"""
|
135
|
+
cdef int i
|
136
|
+
cdef int tmp = 0
|
137
|
+
for i in range(g.n):
|
138
|
+
tmp |= g.graph[i] & (-((S >> i) & 1))
|
139
|
+
|
140
|
+
tmp &= (~S)
|
141
|
+
return popcount32(tmp)
|
142
|
+
|
143
|
+
cdef inline int popcount32(int i) noexcept:
|
144
|
+
r"""
|
145
|
+
Return the number of '1' bits in a 32-bits integer.
|
146
|
+
|
147
|
+
If ``sizeof(int) > 4``, this function only returns the number of '1'
|
148
|
+
bits in ``(i & ((1<<32) - 1))``.
|
149
|
+
|
150
|
+
EXAMPLES::
|
151
|
+
|
152
|
+
sage: cython_code = [
|
153
|
+
....: 'from sage.graphs.graph_decompositions.fast_digraph cimport popcount32',
|
154
|
+
....: 'cdef int i',
|
155
|
+
....: 'print([popcount32(i) for i in range(16)])']
|
156
|
+
sage: cython(os.linesep.join(cython_code)) # needs sage.misc.cython
|
157
|
+
[0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4]
|
158
|
+
"""
|
159
|
+
i = i - ((i >> 1) & 0x55555555)
|
160
|
+
i = (i & 0x33333333) + ((i >> 2) & 0x33333333)
|
161
|
+
return ((i + (i >> 4) & 0x0F0F0F0F) * 0x01010101) >> 24
|
162
|
+
|
163
|
+
|
164
|
+
# If you happened to be doubting the consistency of the popcount32 function
|
165
|
+
# above, you can give the following doctest a try. It is not tested
|
166
|
+
# automatically by Sage as it takes a *LONG* time to run (around 5 minutes), but
|
167
|
+
# it would report any problem if it finds one.
|
168
|
+
|
169
|
+
def test_popcount():
|
170
|
+
"""
|
171
|
+
Correction test for popcount32.
|
172
|
+
|
173
|
+
EXAMPLES::
|
174
|
+
|
175
|
+
sage: from sage.graphs.graph_decompositions.fast_digraph import test_popcount
|
176
|
+
sage: test_popcount() # not tested
|
177
|
+
"""
|
178
|
+
cdef int i = 1
|
179
|
+
# While the last 32 bits of i are not equal to 0
|
180
|
+
while (i & ((1 << 32) - 1)):
|
181
|
+
if popcount32(i) != slow_popcount32(i):
|
182
|
+
print("Error for i = ", str(i))
|
183
|
+
print("Result with popcount32 : " + str(popcount32(i)))
|
184
|
+
print("Result with slow_popcount32 : " + str(slow_popcount32(i)))
|
185
|
+
i += 1
|
186
|
+
|
187
|
+
|
188
|
+
cdef inline int slow_popcount32(int i) noexcept:
|
189
|
+
"""
|
190
|
+
Return the number of '1' bits in a 32-bits integer.
|
191
|
+
|
192
|
+
If ``sizeof(int) > 4``, this function only returns the number of '1'
|
193
|
+
bits in ``(i & ((1<<32) - 1))``.
|
194
|
+
|
195
|
+
EXAMPLES::
|
196
|
+
|
197
|
+
sage: cython_code = [
|
198
|
+
....: 'from sage.graphs.graph_decompositions.fast_digraph cimport popcount32',
|
199
|
+
....: 'from sage.graphs.graph_decompositions.fast_digraph cimport slow_popcount32',
|
200
|
+
....: 'cdef int i',
|
201
|
+
....: 'print(all(popcount32(i) == slow_popcount32(i) for i in range(16)))']
|
202
|
+
sage: cython(os.linesep.join(cython_code)) # needs sage.misc.cython
|
203
|
+
True
|
204
|
+
"""
|
205
|
+
# Slow popcount for 32bits integers
|
206
|
+
cdef int j = 0
|
207
|
+
cdef int k
|
208
|
+
|
209
|
+
for k in range(32):
|
210
|
+
j += (i >> k) & 1
|
211
|
+
|
212
|
+
return j
|