Commit ed348374 authored by Tiago Peixoto's avatar Tiago Peixoto

Fix doctests

parent 669e3448
......@@ -1109,10 +1109,10 @@ def map_property_values(src_prop, tgt_prop, map_func):
>>> gt.map_property_values(g.vp.label, label_len,
... lambda x: len(x))
>>> print(label_len.a)
[ 6 8 14 11 12 8 12 8 5 6 7 7 10 6 7 7 9 9 7 11 9 6 7 7 13
10 7 6 12 10 8 8 11 6 5 12 6 10 11 9 12 7 7 6 14 7 9 9 8 12
6 16 12 11 14 6 9 6 8 10 9 7 10 7 7 4 9 14 9 5 10 12 9 6 6
6 12]
[ 6 8 14 11 12 8 12 8 5 6 7 7 10 6 7 7 9 9 7 11 9 6 7 7
13 10 7 6 12 10 8 8 11 6 5 12 6 10 11 9 12 7 7 6 14 7 9 9
8 12 6 16 12 11 14 6 9 6 8 10 9 7 10 7 7 4 9 14 9 5 10 12
9 6 6 6 12]
"""
if src_prop.key_type() != tgt_prop.key_type():
......@@ -1186,18 +1186,19 @@ def edge_endpoint_property(g, prop, endpoint, eprop=None):
>>> g = gt.random_graph(100, lambda: (3, 3))
>>> esource = gt.edge_endpoint_property(g, g.vertex_index, "source")
>>> print(esource.a)
[ 0 0 0 96 96 96 92 92 92 88 88 88 84 84 84 80 80 80 76 76 76 72 72 72 68
68 68 64 64 64 60 60 60 56 56 56 52 52 52 48 48 48 44 44 44 40 40 40 36 36
36 32 32 32 28 28 28 24 24 24 20 20 20 16 16 16 12 12 12 8 8 8 4 4 4
99 99 99 1 1 1 2 2 2 3 3 3 5 5 5 6 6 6 7 7 7 9 9 9 10
10 10 14 14 14 19 19 19 25 25 25 30 30 30 35 35 35 41 41 41 46 46 46 51 51
51 57 57 57 62 62 62 67 67 67 73 73 73 78 78 78 83 83 83 89 89 89 94 94 94
11 11 11 98 98 98 97 97 97 95 95 95 93 93 93 91 91 91 90 90 90 87 87 87 86
86 86 85 85 85 82 82 82 81 81 81 79 79 79 77 77 77 75 75 75 74 74 74 71 71
71 69 69 69 61 61 61 54 54 54 47 47 47 39 39 39 33 33 33 26 26 26 18 18 18
70 70 70 13 13 13 15 15 15 17 17 17 21 21 21 22 22 22 23 23 23 27 27 27 29
29 29 31 31 31 34 34 34 37 37 37 38 38 38 42 42 42 43 43 43 45 45 45 49 49
49 50 50 50 53 53 53 55 55 55 58 58 58 59 59 59 63 63 63 65 65 65 66 66 66]
[ 0 0 0 96 96 96 92 92 92 88 88 88 84 84 84 80 80 80 76 76 76 72 72 72
68 68 68 64 64 64 60 60 60 56 56 56 52 52 52 48 48 48 44 44 44 40 40 40
36 36 36 32 32 32 28 28 28 24 24 24 20 20 20 16 16 16 12 12 12 8 8 8
4 4 4 99 99 99 1 1 1 2 2 2 3 3 3 5 5 5 6 6 6 7 7 7
9 9 9 10 10 10 14 14 14 19 19 19 25 25 25 30 30 30 35 35 35 41 41 41
46 46 46 51 51 51 57 57 57 62 62 62 67 67 67 73 73 73 78 78 78 83 83 83
89 89 89 94 94 94 11 11 11 98 98 98 97 97 97 95 95 95 93 93 93 91 91 91
90 90 90 87 87 87 86 86 86 85 85 85 82 82 82 81 81 81 79 79 79 77 77 77
75 75 75 74 74 74 71 71 71 69 69 69 61 61 61 54 54 54 47 47 47 39 39 39
33 33 33 26 26 26 18 18 18 70 70 70 13 13 13 15 15 15 17 17 17 21 21 21
22 22 22 23 23 23 27 27 27 29 29 29 31 31 31 34 34 34 37 37 37 38 38 38
42 42 42 43 43 43 45 45 45 49 49 49 50 50 50 53 53 53 55 55 55 58 58 58
59 59 59 63 63 63 65 65 65 66 66 66]
"""
val_t = prop.value_type()
......
......@@ -522,7 +522,7 @@ def motif_significance(g, k, n_shuffles=100, p=1.0, motif_list=None,
>>> print(len(motifs))
11
>>> print(zscores)
[0.22728646681107012, 0.21409572051644973, 0.0070220407889021114, 0.58721419671233477, -0.37770179603294357, -0.34847335047837341, 0.88618118013255021, -0.08, -0.2, -0.38, -0.2]
[0.22728646681107012, 0.21409572051644973, 0.007022040788902111, 0.5872141967123348, -0.37770179603294357, -0.3484733504783734, 0.8861811801325502, -0.08, -0.2, -0.38, -0.2]
"""
s_ms, counts = motifs(g, k, p, motif_list)
......
......@@ -1394,6 +1394,7 @@ def triangulation(points, type="simple", periodic=False):
from pylab import *
seed(42)
gt.seed_rng(42)
>>> points = random((500, 2)) * 4
>>> g, pos = gt.triangulation(points)
>>> weight = g.new_edge_property("double") # Edge weights corresponding to
......
......@@ -2056,7 +2056,7 @@ class BlockState(object):
>>> state.mcmc_sweep(niter=1000) # remove part of the transient
(...)
>>> for i in range(1000):
... ds, nmoves = state.mcmc_sweep(niter=10)
... state.mcmc_sweep(niter=10)
... pe = state.collect_edge_marginals(pe)
>>> gt.bethe_entropy(g, pe)[0]
-21.162075...
......@@ -2110,7 +2110,7 @@ class BlockState(object):
>>> state.mcmc_sweep(niter=1000) # remove part of the transient
(...)
>>> for i in range(1000):
... ds, nmoves = state.mcmc_sweep(niter=10)
... state.mcmc_sweep(niter=10)
... pv = state.collect_vertex_marginals(pv)
>>> gt.mf_entropy(g, pv)
7.578883...
......@@ -2176,7 +2176,7 @@ class BlockState(object):
>>> state.mcmc_sweep(niter=1000) # remove part of the transient
(...)
>>> for i in range(1000):
... ds, nmoves = state.mcmc_sweep(niter=10)
... state.mcmc_sweep(niter=10)
... ph = state.collect_partition_histogram(ph)
>>> gt.microstate_entropy(ph)
146.181674...
......
......@@ -185,7 +185,7 @@ def minimize_blockmodel_dl(g, B_min=None, B_max=None, b_min=None, b_max=None,
the number of nodes in the network.
Examples
-----
--------
.. testsetup:: mdl
......
......@@ -800,7 +800,7 @@ class NestedBlockState(object):
MCMC to sample hierarchical network partitions.
The arguments accepted are the same as in
:method:`graph_tool.inference.BlockState.mcmc_sweep`.
:meth:`graph_tool.inference.BlockState.mcmc_sweep`.
If the parameter ``c`` is a scalar, the values used at each level are
``c * 2 ** l`` for ``l`` in the range ``[0, L-1]``. Optionally, a list
......@@ -840,7 +840,7 @@ class NestedBlockState(object):
with multiple moves to sample hierarchical network partitions.
The arguments accepted are the same as in
:method:`graph_tool.inference.BlockState.multiflip_mcmc_sweep`.
:meth:`graph_tool.inference.BlockState.multiflip_mcmc_sweep`.
If the parameter ``c`` is a scalar, the values used at each level are
``c * 2 ** l`` for ``l`` in the range ``[0, L-1]``. Optionally, a list
......@@ -880,7 +880,7 @@ class NestedBlockState(object):
Wang-Landau algorithm.
The arguments accepted are the same as in
:method:`graph_tool.inference.BlockState.multicanonical_sweep`.
:meth:`graph_tool.inference.BlockState.multicanonical_sweep`.
"""
if _bm_test():
kwargs = dict(kwargs, test=False)
......
......@@ -369,13 +369,13 @@ def incidence(g, vindex=None, eindex=None):
>>> g = gt.random_graph(100, lambda: (2,2))
>>> m = gt.incidence(g)
>>> print(m.todense())
[[-1. -1. 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.]]
[[-1. -1. 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.]]
References
----------
......
......@@ -113,8 +113,9 @@ def vertex_hist(g, deg, bins=[0, 1], float_count=True):
>>> from numpy.random import poisson
>>> g = gt.random_graph(1000, lambda: (poisson(5), poisson(5)))
>>> print(gt.vertex_hist(g, "out"))
[array([ 7., 33., 91., 145., 165., 164., 152., 115., 62.,
29., 28., 6., 1., 1., 0., 1.]), array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16], dtype=uint...)]
[array([ 7., 33., 91., 145., 165., 164., 152., 115., 62., 29., 28.,
6., 1., 1., 0., 1.]), array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],
dtype=uint64)]
"""
ret = libgraph_tool_stats.\
......@@ -177,7 +178,7 @@ def edge_hist(g, eprop, bins=[0, 1], float_count=True):
>>> eprop = g.new_edge_property("double")
>>> eprop.get_array()[:] = random(g.num_edges())
>>> print(gt.edge_hist(g, eprop, linspace(0, 1, 11)))
[array([ 501., 441., 478., 480., 506., 494., 507., 535., 499., 559.]), array([ 0. , 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1. ])]
[array([501., 441., 478., 480., 506., 494., 507., 535., 499., 559.]), array([0. , 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1. ])]
"""
......@@ -231,7 +232,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.96, 0.067988234276233406)
(4.96, 0.0679882342762334)
"""
if isinstance(deg, PropertyMap) and "string" in deg.value_type():
......@@ -293,7 +294,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.49888156584192045, 0.0040967399234187541)
(0.49888156584192045, 0.004096739923418754)
"""
if "string" in eprop.value_type():
......@@ -426,10 +427,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., 880., 2269., 3974., 2358., 119.]), array([0, 1, 2, 3, 4, 5, 6, 7], dtype=uint64)]
[array([ 0., 300., 880., 2269., 3974., 2358., 119.]), array([0, 1, 2, 3, 4, 5, 6, 7], dtype=uint64)]
>>> hist = gt.distance_histogram(g, samples=10)
>>> print(hist)
[array([ 0., 30., 87., 223., 394., 239., 17.]), array([0, 1, 2, 3, 4, 5, 6, 7], dtype=uint64)]
[array([ 0., 30., 87., 223., 394., 239., 17.]), array([0, 1, 2, 3, 4, 5, 6, 7], dtype=uint64)]
"""
if samples is not None:
......
......@@ -860,10 +860,11 @@ 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 74 0 0 0 97 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 97 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 64 67 0 0 67 0 0 74 0 0 0 0 23 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7 0 0]
[ 0 0 0 0 0 0 0 74 0 0 0 97 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 97 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 64 67 0 0 67 0 0 74 0 0 0 0
23 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 7 0 0]
References
----------
......@@ -910,8 +911,8 @@ def topological_sort(g):
>>> g.set_edge_filter(tree)
>>> sort = gt.topological_sort(g)
>>> print(sort)
[28 26 29 27 23 22 18 17 16 20 21 15 12 11 10 25 14 9 8 7 5 3 2 24 4
6 1 0 19 13]
[28 26 29 27 23 22 18 17 16 20 21 15 12 11 10 25 14 9 8 7 5 3 2 24
4 6 1 0 19 13]
References
----------
......@@ -1019,13 +1020,14 @@ 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)
[ 9 9 9 9 10 1 9 11 12 9 9 9 9 9 9 13 9 9 9 0 9 9 16 9 9
3 9 9 4 17 9 9 18 9 9 19 20 9 9 9 14 5 9 9 6 9 9 9 21 9
9 9 9 9 9 9 9 9 9 9 9 9 9 2 9 8 9 22 15 9 9 9 9 9 23
25 9 9 26 27 28 29 30 9 9 9 9 9 9 31 9 9 9 9 9 32 9 9 7 24]
[ 9 9 9 9 10 1 9 11 12 9 9 9 9 9 9 13 9 9 9 0 9 9 16 9
9 3 9 9 4 17 9 9 18 9 9 19 20 9 9 9 14 5 9 9 6 9 9 9
21 9 9 9 9 9 9 9 9 9 9 9 9 9 9 2 9 8 9 22 15 9 9 9
9 9 23 25 9 9 26 27 28 29 30 9 9 9 9 9 9 31 9 9 9 9 9 32
9 9 7 24]
>>> print(hist)
[ 1 1 1 1 1 1 1 1 1 68 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 68 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 True True True True True True True True False True False
False False False False False False False False False False False False
......@@ -1937,7 +1939,7 @@ def all_shortest_paths(g, source, target, weights=None, negative_weights=False,
True``, the Bellman-Ford algorithm is used [bellman-ford]_, which accepts
negative weights, as long as there are no negative loops.
If both ``dist_map`` and ``pred_map` are provided, the search is not
If both ``dist_map`` and ``pred_map`` are provided, the search is not
actually performed.
Examples
......@@ -2693,11 +2695,11 @@ def tsp_tour(g, src, weight=None):
>>> g = gt.lattice([10, 10])
>>> tour = gt.tsp_tour(g, g.vertex(0))
>>> print(tour)
[ 0 1 2 11 12 21 22 31 32 41 42 51 52 61 62 71 72 81 82 83 73 63 53 43 33
23 13 3 4 5 6 7 8 9 19 29 39 49 59 69 79 89 14 24 34 44 54 64 74 84
91 92 93 94 95 85 75 65 55 45 35 25 15 16 17 18 27 28 37 38 47 48 57 58 67
68 77 78 87 88 97 98 99 26 36 46 56 66 76 86 96 10 20 30 40 50 60 70 80 90
0]
[ 0 1 2 11 12 21 22 31 32 41 42 51 52 61 62 71 72 81 82 83 73 63 53 43
33 23 13 3 4 5 6 7 8 9 19 29 39 49 59 69 79 89 14 24 34 44 54 64
74 84 91 92 93 94 95 85 75 65 55 45 35 25 15 16 17 18 27 28 37 38 47 48
57 58 67 68 77 78 87 88 97 98 99 26 36 46 56 66 76 86 96 10 20 30 40 50
60 70 80 90 0]
References
----------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment