Commit 4d0809f2 authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

Use range iterators in spectral functions

parent cfb7809f
...@@ -35,19 +35,18 @@ struct get_adjacency ...@@ -35,19 +35,18 @@ struct get_adjacency
multi_array_ref<int,1>& j) const multi_array_ref<int,1>& j) const
{ {
int pos = 0; int pos = 0;
typename graph_traits<Graph>::edge_iterator e, e_end; for (const auto& e : edges_range(g))
for(tie(e, e_end) = edges(g); e != e_end; ++e)
{ {
data[pos] = get(weight, *e); data[pos] = get(weight, e);
i[pos] = get(index, target(*e, g)); i[pos] = get(index, target(e, g));
j[pos] = get(index, source(*e, g)); j[pos] = get(index, source(e, g));
++pos; ++pos;
if (!is_directed::apply<Graph>::type::value) if (!is_directed::apply<Graph>::type::value)
{ {
data[pos] = get(weight, *e); data[pos] = get(weight, e);
i[pos] = get(index, source(*e, g)); i[pos] = get(index, source(e, g));
j[pos] = get(index, target(*e, g)); j[pos] = get(index, target(e, g));
++pos; ++pos;
} }
} }
......
...@@ -35,29 +35,24 @@ struct get_incidence ...@@ -35,29 +35,24 @@ struct get_incidence
multi_array_ref<int32_t,1>& j) const multi_array_ref<int32_t,1>& j) const
{ {
int pos = 0; int pos = 0;
typename graph_traits<Graph>::vertex_iterator v, v_end; for (auto v : vertices_range(g))
for(tie(v, v_end) = vertices(g); v != v_end; ++v)
{ {
for (const auto& e : out_edges_range(v, g))
typename graph_traits<Graph>::out_edge_iterator e, e_end;
for(tie(e, e_end) = out_edges(*v, g); e != e_end; ++e)
{ {
if (is_directed::apply<Graph>::type::value) if (is_directed::apply<Graph>::type::value)
data[pos] = -1; data[pos] = -1;
else else
data[pos] = 1; data[pos] = 1;
i[pos] = get(vindex, *v); i[pos] = get(vindex, v);
j[pos] = get(eindex, *e); j[pos] = get(eindex, e);
++pos; ++pos;
} }
typename in_edge_iteratorS<Graph>::type ie, ie_end; for (const auto& e : in_edges_range(v, g))
for(tie(ie, ie_end) = in_edge_iteratorS<Graph>::get_edges(*v, g);
ie != ie_end; ++ie)
{ {
data[pos] = 1; data[pos] = 1;
i[pos] = get(vindex, *v); i[pos] = get(vindex, v);
j[pos] = get(eindex, *ie); j[pos] = get(eindex, e);
++pos; ++pos;
} }
} }
......
...@@ -78,43 +78,41 @@ struct get_laplacian ...@@ -78,43 +78,41 @@ struct get_laplacian
multi_array_ref<int32_t,1>& j) const multi_array_ref<int32_t,1>& j) const
{ {
int pos = 0; int pos = 0;
typename graph_traits<Graph>::edge_iterator e, e_end; for (const auto& e : edges_range(g))
for(tie(e, e_end) = edges(g); e != e_end; ++e)
{ {
if (source(*e, g) == target(*e, g)) if (source(e, g) == target(e, g))
continue; continue;
data[pos] = -get(weight, *e); data[pos] = -get(weight, e);
i[pos] = get(index, target(*e, g)); i[pos] = get(index, target(e, g));
j[pos] = get(index, source(*e, g)); j[pos] = get(index, source(e, g));
++pos; ++pos;
if (!is_directed::apply<Graph>::type::value) if (!is_directed::apply<Graph>::type::value)
{ {
data[pos] = -get(weight, *e); data[pos] = -get(weight, e);
i[pos] = get(index, source(*e, g)); i[pos] = get(index, source(e, g));
j[pos] = get(index, target(*e, g)); j[pos] = get(index, target(e, g));
++pos; ++pos;
} }
} }
typename graph_traits<Graph>::vertex_iterator v, v_end; for (auto v : vertices_range(g))
for(tie(v, v_end) = vertices(g); v != v_end; ++v)
{ {
double k = 0; double k = 0;
switch (deg) switch (deg)
{ {
case OUT_DEG: case OUT_DEG:
k = sum_degree(g, *v, weight, out_edge_iteratorS<Graph>()); k = sum_degree(g, v, weight, out_edge_iteratorS<Graph>());
break; break;
case IN_DEG: case IN_DEG:
k = sum_degree(g, *v, weight, in_edge_iteratorS<Graph>()); k = sum_degree(g, v, weight, in_edge_iteratorS<Graph>());
break; break;
case TOTAL_DEG: case TOTAL_DEG:
k = sum_degree(g, *v, weight, all_edges_iteratorS<Graph>()); k = sum_degree(g, v, weight, all_edges_iteratorS<Graph>());
} }
data[pos] = k; data[pos] = k;
i[pos] = j[pos] = get(index, *v); i[pos] = j[pos] = get(index, v);
++pos; ++pos;
} }
...@@ -132,52 +130,50 @@ struct get_norm_laplacian ...@@ -132,52 +130,50 @@ struct get_norm_laplacian
multi_array_ref<int32_t,1>& j) const multi_array_ref<int32_t,1>& j) const
{ {
int pos = 0; int pos = 0;
typename graph_traits<Graph>::vertex_iterator v, v_end; for (auto v : vertices_range(g))
for(tie(v, v_end) = vertices(g); v != v_end; ++v)
{ {
double ks = 0; double ks = 0;
switch (deg) switch (deg)
{ {
case OUT_DEG: case OUT_DEG:
ks = sum_degree(g, *v, weight, out_edge_iteratorS<Graph>()); ks = sum_degree(g, v, weight, out_edge_iteratorS<Graph>());
break; break;
case IN_DEG: case IN_DEG:
ks = sum_degree(g, *v, weight, in_edge_iteratorS<Graph>()); ks = sum_degree(g, v, weight, in_edge_iteratorS<Graph>());
break; break;
case TOTAL_DEG: case TOTAL_DEG:
ks = sum_degree(g, *v, weight, all_edges_iteratorS<Graph>()); ks = sum_degree(g, v, weight, all_edges_iteratorS<Graph>());
} }
typename graph_traits<Graph>::out_edge_iterator e, e_end; for(const auto& e : out_edges_range(v, g))
for(tie(e, e_end) = out_edges(*v, g); e != e_end; ++e)
{ {
if (source(*e, g) == target(*e, g)) if (source(e, g) == target(e, g))
continue; continue;
double kt = 0; double kt = 0;
switch (deg) switch (deg)
{ {
case OUT_DEG: case OUT_DEG:
kt = sum_degree(g, target(*e, g), weight, out_edge_iteratorS<Graph>()); kt = sum_degree(g, target(e, g), weight, out_edge_iteratorS<Graph>());
break; break;
case IN_DEG: case IN_DEG:
kt = sum_degree(g, target(*e, g), weight, in_edge_iteratorS<Graph>()); kt = sum_degree(g, target(e, g), weight, in_edge_iteratorS<Graph>());
break; break;
case TOTAL_DEG: case TOTAL_DEG:
kt = sum_degree(g, target(*e, g), weight, all_edges_iteratorS<Graph>()); kt = sum_degree(g, target(e, g), weight, all_edges_iteratorS<Graph>());
} }
if (ks * kt > 0) if (ks * kt > 0)
data[pos] = -get(weight, *e) / sqrt(ks * kt); data[pos] = -get(weight, e) / sqrt(ks * kt);
i[pos] = get(index, target(*e, g)); i[pos] = get(index, target(e, g));
j[pos] = get(index, source(*e, g)); j[pos] = get(index, source(e, g));
++pos; ++pos;
} }
if (ks > 0) if (ks > 0)
data[pos] = 1; data[pos] = 1;
i[pos] = j[pos] = get(index, *v); i[pos] = j[pos] = get(index, v);
++pos; ++pos;
} }
......
...@@ -59,7 +59,7 @@ struct get_transition ...@@ -59,7 +59,7 @@ struct get_transition
for (auto v: vertices_range(g)) for (auto v: vertices_range(g))
{ {
double k = sum_degree(g, v, weight, out_edge_iteratorS<Graph>()); double k = sum_degree(g, v, weight, out_edge_iteratorS<Graph>());
for (auto e: out_edges_range(v, g)) for (const auto& e: out_edges_range(v, g))
{ {
data[pos] = weight[e] / k; data[pos] = weight[e] / k;
i[pos] = get(index, source(e, g)); i[pos] = get(index, source(e, g));
......
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