Commit 531add6b authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

Fix bug in similarity()

parent e8fa7fbd
...@@ -128,7 +128,8 @@ struct get_similarity_fast ...@@ -128,7 +128,8 @@ struct get_similarity_fast
s = 0; s = 0;
int i, N = lmap1.size(); int i, N = lmap1.size();
#pragma omp parallel for default(shared) private(i) schedule(runtime) if (N > 100) #pragma omp parallel for default(shared) private(i) schedule(runtime) \
reduction(+:s) if (N > 100)
for (i = 0; i < N; ++i) for (i = 0; i < N; ++i)
{ {
auto v1 = lmap1[i]; auto v1 = lmap1[i];
......
...@@ -141,20 +141,14 @@ def similarity(g1, g2, label1=None, label2=None, norm=True): ...@@ -141,20 +141,14 @@ def similarity(g1, g2, label1=None, label2=None, norm=True):
label2 = label2.copy(label1.value_type()) label2 = label2.copy(label1.value_type())
except ValueError: except ValueError:
label1 = label1.copy(label2.value_type()) label1 = label1.copy(label2.value_type())
try: if label1.is_writable() or label2.is_writable():
_check_prop_scalar(label1, floating=False)
_check_prop_scalar(label2, floating=False)
if label1.fa is not None and label1.fa.max() >= g1.num_vertices():
raise ValueError()
if label2.fa is not None and label2.fa.max() >= g2.num_vertices():
raise ValueError()
s = libgraph_tool_topology.\
similarity_fast(g1._Graph__graph, g2._Graph__graph,
_prop("v", g1, label1), _prop("v", g2, label2))
except ValueError:
s = libgraph_tool_topology.\ s = libgraph_tool_topology.\
similarity(g1._Graph__graph, g2._Graph__graph, similarity(g1._Graph__graph, g2._Graph__graph,
_prop("v", g1, label1), _prop("v", g2, label2)) _prop("v", g1, label1), _prop("v", g2, label2))
else:
s = libgraph_tool_topology.\
similarity_fast(g1._Graph__graph, g2._Graph__graph,
_prop("v", g1, label1), _prop("v", g2, label2))
if not g1.is_directed() or not g2.is_directed(): if not g1.is_directed() or not g2.is_directed():
s /= 2 s /= 2
if norm: if norm:
......
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