Commit b08d153c authored by Tiago Peixoto's avatar Tiago Peixoto

Fix simple test failures for 32bit architectures

parent 3cb868e0
......@@ -650,12 +650,21 @@ format tends to be about an order of magnitude faster than ``graphml``,
and largely I/O-bound, instead of the latter, which is often
CPU-bound. Here is an example for a somewhat larger graph:
.. testsetup::
.. testsetup:: gt_format
import graph_tool.all as gt
gt.seed_rng(42)
.. doctest::
.. doctest:: gt_format
:hide:
import timeit
g = gt.random_graph(100000, lambda: (10, 10))
g.save("/tmp/random_graph.xml")
g.save("/tmp/random_graph.xml.xz")
g.save("/tmp/random_graph.gt")
g.save("/tmp/random_graph.gt.xz")
.. doctest:: gt_format
>>> import timeit
>>> g = gt.random_graph(100000, lambda: (10, 10))
......
......@@ -1165,6 +1165,8 @@ def edge_endpoint_property(g, prop, endpoint, eprop=None):
val_t = prop.value_type()
if val_t == "unsigned long":
val_t = "int64_t"
elif val_t == "unsigned int":
val_t = "int32_t"
if eprop is None:
eprop = g.new_edge_property(val_t)
if eprop.value_type() != val_t:
......@@ -1214,6 +1216,8 @@ def incident_edges_op(g, direction, op, eprop, vprop=None):
val_t = eprop.value_type()
if val_t == "unsigned long":
val_t = "int64_t"
if val_t == "unsigned int":
val_t = "int32_t"
if vprop is None:
vprop = g.new_vertex_property(val_t)
orig_vprop = vprop
......
......@@ -513,7 +513,7 @@ def central_point_dominance(g, betweenness):
>>> g = gt.GraphView(g, vfilt=gt.label_largest_component(g))
>>> vp, ep = gt.betweenness(g)
>>> print(gt.central_point_dominance(g, vp))
0.11610685614353008
0.116106856143530...
References
----------
......
......@@ -182,7 +182,7 @@ def global_clustering(g):
>>> g = gt.random_graph(1000, lambda: (5,5))
>>> print(gt.global_clustering(g))
(0.006177777777777778, 0.0003700318726720911)
(0.006177777777777778, 0.0003700318726720...)
References
----------
......@@ -261,11 +261,11 @@ def extended_clustering(g, props=None, max_depth=3, undirected=False):
>>> for i in range(0, 5):
... print(gt.vertex_average(g, clusts[i]))
...
(0.00421, 0.00041685103920811916)
(0.027226666666666666, 0.0010073522830778825)
(0.11549166666666667, 0.0020813990854177339)
(0.4128066666666666, 0.0029479221231987242)
(0.4205716666666667, 0.0031564657411414965)
(0.00421, 0.00041685103920811...)
(0.027226666666666666, 0.00100735228307788...)
(0.11549166666666667, 0.00208139908541773...)
(0.4128066666666666, 0.00294792212319872...)
(0.4205716666666667, 0.00315646574114149...)
References
----------
......
......@@ -367,7 +367,7 @@ def modularity(g, prop, weight=None):
>>> g = gt.load_graph("community.xml")
>>> b = gt.community_structure(g, 10000, 10)
>>> gt.modularity(g, b)
0.5353141885624041
0.535314188562404...
References
----------
......
......@@ -2522,7 +2522,7 @@ def collect_edge_marginals(state, p=None):
... ds, nmoves = gt.mcmc_sweep(state)
... pe = gt.collect_edge_marginals(state, pe)
>>> gt.bethe_entropy(state, pe)[0]
17.609773262509986
17.60977326250998...
"""
if p is None:
......
......@@ -108,7 +108,7 @@ def assortativity(g, deg):
... accept = False
... while not accept:
... k = np.random.randint(1,max+1)
... accept = random() < 1.0/k
... accept = np.random.random() < 1.0/k
... return k
...
>>> g = gt.random_graph(1000, lambda: sample_k(40), model="probabilistic",
......@@ -184,7 +184,7 @@ def scalar_assortativity(g, deg):
... accept = False
... while not accept:
... k = np.random.randint(1,max+1)
... accept = random() < 1.0/k
... accept = np.random.random() < 1.0/k
... return k
...
>>> g = gt.random_graph(1000, lambda: sample_k(40), model="probabilistic",
......@@ -277,7 +277,7 @@ def corr_hist(g, deg_source, deg_target, bins=[[0, 1], [0, 1]], weight=None,
... accept = False
... while not accept:
... k = np.random.randint(1,max+1)
... accept = random() < 1.0/k
... accept = np.random.random() < 1.0/k
... return k
...
>>> g = gt.random_graph(10000, lambda: sample_k(40), model="probabilistic",
......@@ -372,9 +372,9 @@ def combined_corr_hist(g, deg1, deg2, bins=[[0, 1], [0, 1]], float_count=True):
>>> def sample_k(max):
... accept = False
... while not accept:
... i = randint(1, max + 1)
... j = randint(1, max + 1)
... accept = random() < (sin(i / pi) * sin(j / pi) + 1) / 2
... i = np.random.randint(1, max + 1)
... j = np.random.randint(1, max + 1)
... accept = np.random.random() < (sin(i / pi) * sin(j / pi) + 1) / 2
... return i,j
...
>>> g = gt.random_graph(10000, lambda: sample_k(40))
......@@ -472,8 +472,8 @@ def avg_neighbour_corr(g, deg_source, deg_target, bins=[0, 1], weight=None):
>>> def sample_k(max):
... accept = False
... while not accept:
... k = randint(1,max+1)
... accept = random() < 1.0 / k
... k = np.random.randint(1,max+1)
... accept = np.random.random() < 1.0 / k
... return k
...
>>> g = gt.random_graph(10000, lambda: sample_k(40), model="probabilistic",
......@@ -559,9 +559,9 @@ def avg_combined_corr(g, deg1, deg2, bins=[0, 1]):
>>> def sample_k(max):
... accept = False
... while not accept:
... i = randint(1,max+1)
... j = randint(1,max+1)
... accept = random() < (sin(i/pi)*sin(j/pi)+1)/2
... i = np.random.randint(1,max+1)
... j = np.random.randint(1,max+1)
... accept = np.random.random() < (sin(i/pi)*sin(j/pi)+1)/2
... return i,j
...
>>> g = gt.random_graph(10000, lambda: sample_k(40))
......
......@@ -397,7 +397,8 @@ def _convert(attr, val, cmap, pmap_default=False, g=None, k=None):
if val.value_type() in ["vector<double>", "vector<long double>"]:
new_val = val
elif val.value_type() in ["int32_t", "int64_t", "double",
"long double", "unsigned long", "bool"]:
"long double", "unsigned long",
"unsigned int", "bool"]:
g = val.get_graph()
try:
vrange = [val.fa.min(), val.fa.max()]
......
......@@ -165,9 +165,9 @@ def random_graph(N, deg_sampler, directed=True,
.. testcode::
:hide:
from numpy.random import randint, random, seed, poisson
import numpy.random
from pylab import *
seed(43)
np.random.seed(43)
gt.seed_rng(42)
This is a degree sampler which uses rejection sampling to sample from the
......@@ -176,8 +176,8 @@ def random_graph(N, deg_sampler, directed=True,
>>> def sample_k(max):
... accept = False
... while not accept:
... k = randint(1,max+1)
... accept = random() < 1.0/k
... k = np.random.randint(1,max+1)
... accept = np.random.random() < 1.0/k
... return k
...
......@@ -206,9 +206,9 @@ def random_graph(N, deg_sampler, directed=True,
>>> def deg_sample():
... if random() > 0.5:
... return poisson(4), poisson(4)
... return np.random.poisson(4), np.random.poisson(4)
... else:
... return poisson(20), poisson(20)
... return np.random.poisson(20), np.random.poisson(20)
...
The following generates a random directed graph with this distribution, and
......@@ -606,7 +606,7 @@ def random_rewire(g, model="uncorrelated", n_iter=1, edge_sweep=True,
seed(43)
gt.seed_rng(42)
>>> g, pos = gt.triangulation(random((1000,2)))
>>> g, pos = gt.triangulation(np.random.random((1000,2)))
>>> pos = gt.arf_layout(g)
>>> gt.graph_draw(g, pos=pos, output="rewire_orig.pdf", output_size=(300, 300))
<...>
......@@ -616,8 +616,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")
607
>>> ret = gt.random_rewire(g, "correlated")
>>> pos = gt.arf_layout(g)
>>> gt.graph_draw(g, pos=pos, output="rewire_corr.pdf", output_size=(300, 300))
<...>
......@@ -627,8 +626,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)
211
>>> ret = gt.random_rewire(g)
>>> pos = gt.arf_layout(g)
>>> gt.graph_draw(g, pos=pos, output="rewire_uncorr.pdf", output_size=(300, 300))
<...>
......@@ -638,8 +636,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")
21
>>> ret = gt.random_rewire(g, "erdos")
>>> pos = gt.arf_layout(g)
>>> gt.graph_draw(g, pos=pos, output="rewire_erdos.pdf", output_size=(300, 300))
<...>
......@@ -669,18 +666,15 @@ def random_rewire(g, model="uncorrelated", n_iter=1, edge_sweep=True,
>>> corr = gt.avg_neighbour_corr(g, "out", "out")
>>> errorbar(corr[2][:-1], corr[0], yerr=corr[1], fmt="o-", label="Original")
<...>
>>> gt.random_rewire(g, "correlated")
252
>>> ret = gt.random_rewire(g, "correlated")
>>> corr = gt.avg_neighbour_corr(g, "out", "out")
>>> errorbar(corr[2][:-1], corr[0], yerr=corr[1], fmt="*", label="Correlated")
<...>
>>> gt.random_rewire(g)
92
>>> ret = gt.random_rewire(g)
>>> 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")
9
>>> ret = gt.random_rewire(g, "erdos")
>>> 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")
<...>
......@@ -724,8 +718,7 @@ def random_rewire(g, model="uncorrelated", n_iter=1, edge_sweep=True,
>>> errorbar(corr[2][:-1], corr[0], yerr=corr[1], fmt="o-",
... label=r"$\left<\text{i}\right>$ vs o")
<...>
>>> gt.random_rewire(g, "correlated")
4199
>>> ret = gt.random_rewire(g, "correlated")
>>> 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.")
......@@ -734,8 +727,7 @@ def random_rewire(g, model="uncorrelated", n_iter=1, edge_sweep=True,
>>> errorbar(corr[2][:-1], corr[0], yerr=corr[1], fmt="o-",
... label=r"$\left<\text{i}\right>$ vs o, corr.")
<...>
>>> gt.random_rewire(g, "uncorrelated")
193
>>> ret = gt.random_rewire(g, "uncorrelated")
>>> 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.")
......
......@@ -426,10 +426,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., 865., 2214., 3857., 2480., 184.]), array([0, 1, 2, 3, 4, 5, 6, 7], dtype=uint64)]
[array([ 0., 300., 865., 2214., 3857., 2480., 184.]), array([0, 1, 2, 3, 4, 5, 6, 7], dtype=uint...)]
>>> hist = gt.distance_histogram(g, samples=10)
>>> print(hist)
[array([ 0., 30., 88., 226., 391., 240., 15.]), array([0, 1, 2, 3, 4, 5, 6, 7], dtype=uint64)]
[array([ 0., 30., 88., 226., 391., 240., 15.]), array([0, 1, 2, 3, 4, 5, 6, 7], dtype=uint...)]
"""
if samples != None:
......
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