Commit 3cd1f5d1 authored by pmla's avatar pmla

fixed memory bug

parent 69b63dd2
Pipeline #26820120 failed with stage
in 12 seconds
......@@ -591,7 +591,7 @@ bool GrainSegmentationEngine::modularitySegmentation()
clock_t startTime = clock();
if(!parallelFor(_numSuperclusters, *this, [this, &atomCumulative, &vIndex, &particleToVertexId, &numEdges, &numSuperclusterEdges, &adjlist, &scOffset, &adjweight, numAtoms, totalWeight, &orderedRMSD, &community](size_t scIndex) {
if(!parallelFor(_numSuperclusters, *this, [this, &atomCumulative, &vIndex, &particleToVertexId, &numEdges, &adjlist, &scOffset, &adjweight, numAtoms, totalWeight, &orderedRMSD, &community](size_t scIndex) {
// Nothing to do for supercluster 0.
if(scIndex == 0) return;
......@@ -607,7 +607,6 @@ clock_t startTime = clock();
}
assign_communities_halfedge( numVertices, cumulative_degrees, orderedRMSD.begin() + atomCumulative[scIndex],
numSuperclusterEdges[scIndex],
adjlist.begin() + scOffset[scIndex],
adjweight.begin() + scOffset[scIndex],
totalWeight, community.begin() + atomCumulative[scIndex]);
......
......@@ -35,14 +35,12 @@
#include <map>
#include <vector>
#include <cassert>
#include <algorithm>
class Graph {
public:
size_t num_nodes;
size_t num_edges;
std::vector<size_t> degrees;
std::vector<size_t> node_size;
std::vector<size_t> edges;
......@@ -69,21 +67,17 @@ public:
};
Graph( size_t num_vertices, std::vector<size_t>::iterator adjdegrees, std::vector<double>::iterator _rmsds,
size_t _num_edges, std::vector<size_t>::iterator adjlist, std::vector<double>::iterator adjweight)
std::vector<size_t>::iterator adjlist, std::vector<double>::iterator adjweight)
{
num_nodes = num_vertices;
num_edges = _num_edges;
edge_iterator = adjlist;
weight_iterator = adjweight;
rmsd_iterator = _rmsds;
node_size.assign(num_nodes, 1);
degree_iterator = adjdegrees;
degrees.resize(1);
}
size_t num_neighbors(size_t node) {
assert(node >= 0 && node < num_nodes);
if (node == 0)
return degree_iterator[0];
......@@ -92,7 +86,6 @@ degrees.resize(1);
}
double num_selfloops(size_t node) {
assert(node >= 0 && node < num_nodes);
std::pair<std::vector<size_t>::iterator, std::vector<double>::iterator> p = neighbors(node);
for (size_t i = 0; i < num_neighbors(node); i++)
......@@ -103,7 +96,6 @@ degrees.resize(1);
}
double weighted_degree(size_t node) {
assert(node >= 0 && node < num_nodes);
std::pair<std::vector<size_t>::iterator, std::vector<double>::iterator> p = neighbors(node);
double res = 0.0L;
......@@ -114,7 +106,6 @@ degrees.resize(1);
}
std::pair<std::vector<size_t>::iterator, std::vector<double>::iterator> neighbors(size_t node) {
assert(node >= 0 && node < num_nodes);
if (node == 0)
return make_pair(edge_iterator, weight_iterator);
......@@ -125,8 +116,6 @@ degrees.resize(1);
static void remove(Graph* g, std::vector<size_t>& n2c, std::vector<double>& in, std::vector<double>& tot, size_t node, size_t comm, double dnodecomm) {
assert(node >= 0 && node < size);
in[comm] -= 2 * dnodecomm + g->num_selfloops(node);
tot[comm] -= g->weighted_degree(node);
n2c[node] = -1;
......@@ -134,8 +123,6 @@ static void remove(Graph* g, std::vector<size_t>& n2c, std::vector<double>& in,
static void insert(Graph* g, std::vector<size_t>& n2c, std::vector<double>& in, std::vector<double>& tot, size_t node, size_t comm, double dnodecomm) {
assert(node >= 0 && node < size);
in[comm] += 2 * dnodecomm + g->num_selfloops(node);
tot[comm] += g->weighted_degree(node);
n2c[node] = comm;
......@@ -143,8 +130,6 @@ static void insert(Graph* g, std::vector<size_t>& n2c, std::vector<double>& in,
static double gain(double total_weight, std::vector<double>& tot, size_t node, size_t comm, double dnc, double degc) {
assert(node >= 0 && node < size);
double totc = tot[comm];
return dnc - totc * degc / total_weight;
}
......@@ -175,7 +160,7 @@ static void neigh_comm(Graph* g, size_t node, size_t& neigh_last, std::vector<si
for (size_t i=0;i<deg;i++) {
size_t neigh = *(p.first + i);
size_t neigh_comm = n2c[neigh];
double neigh_w = (g->num_edges == 0) ? 1 : *(p.second + i);
double neigh_w = *(p.second + i);
if (neigh != node) {
if (neigh_weight[neigh_comm] == -1) {
......@@ -317,7 +302,7 @@ static Graph one_level(Graph* g, size_t num_vertices, std::vector< size_t >::ite
for (size_t i = 0; i < deg; i++) {
size_t neigh = *(p.first + i);
size_t neigh_comm = renumber[n2c[neigh]];
double neigh_weight = (g->num_edges == 0) ? 1 : *(p.second + i);
double neigh_weight = *(p.second + i);
auto it = m.find(neigh_comm);
if (it == m.end())
......@@ -332,7 +317,6 @@ static Graph one_level(Graph* g, size_t num_vertices, std::vector< size_t >::ite
for (auto it = m.begin(); it != m.end(); it++) {
g2.edges.push_back(it->first);
g2.weights.push_back(it->second);
g->num_edges++;
}
}
......@@ -343,9 +327,9 @@ static Graph one_level(Graph* g, size_t num_vertices, std::vector< size_t >::ite
}
size_t assign_communities_halfedge( size_t num_vertices, std::vector<size_t>::iterator adjdegrees, std::vector<double>::iterator rmsds,
size_t num_edges, std::vector<size_t>::iterator adjlist, std::vector<double>::iterator adjweight, double total_weight, std::vector< size_t >::iterator n2c)
std::vector<size_t>::iterator adjlist, std::vector<double>::iterator adjweight, double total_weight, std::vector< size_t >::iterator n2c)
{
Graph g(num_vertices, adjdegrees, rmsds, num_edges, adjlist, adjweight);
Graph g(num_vertices, adjdegrees, rmsds, adjlist, adjweight);
for (size_t i=0;i<num_vertices;i++)
n2c[i] = i;
......
......@@ -36,7 +36,7 @@
#include <vector>
size_t assign_communities_halfedge(size_t numVertices, std::vector<size_t>::iterator adjdegrees, std::vector<double>::iterator rmsds,
size_t numEdges, std::vector<size_t>::iterator adjlist, std::vector<double>::iterator adjweight, double total_weight, std::vector< size_t >::iterator n2c);
std::vector<size_t>::iterator adjlist, std::vector<double>::iterator adjweight, double total_weight, std::vector< size_t >::iterator n2c);
#endif // LOUVAIN_H
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