Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Tiago Peixoto
graph-tool
Commits
0507fe70
Commit
0507fe70
authored
Sep 26, 2015
by
Tiago Peixoto
Browse files
Fix remaining incompatibility issues with Python 2
parent
ce5f96f4
Changes
7
Hide whitespace changes
Inline
Side-by-side
doc/pyenv.py
View file @
0507fe70
from
__future__
import
division
,
absolute_import
,
print_function
import
sys
if
sys
.
version_info
<
(
3
,):
range
=
xrange
else
:
unicode
=
str
from
matplotlib
import
rc
from
matplotlib
import
rcParams
...
...
src/graph_tool/__init__.py
View file @
0507fe70
...
...
@@ -1994,10 +1994,9 @@ class Graph(object):
if
len
(
val
)
>
1000
:
val
=
val
[:
1000
]
+
"..."
tw
=
terminal_size
()[
0
]
val
=
textwrap
.
indent
(
textwrap
.
fill
(
val
,
width
=
max
(
tw
-
len
(
pref
),
1
)),
" "
*
len
(
pref
))
val
=
val
[
len
(
pref
):]
val
=
textwrap
.
fill
(
val
,
width
=
max
(
tw
-
len
(
pref
),
1
))
val
=
val
.
replace
(
"
\n
"
,
"
\n
"
+
" "
*
len
(
pref
))
print
(
"%s%s)"
%
(
pref
,
val
))
for
k
,
v
in
sorted
(
self
.
vertex_properties
.
items
(),
key
=
lambda
k
:
k
[
0
]):
print
(
"%%-%ds (vertex) (type: %%s)"
%
w
%
(
k
,
v
.
value_type
()))
...
...
@@ -2101,7 +2100,7 @@ class Graph(object):
provided, the values will be initialized by ``vals``, which should be
sequence or by ``val`` which should be a single value.
"""
prop
=
PropertyMap
(
new_edge_property
(
_type_alias
(
value_type
),
prop
=
PropertyMap
(
new_edge_property
(
_
c_str
(
_
type_alias
(
value_type
)
)
,
self
.
__graph
.
get_edge_index
(),
libcore
.
any
()),
self
,
"e"
)
...
...
@@ -2118,7 +2117,7 @@ class Graph(object):
def
new_graph_property
(
self
,
value_type
,
val
=
None
):
"""Create a new graph property map of type ``value_type``, and return
it. If ``val`` is not None, the property is initialized to its value."""
prop
=
PropertyMap
(
new_graph_property
(
_type_alias
(
value_type
),
prop
=
PropertyMap
(
new_graph_property
(
_
c_str
(
_
type_alias
(
value_type
)
)
,
self
.
__graph
.
get_graph_index
(),
libcore
.
any
()),
self
,
"g"
)
...
...
@@ -2835,42 +2834,46 @@ This class represents a vertex in a :class:`~graph_tool.Graph` instance.
integers, corresponding to its index (see :attr:`~graph_tool.Graph.vertex_index`).
"""
def
v_eq
(
v1
,
v2
):
def
_
v_eq
(
v1
,
v2
):
try
:
return
int
(
v1
)
==
int
(
v2
)
except
TypeError
:
return
False
def
v_ne
(
v1
,
v2
):
def
_
v_ne
(
v1
,
v2
):
try
:
return
int
(
v1
)
!=
int
(
v2
)
except
TypeError
:
return
True
def
v_lt
(
v1
,
v2
):
def
_
v_lt
(
v1
,
v2
):
try
:
return
int
(
v1
)
<
int
(
v2
)
except
TypeError
:
return
False
def
v_gt
(
v1
,
v2
):
def
_
v_gt
(
v1
,
v2
):
try
:
return
int
(
v1
)
>
int
(
v2
)
except
TypeError
:
return
False
def
v_le
(
v1
,
v2
):
def
_
v_le
(
v1
,
v2
):
try
:
return
int
(
v1
)
<=
int
(
v2
)
except
TypeError
:
return
False
def
v_ge
(
v1
,
v2
):
def
_
v_ge
(
v1
,
v2
):
try
:
return
int
(
v1
)
>=
int
(
v2
)
except
TypeError
:
return
False
if
sys
.
version_info
<
(
3
,):
def
_v_long
(
self
):
return
long
(
int
(
self
))
for
Vertex
in
libcore
.
get_vlist
():
Vertex
.
__doc__
=
_vertex_doc
Vertex
.
out_neighbours
=
_out_neighbours
...
...
@@ -2884,12 +2887,14 @@ for Vertex in libcore.get_vlist():
except
AttributeError
:
pass
Vertex
.
__repr__
=
_vertex_repr
Vertex
.
__eq__
=
v_eq
Vertex
.
__ne__
=
v_ne
Vertex
.
__lt__
=
v_lt
Vertex
.
__gt__
=
v_gt
Vertex
.
__le__
=
v_le
Vertex
.
__ge__
=
v_ge
Vertex
.
__eq__
=
_v_eq
Vertex
.
__ne__
=
_v_ne
Vertex
.
__lt__
=
_v_lt
Vertex
.
__gt__
=
_v_gt
Vertex
.
__le__
=
_v_le
Vertex
.
__ge__
=
_v_ge
if
sys
.
version_info
<
(
3
,):
Vertex
.
__long__
=
_v_long
_edge_doc
=
"""Edge descriptor.
...
...
src/graph_tool/centrality/__init__.py
View file @
0507fe70
...
...
@@ -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.11610685614
3530
...
0.11610685614...
References
----------
...
...
@@ -600,7 +600,7 @@ def eigenvector(g, weight=None, vprop=None, epsilon=1e-6, max_iter=None):
>>> w.a = np.random.random(len(w.a)) * 42
>>> ee, x = gt.eigenvector(g, w)
>>> print(ee)
724.302745922
1508
724.302745922
...
>>> gt.graph_draw(g, pos=g.vp["pos"], vertex_fill_color=x,
... vertex_size=gt.prop_to_size(x, mi=5, ma=15),
... vcmap=matplotlib.cm.gist_heat,
...
...
src/graph_tool/community/blockmodel.py
View file @
0507fe70
...
...
@@ -2143,7 +2143,8 @@ def minimize_blockmodel_dl(g, deg_corr=True, overlap=False, ec=None,
>>> g = gt.collection.data["polbooks"]
>>> state = gt.minimize_blockmodel_dl(g, overlap=True)
>>> bv, *rest, bc = state.get_overlap_blocks()
>>> ret = state.get_overlap_blocks()
>>> bv, bc = ret[0], ret[-1]
>>> eg = gt.get_block_edge_gradient(g, state.get_edge_blocks())
>>> gt.graph_draw(g, g.vp["pos"], vertex_pie_fractions=bc,
... vertex_pie_colors=bv, vertex_shape="pie",
...
...
src/graph_tool/draw/cairo_draw.py
View file @
0507fe70
...
...
@@ -228,7 +228,7 @@ def shape_from_prop(shape, enum):
prop
.
fa
%=
rg
[
1
]
-
rg
[
0
]
+
1
prop
.
fa
+=
rg
[
0
]
return
prop
if
isinstance
(
shape
,
str
):
if
isinstance
(
shape
,
(
str
,
unicode
)
):
return
int
(
getattr
(
enum
,
shape
))
else
:
return
shape
...
...
@@ -292,7 +292,7 @@ def surface_from_prop(surface):
surface
.
value_type
())
return
prop
if
isinstance
(
surface
,
str
):
if
isinstance
(
surface
,
(
str
,
unicode
)
):
return
gen_surface
(
surface
)
elif
isinstance
(
surface
,
cairo
.
Surface
)
or
surface
is
None
:
return
surface
...
...
@@ -393,7 +393,7 @@ def _convert(attr, val, cmap, pmap_default=False, g=None, k=None):
new_val
=
val
elif
isinstance
(
val
,
(
tuple
,
np
.
ndarray
)):
new_val
=
list
(
val
)
elif
isinstance
(
val
,
str
):
elif
isinstance
(
val
,
(
str
,
unicode
)
):
new_val
=
list
(
color_converter
.
to_rgba
(
val
))
elif
isinstance
(
val
,
PropertyMap
):
if
val
.
value_type
()
in
[
"vector<double>"
,
"vector<long double>"
]:
...
...
@@ -693,7 +693,7 @@ def color_contrast(color):
def
auto_colors
(
g
,
bg
,
pos
,
back
):
if
not
isinstance
(
bg
,
PropertyMap
):
if
isinstance
(
bg
,
str
):
if
isinstance
(
bg
,
(
str
,
unicode
)
):
bg
=
color_converter
.
to_rgba
(
bg
)
bg
=
g
.
new_vertex_property
(
"vector<double>"
,
val
=
bg
)
if
not
isinstance
(
pos
,
PropertyMap
):
...
...
src/graph_tool/flow/__init__.py
View file @
0507fe70
...
...
@@ -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.8905957841
1614
44.8905957841
...
>>> 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.8905957841
1614
44.8905957841
...
>>> 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.8905957841
1614
44.8905957841
...
>>> 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")
<...>
...
...
src/graph_tool/topology/__init__.py
View file @
0507fe70
...
...
@@ -1202,10 +1202,10 @@ def shortest_distance(g, source=None, target=None, weights=None, max_dist=None,
4 6 4 4 4 4
6 5 4 4]
>>> dist = gt.shortest_distance(g, source=g.vertex(0), target=g.vertex(2))
>>> print
(dist)
>>> print(dist)
5
>>> dist = gt.shortest_distance(g, source=g.vertex(0), target=[g.vertex(2), g.vertex(6)])
>>> print
(dist)
>>> print(dist)
[5 9]
References
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment