Commit c8c4518d authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

Docstring tests update

parent bb2e8bf4
......@@ -658,7 +658,7 @@ def get_akc(B, I, N=float("inf"), directed=False):
--------
>>> gt.get_akc(10, log(10) / 100, N=100)
2.4199998721289937
2.4199998936261204
References
----------
......
......@@ -191,13 +191,13 @@ def scalar_assortativity(g, deg):
... vertex_corr=lambda i,k: abs(i-k),
... directed=False, n_iter=100)
>>> gt.scalar_assortativity(g, "out")
(-0.4334085753985522, 0.010571027872280038)
(-0.44070158356400696, 0.010592022444678632)
>>> g = gt.random_graph(1000, lambda: sample_k(40), model="probabilistic",
... vertex_corr=lambda i, k: 1.0 / (1 + abs(i - k)),
... directed=False, n_iter=100)
>>> gt.scalar_assortativity(g, "out")
(0.5994169713159511, 0.011668093738666827)
(0.6007430887839058, 0.011569809783643956)
References
----------
......
......@@ -140,7 +140,7 @@ def edmonds_karp_max_flow(g, source, target, capacity, residual=None):
>>> res.a = cap.a - res.a # the actual flow
>>> max_flow = sum(res[e] for e in tgt.in_edges())
>>> print(max_flow)
44.890595784116144
44.89059578411614
>>> pos = g.vertex_properties["pos"]
>>> gt.graph_draw(g, pos=pos, edge_pen_width=gt.prop_to_size(res, mi=0, ma=5, power=1), output="example-edmonds-karp.pdf")
<...>
......@@ -221,7 +221,7 @@ def push_relabel_max_flow(g, source, target, capacity, residual=None):
>>> res.a = cap.a - res.a # the actual flow
>>> max_flow = sum(res[e] for e in tgt.in_edges())
>>> print(max_flow)
44.890595784116144
44.89059578411614
>>> pos = g.vertex_properties["pos"]
>>> gt.graph_draw(g, pos=pos, edge_pen_width=gt.prop_to_size(res, mi=0, ma=5, power=1), output="example-push-relabel.pdf")
<...>
......@@ -303,7 +303,7 @@ def boykov_kolmogorov_max_flow(g, source, target, capacity, residual=None):
>>> res.a = cap.a - res.a # the actual flow
>>> max_flow = sum(res[e] for e in tgt.in_edges())
>>> print(max_flow)
44.890595784116144
44.89059578411614
>>> pos = g.vertex_properties["pos"]
>>> gt.graph_draw(g, pos=pos, edge_pen_width=gt.prop_to_size(res, mi=0, ma=3, power=1), output="example-kolmogorov.pdf")
<...>
......
......@@ -314,13 +314,13 @@ def random_graph(N, deg_sampler, directed=True,
... model="blockmodel-traditional",
... block_membership=lambda: randint(10),
... vertex_corr=corr)
>>> gt.graph_draw(g, vertex_fill_color=bm, output="blockmodel.pdf")
>>> gt.graph_draw(g, vertex_fill_color=bm, edge_color="black", output="blockmodel.pdf")
<...>
.. testcode::
:hide:
gt.graph_draw(g, vertex_fill_color=bm, output="blockmodel.png")
gt.graph_draw(g, vertex_fill_color=bm, edge_color="black", output="blockmodel.png")
.. figure:: blockmodel.*
:align: center
......@@ -584,7 +584,7 @@ def random_rewire(g, model="uncorrelated", n_iter=1, edge_sweep=True,
gt.graph_draw(g, pos=pos, output="rewire_orig.png", output_size=(300, 300))
>>> gt.random_rewire(g, "correlated")
<...>
189
>>> pos = gt.arf_layout(g)
>>> gt.graph_draw(g, pos=pos, output="rewire_corr.pdf", output_size=(300, 300))
<...>
......@@ -595,7 +595,7 @@ def random_rewire(g, model="uncorrelated", n_iter=1, edge_sweep=True,
gt.graph_draw(g, pos=pos, output="rewire_corr.png", output_size=(300, 300))
>>> gt.random_rewire(g)
<...>
197
>>> pos = gt.arf_layout(g)
>>> gt.graph_draw(g, pos=pos, output="rewire_uncorr.pdf", output_size=(300, 300))
<...>
......@@ -606,7 +606,7 @@ def random_rewire(g, model="uncorrelated", n_iter=1, edge_sweep=True,
gt.graph_draw(g, pos=pos, output="rewire_uncorr.png", output_size=(300, 300))
>>> gt.random_rewire(g, "erdos")
<...>
26
>>> pos = gt.arf_layout(g)
>>> gt.graph_draw(g, pos=pos, output="rewire_erdos.pdf", output_size=(300, 300))
<...>
......@@ -637,17 +637,17 @@ def random_rewire(g, model="uncorrelated", n_iter=1, edge_sweep=True,
>>> errorbar(corr[2][:-1], corr[0], yerr=corr[1], fmt="o-", label="Original")
<...>
>>> gt.random_rewire(g, "correlated")
<...>
206
>>> corr = gt.avg_neighbour_corr(g, "out", "out")
>>> errorbar(corr[2][:-1], corr[0], yerr=corr[1], fmt="*", label="Correlated")
<...>
>>> gt.random_rewire(g)
<...>
109
>>> corr = gt.avg_neighbour_corr(g, "out", "out")
>>> errorbar(corr[2][:-1], corr[0], yerr=corr[1], fmt="o-", label="Uncorrelated")
<...>
>>> gt.random_rewire(g, "erdos")
<...>
13
>>> corr = gt.avg_neighbour_corr(g, "out", "out")
>>> errorbar(corr[2][:-1], corr[0], yerr=corr[1], fmt="o-", label=r"Erd\H{o}s")
<...>
......@@ -693,7 +693,7 @@ def random_rewire(g, model="uncorrelated", n_iter=1, edge_sweep=True,
... label=r"$\left<\text{i}\right>$ vs o")
<...>
>>> gt.random_rewire(g, "correlated")
<...>
4323
>>> corr = gt.avg_neighbour_corr(g, "in", "out")
>>> errorbar(corr[2][:-1], corr[0], yerr=corr[1], fmt="o-",
... label=r"$\left<\text{o}\right>$ vs i, corr.")
......@@ -703,7 +703,7 @@ def random_rewire(g, model="uncorrelated", n_iter=1, edge_sweep=True,
... label=r"$\left<\text{i}\right>$ vs o, corr.")
<...>
>>> gt.random_rewire(g, "uncorrelated")
<...>
153
>>> corr = gt.avg_neighbour_corr(g, "in", "out")
>>> errorbar(corr[2][:-1], corr[0], yerr=corr[1], fmt="o-",
... label=r"$\left<\text{o}\right>$ vs i, uncorr.")
......
......@@ -64,7 +64,7 @@ def adjacency(g, weight=None, index=None):
Returns
-------
a : :mod:`~scipy.sparse.csr_matrix`
a : :class:`~scipy.sparse.csr_matrix`
The (sparse) adjacency matrix.
Notes
......@@ -76,11 +76,12 @@ def adjacency(g, weight=None, index=None):
a_{i,j} =
\begin{cases}
1 & \text{if } v_i \text{ is adjacent to } v_j, \\
2 & \text{if } i = j, \text{ the graph is undirected and there is a self-loop incident in } v_i, \\
0 & \text{otherwise}
\end{cases}
In the case of weighted edges, the value 1 is replaced the weight of the
respective edge.
In the case of weighted edges, the entry values are multiplied by the weight
of the respective edge.
In the case of networks with parallel edges, the entries in the matrix
become simply the edge multiplicities.
......@@ -89,18 +90,33 @@ def adjacency(g, weight=None, index=None):
--------
.. testsetup::
gt.seed_rng(42)
import scipy.linalg
from pylab import *
>>> g = gt.random_graph(100, lambda: (10, 10))
>>> m = gt.adjacency(g)
>>> print(m.todense())
[[ 0. 0. 0. ..., 0. 1. 0.]
[ 0. 0. 0. ..., 0. 0. 0.]
[ 0. 0. 0. ..., 0. 0. 1.]
...,
[ 0. 0. 0. ..., 0. 0. 0.]
[ 0. 0. 0. ..., 0. 0. 0.]
[ 0. 0. 1. ..., 0. 0. 0.]]
>>> g = gt.collection.data["polblogs"]
>>> A = gt.adjacency(g)
>>> ew, ev = scipy.linalg.eig(A.todense())
>>> figure(figsize=(8, 2))
<...>
>>> scatter(real(ew), imag(ew), c=abs(ew))
<...>
>>> xlabel(r"$\operatorname{Re}(\lambda)$")
<...>
>>> ylabel(r"$\operatorname{Im}(\lambda)$")
<...>
>>> tight_layout()
>>> savefig("adjacency-spectrum.pdf")
.. testcode::
:hide:
savefig("adjacency-spectrum.png")
.. figure:: adjacency-spectrum.*
:align: center
Adjacency matrix spectrum for the political blog network.
References
----------
......@@ -121,13 +137,14 @@ def adjacency(g, weight=None, index=None):
libgraph_tool_spectral.adjacency(g._Graph__graph, _prop("v", g, index),
_prop("e", g, weight), data, i, j)
m = scipy.sparse.coo_matrix((data, (i,j)))
V = max(g.num_vertices(), max(i.max() + 1, j.max() + 1))
m = scipy.sparse.coo_matrix((data, (i,j)), shape=(V, V))
m = m.tocsr()
return m
@_limit_args({"deg": ["total", "in", "out"]})
def laplacian(g, deg="total", normalized=True, weight=None, index=None):
def laplacian(g, deg="total", normalized=False, weight=None, index=None):
r"""Return the Laplacian matrix of the graph.
Parameters
......@@ -136,7 +153,7 @@ def laplacian(g, deg="total", normalized=True, weight=None, index=None):
Graph to be used.
deg : str (optional, default: "total")
Degree to be used, in case of a directed graph.
normalized : bool (optional, default: True)
normalized : bool (optional, default: False)
Whether to compute the normalized Laplacian.
weight : :class:`~graph_tool.PropertyMap` (optional, default: True)
Edge property map with the edge weights.
......@@ -146,7 +163,7 @@ def laplacian(g, deg="total", normalized=True, weight=None, index=None):
Returns
-------
l : :mod:`~scipy.sparse.csr_matrix`
l : :class:`~scipy.sparse.csr_matrix`
The (sparse) Laplacian matrix.
Notes
......@@ -182,20 +199,60 @@ def laplacian(g, deg="total", normalized=True, weight=None, index=None):
Examples
--------
.. testsetup::
gt.seed_rng(42)
import scipy.linalg
from pylab import *
>>> g = gt.random_graph(100, lambda: (10,10))
>>> m = gt.laplacian(g)
>>> print(m.todense())
[[ 1. -0.05 0. ..., 0. 0. 0. ]
[ 0. 1. 0. ..., 0. 0. -0.05]
[ 0. 0. 1. ..., 0. -0.05 0. ]
...,
[ 0. 0. 0. ..., 1. 0. 0. ]
[-0.05 0. 0. ..., 0. 1. 0. ]
[ 0. 0. 0. ..., -0.05 0. 1. ]]
>>> g = gt.collection.data["polblogs"]
>>> L = gt.laplacian(g)
>>> ew, ev = scipy.linalg.eig(L.todense())
>>> figure(figsize=(8, 2))
<...>
>>> scatter(real(ew), imag(ew), c=abs(ew))
<...>
>>> xlabel(r"$\operatorname{Re}(\lambda)$")
<...>
>>> ylabel(r"$\operatorname{Im}(\lambda)$")
<...>
>>> tight_layout()
>>> savefig("laplacian-spectrum.pdf")
.. testcode::
:hide:
savefig("laplacian-spectrum.png")
.. figure:: laplacian-spectrum.*
:align: center
Laplacian matrix spectrum for the political blog network.
>>> L = gt.laplacian(g, normalized=True)
>>> ew, ev = scipy.linalg.eig(L.todense())
>>> figure(figsize=(8, 2))
<...>
>>> scatter(real(ew), imag(ew), c=abs(ew))
<...>
>>> xlabel(r"$\operatorname{Re}(\lambda)$")
<...>
>>> ylabel(r"$\operatorname{Im}(\lambda)$")
<...>
>>> tight_layout()
>>> savefig("norm-laplacian-spectrum.pdf")
.. testcode::
:hide:
savefig("norm-laplacian-spectrum.png")
.. figure:: norm-laplacian-spectrum.*
:align: center
Normalized Laplacian matrix spectrum for the political blog network.
References
----------
......@@ -209,6 +266,7 @@ def laplacian(g, deg="total", normalized=True, weight=None, index=None):
else:
index = g.vertex_index
V = g.num_vertices()
nself = label_self_loops(g, mark_only=True).a.sum()
E = g.num_edges() - nself
if not g.is_directed():
......@@ -224,7 +282,8 @@ def laplacian(g, deg="total", normalized=True, weight=None, index=None):
else:
libgraph_tool_spectral.laplacian(g._Graph__graph, _prop("v", g, index),
_prop("e", g, weight), deg, data, i, j)
m = scipy.sparse.coo_matrix((data, (i,j)))
V = max(g.num_vertices(), max(i.max() + 1, j.max() + 1))
m = scipy.sparse.coo_matrix((data, (i, j)), shape=(V, V))
m = m.tocsr()
return m
......@@ -245,8 +304,8 @@ def incidence(g, vindex=None, eindex=None):
Returns
-------
a : :mod:`~scipy.sparse.csr_matrix`
The (sparse) adjacency matrix.
a : :class:`~scipy.sparse.csr_matrix`
The (sparse) incidence matrix.
Notes
-----
......@@ -281,12 +340,12 @@ def incidence(g, vindex=None, eindex=None):
>>> m = gt.incidence(g)
>>> print(m.todense())
[[-1. -1. 0. ..., 0. 0. 0.]
[ 0. 0. -1. ..., 0. 0. 0.]
[ 0. 0. 0. ..., 0. 0. 0.]
[ 0. 0. 0. ..., 0. 0. 0.]
...,
[ 0. 0. -1. ..., 0. 0. 0.]
[ 0. 0. 0. ..., 0. 0. 0.]
[ 0. 0. 0. ..., -1. 0. 0.]
[ 0. 0. 0. ..., 0. -1. -1.]]
[ 0. 0. 0. ..., 1. 0. 0.]]
References
----------
......
......@@ -231,7 +231,7 @@ def vertex_average(g, deg):
>>> from numpy.random import poisson
>>> g = gt.random_graph(1000, lambda: (poisson(5), poisson(5)))
>>> print(gt.vertex_average(g, "in"))
(4.98, 0.06840760191674607)
(4.982, 0.06855418295042251)
"""
ret = libgraph_tool_stats.\
......@@ -284,7 +284,7 @@ def edge_average(g, eprop):
>>> eprop = g.new_edge_property("double")
>>> eprop.get_array()[:] = random(g.num_edges())
>>> print(gt.edge_average(g, eprop))
(0.4979474933948808, 0.004104589512548127)
(0.49849732125677476, 0.004086182531863621)
"""
ret = libgraph_tool_stats.\
......@@ -408,10 +408,10 @@ def distance_histogram(g, weight=None, bins=[0, 1], samples=None,
>>> g = gt.random_graph(100, lambda: (3, 3))
>>> hist = gt.distance_histogram(g)
>>> print(hist)
[array([ 0., 300., 856., 2185., 3840., 2516., 203.]), array([0, 1, 2, 3, 4, 5, 6, 7], dtype=uint64)]
[array([ 0., 300., 866., 2206., 3893., 2476., 159.]), array([0, 1, 2, 3, 4, 5, 6, 7], dtype=uint64)]
>>> hist = gt.distance_histogram(g, samples=10)
>>> print(hist)
[array([ 0., 30., 87., 227., 390., 242., 14.]), array([0, 1, 2, 3, 4, 5, 6, 7], dtype=uint64)]
[array([ 0., 30., 84., 217., 385., 249., 25.]), array([0, 1, 2, 3, 4, 5, 6, 7], dtype=uint64)]
"""
if samples != None:
......
......@@ -126,9 +126,10 @@ def similarity(g1, g2, label1=None, label2=None, norm=True):
>>> u = g.copy()
>>> gt.similarity(u, g)
1.0
>>> gt.random_rewire(u);
>>> gt.random_rewire(u)
21
>>> gt.similarity(u, g)
0.05
0.03
"""
if label1 is None:
......@@ -229,11 +230,11 @@ def subgraph_isomorphism(sub, g, max_n=0, random=False):
gt.seed_rng(44)
>>> from numpy.random import poisson
>>> g = gt.random_graph(30, lambda: (poisson(6.0), poisson(6.0)))
>>> g = gt.random_graph(30, lambda: (poisson(6.1), poisson(6.1)))
>>> sub = gt.random_graph(10, lambda: (poisson(1.9), poisson(1.9)))
>>> vm, em = gt.subgraph_isomorphism(sub, g)
>>> print(len(vm))
5632
35
>>> for i in range(len(vm)):
... g.set_vertex_filter(None)
... g.set_edge_filter(None)
......@@ -540,10 +541,10 @@ def dominator_tree(g, root, dom_map=None):
>>> root = [v for v in g.vertices() if v.in_degree() == 0]
>>> dom = gt.dominator_tree(g, root[0])
>>> print(dom.a)
[ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 78 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
[ 0 0 0 0 0 0 62 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 15 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
References
----------
......@@ -590,8 +591,8 @@ def topological_sort(g):
>>> g.set_edge_filter(tree)
>>> sort = gt.topological_sort(g)
>>> print(sort)
[17 1 20 5 6 8 28 0 3 9 11 24 29 2 22 4 7 14 19 26 23 10 12 13 15
16 18 21 25 27]
[ 1 14 2 7 17 0 3 4 5 6 8 9 22 10 11 12 13 16 23 27 15 18 19 20 21
24 25 26 28 29]
References
----------
......@@ -699,17 +700,18 @@ def label_components(g, vprop=None, directed=None, attractors=False):
>>> g = gt.random_graph(100, lambda: (poisson(2), poisson(2)))
>>> comp, hist, is_attractor = gt.label_components(g, attractors=True)
>>> print(comp.a)
[12 12 12 12 12 12 12 12 13 12 12 12 12 12 11 12 5 14 12 12 7 15 12 12 12
12 12 12 12 12 12 12 12 12 16 12 2 0 12 17 12 12 1 12 12 10 12 18 12 21
12 12 12 6 9 12 12 22 12 12 12 12 3 12 8 23 24 12 12 12 25 12 12 12 12
12 27 28 12 12 26 12 20 12 12 12 12 12 12 12 12 29 30 19 12 4 12 31 12 12]
[14 15 14 14 14 5 14 14 18 14 14 8 14 14 13 14 14 21 14 14 7 23 10 14 14
14 24 4 14 14 0 14 14 14 25 14 14 1 14 26 14 19 9 14 14 3 14 14 27 28
29 14 14 6 14 14 14 30 14 14 20 14 2 14 22 33 34 14 14 14 35 14 14 16 14
11 36 37 14 14 31 14 14 17 14 14 14 14 14 0 14 38 39 32 14 12 14 40 14 14]
>>> print(hist)
[ 1 1 1 1 1 1 1 1 1 1 1 1 69 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1]
[ 2 1 1 1 1 1 1 1 1 1 1 1 1 1 59 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]
>>> print(is_attractor)
[ True False False True True False True True True False False True
[ True True True False False False True True False False False False
True True False False False False False False False False True False
False False False False False False False False False False False False
False False False False False False False False]
False False False False False]
"""
if vprop is None:
......@@ -770,12 +772,12 @@ def label_largest_component(g, directed=None):
>>> g = gt.random_graph(100, lambda: poisson(1), directed=False)
>>> l = gt.label_largest_component(g)
>>> print(l.a)
[0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 1 0 0 0 0 0 1 0 0 1 0 0 0 0 0 1 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0]
[1 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0
0 0 0 0 0 0 0 0 1 0 0 0 1 0 1 1 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0
0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1]
>>> u = gt.GraphView(g, vfilt=l) # extract the largest component as a graph
>>> print(u.num_vertices())
10
16
"""
label = g.new_vertex_property("bool")
......@@ -821,18 +823,18 @@ def label_out_component(g, root):
>>> g = gt.random_graph(100, lambda: poisson(2.2), directed=False)
>>> l = gt.label_out_component(g, g.vertex(2))
>>> print(l.a)
[1 1 1 1 0 1 0 1 1 1 1 0 1 1 1 0 1 1 1 1 1 0 1 1 1 1 1 0 1 1 1 0 0 1 1 0 0
1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 0 1 0 1 1 1 1 1 1 1 1 1 1 0 0 1 0 1 1 1 1 1
1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 0 1 1 1 0]
[1 1 1 1 0 1 1 1 1 1 1 0 1 1 0 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 0 0 1 1 1 0
1 1 0 0 1 1 0 1 1 0 0 1 1 1 1 0 1 0 0 1 1 1 1 1 1 1 1 1 0 0 1 0 1 1 1 1 1
1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 0 1 1 0 0]
The in-component can be obtained by reversing the graph.
>>> l = gt.label_out_component(gt.GraphView(g, reversed=True, directed=True),
... g.vertex(1))
>>> print(l.a)
[0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[1 1 1 0 0 1 1 0 1 0 0 0 0 1 0 0 0 1 0 0 1 1 0 0 1 0 1 0 0 0 0 0 0 1 1 0 0
0 1 0 0 0 1 0 1 1 0 0 0 0 1 1 0 0 0 0 1 0 0 0 1 1 0 1 0 0 0 1 0 0 1 1 0 1
1 0 0 0 0 1 1 0 1 1 0 1 1 1 0 0 1 0 0 0 0 0 1 0 0 0]
"""
label = g.new_vertex_property("bool")
......@@ -901,18 +903,21 @@ def label_biconnected_components(g, eprop=None, vprop=None):
numpy.random.seed(42)
gt.seed_rng(42)
>>> g = gt.random_graph(100, lambda: 2, directed=False)
>>> g = gt.random_graph(100, lambda: poisson(2), directed=False)
>>> comp, art, hist = gt.label_biconnected_components(g)
>>> print(comp.a)
[1 1 0 1 0 1 1 2 1 1 3 3 0 2 2 1 1 3 2 1 0 1 1 1 1 3 1 2 1 3 4 3 1 1 4 0 0
0 1 1 1 1 2 1 1 2 2 2 2 0 1 0 1 1 1 1 2 2 1 1 1 1 1 0 1 1 0 0 1 0 1 4 1 2
1 1 1 1 0 1 2 1 1 1 1 1 1 1 1 1 4 1 1 1 1 3 1 3 1 3]
[51 51 51 51 51 51 11 52 51 51 44 42 41 45 49 23 19 51 51 32 38 51 24 37 51
51 51 10 8 51 20 43 51 51 51 51 51 47 46 51 51 13 14 51 51 51 51 33 30 51
1 21 51 51 51 35 36 6 51 26 27 7 12 4 3 29 28 51 51 51 31 51 51 0 39
51 51 51 34 40 51 51 9 17 51 51 18 15 22 2 16 50 5 48 51 51 53 51 51 25]
>>> print(art.a)
[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[1 0 1 0 0 1 0 0 1 1 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 0 1 0 0 0 1 0 0 0 1 1 0
0 1 0 0 1 1 0 1 1 0 0 0 1 1 0 1 1 0 0 0 1 0 0 1 0 1 0 0 1 1 0 0 0 0 0 1 1
1 0 1 1 0 1 0 1 1 0 0 0 0 1 0 1 0 0 0 1 0 0 0 1 0 0]
>>> print(hist)
[14 59 14 9 4]
[ 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 47 1 1]
"""
if vprop is None:
......@@ -1078,43 +1083,43 @@ def shortest_distance(g, source=None, target=None, weights=None, max_dist=None,
>>> g = gt.random_graph(100, lambda: (poisson(3), poisson(3)))
>>> dist = gt.shortest_distance(g, source=g.vertex(0))
>>> print(dist.a)
[ 0 4 4 4 2147483647 2147483647
6 7 6 4 5 5
6 4 6 7 4 6
6 1 7 5 6 3
5 7 5 6 7 7
8 6 5 4 5 7
6 7 6 6 2147483647 6
3 7 5 6 7 5
8 5 6 5 4 6
6 4 7 9 6 3
7 6 3 5 7 4
6 8 7 6 2147483647 2147483647
2 5 6 5 7 6
6 5 7 5 5 4
7 6 6 5 3 6
6 8 5 4 5 6
5 6 7 4]
[ 0 6 3 6 2147483647 2147483647
6 5 2 4 5 6
6 3 7 5 4 4
3 4 2 4 3 3
4 4 6 6 4 1
5 2 4 5 3 5
6 5 4 5 2147483647 9
4 4 4 6 3 4
6 6 3 2 4 4
5 4 5 8 6 6
5 5 4 5 6 3
4 3 5 5 2147483647 2147483647
5 5 8 3 7 4
5 2 7 5 2 5
5 5 7 7 4 3
6 5 5 4 5 5
4 4 6 5]
>>> dist = gt.shortest_distance(g)
>>> print(dist[g.vertex(0)].a)
[ 0 4 4 4 2147483647 2147483647
6 7 6 4 5 5
6 4 6 7 4 6
6 1 7 5 6 3
5 7 5 6 7 7
8 6 5 4 5 7
6 7 6 6 2147483647 6
3 7 5 6 7 5
8 5 6 5 4 6
6 4 7 9 6 3
7 6 3 5 7 4
6 8 7 6 2147483647 2147483647
2 5 6 5 7 6
6 5 7 5 5 4
7 6 6 5 3 6
6 8 5 4 5 6
5 6 7 4]
[ 0 6 3 6 2147483647 2147483647
6 5 2 4 5 6
6 3 7 5 4 4
3 4 2 4 3 3
4 4 6 6 4 1
5 2 4 5 3 5
6 5 4 5 2147483647 9
4 4 4 6 3 4
6 6 3 2 4 4
5 4 5 8 6 6
5 5 4 5 6 3
4 3 5 5 2147483647 2147483647
5 5 8 3 7 4
5 2 7 5 2 5
5 5 7 7 4 3
6 5 5 4 5 5
4 4 6 5]
References
----------
......@@ -1232,9 +1237,9 @@ def shortest_path(g, source, target, weights=None, pred_map=None):
>>> g = gt.random_graph(300, lambda: (poisson(4), poisson(4)))
>>> vlist, elist = gt.shortest_path(g, g.vertex(10), g.vertex(11))
>>> print([str(v) for v in vlist])
['10', '267', '212', '158', '112', '160', '11']
['10', '131', '184', '265', '223', '11']
>>> print([str(e) for e in elist])
['(10, 267)', '(267, 212)', '(212, 158)', '(158, 112)', '(112, 160)', '(160, 11)']
['(10, 131)', '(131, 184)', '(184, 265)', '(265, 223)', '(223, 11)']
References
----------
......@@ -1337,9 +1342,9 @@ def pseudo_diameter(g, source=None, weights=None):
>>> g = gt.random_graph(300, lambda: (poisson(3), poisson(3)))
>>> dist, ends = gt.pseudo_diameter(g)
>>> print(dist)