Commit cdcadbfb authored by Tiago Peixoto's avatar Tiago Peixoto

Graph: fix vorder parameter when not contiguous

parent 66086427
......@@ -189,12 +189,24 @@ struct do_graph_copy
vector<pair<std::reference_wrapper<boost::any>,std::reference_wrapper<boost::any>>>& vprops,
vector<pair<std::reference_wrapper<boost::any>,std::reference_wrapper<boost::any>>>& eprops) const
{
vector<size_t> vs;
for (auto v : vertices_range(src))
vs.push_back(v);
std::sort(vs.begin(), vs.end(),
[&](auto u, auto v)
{
return get(vertex_order, u) < get(vertex_order, v);
});
vector<size_t> pos(num_vertices(src));
for (size_t i = 0; i < vs.size(); ++i)
pos[vs[i]] = i;
vector<size_t> index_map(num_vertices(src));
for (auto v : vertices_range(src))
{
if (src_vertex_index[v] >= index_map.size())
index_map.resize(src_vertex_index[v] + 1);
auto new_v = get(vertex_order, v);
auto new_v = pos[v];
while (size_t(new_v) >= num_vertices(tgt))
add_vertex(tgt);
index_map[src_vertex_index[v]] = tgt_vertex_index[new_v];
......
......@@ -1662,8 +1662,10 @@ class Graph(object):
# The vertex ordering
if vorder is None:
vorder = gv.new_vertex_property("int")
vorder.fa = numpy.arange(gv.num_vertices())
vorder = gv.new_vertex_property("int",
vals=numpy.arange(gv.num_vertices()))
else:
vorder = vorder.copy("int")
# The actual copying of the graph and property maps
self.__graph = libcore.GraphInterface(gv.__graph, False,
......
......@@ -97,8 +97,12 @@ def get_block_graph(g, B, b, vcount=None, ecount=None, rec=None, drec=None):
cg.ep["drec%d" % i] = ae[0]
del ae[0]
rs = numpy.setdiff1d(numpy.arange(B, dtype="int"), br.fa,
assume_unique=True)
if len(rs) > 0:
cg.add_vertex(len(rs))
br.fa[-len(rs):] = rs
cg = Graph(cg, vorder=br)
cg.add_vertex(B - cg.num_vertices())
cg.gp.rec = cg.new_gp("object", [])
if rec is not 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