Commit 9b659850 authored by Tiago Peixoto's avatar Tiago Peixoto

(*)_blockmodel.py: Improve memory usage by clearing cache more frequently

parent f44436b4
......@@ -198,6 +198,9 @@ class BlockState(object):
if self.ignore_degrees is None:
self.ignore_degrees = g.new_vertex_property("bool", False)
self.clear_cache()
def clear_cache(self):
# used by mcmc_sweep()
self.egroups = None
self.nsampler = None
......@@ -205,6 +208,7 @@ class BlockState(object):
self.overlap_stats = libcommunity.overlap_stats()
self.partition_stats = libcommunity.partition_stats()
self.edges_dl = False
self.emat = None
def __repr__(self):
return "<BlockState object with %d blocks,%s for graph %s, at 0x%x>" % \
......@@ -351,13 +355,6 @@ class BlockState(object):
_prop("e", self.g, self.eweight),
True, empty)
def __cleanup_bg(self):
emask = self.bg.new_edge_property("bool")
emask.a = self.mrs.a[:len(emask.a)] > 0
self.bg.set_edge_filter(emask)
self.bg.purge_edges()
self.emat = None
def get_blocks(self):
r"""Returns the property map which contains the block labels for each vertex."""
return self.b
......@@ -1529,6 +1526,8 @@ def unilevel_minimize(state, nsweeps=10, adaptive_sweeps=True, epsilon=0,
bi = state.b
state.clear_cache()
return t_dS, t_nmoves
......
......@@ -194,6 +194,13 @@ class CovariateBlockState(BlockState):
assert state.mrs.fa.sum() == state.eweight.fa.sum(), ("inconsistent mrs!", l)
self.clear_cache()
if _bm_test():
assert self.mrs.fa.sum() == self.eweight.fa.sum(), "inconsistent mrs!"
def clear_cache(self):
self.__bg = None
self.__mrs = None
self.__bec = None
......@@ -202,16 +209,15 @@ class CovariateBlockState(BlockState):
#self.wr = self.__dummy_bg.own_property(total_state.wr)
self.wr = total_state.wr
for s in self.states:
s.clear_cache()
self.total_state.clear_cache()
self.sweep_vertices = total_state.sweep_vertices
self.emat = None
self.overlap_stats = self.total_state.overlap_stats
self.__layer_entropy = None
if _bm_test():
assert self.mrs.fa.sum() == self.eweight.fa.sum(), "inconsistent mrs!"
def __get_base_u(self, u):
node_index = u.vp["vmap"].copy("int64_t")
pmap(node_index, self.total_state.node_index)
......
......@@ -214,23 +214,20 @@ class OverlapBlockState(BlockState):
else:
self.clabel = self.g.new_vertex_property("int")
self.emat = None
if max_BE is None:
max_BE = 1000
self.max_BE = max_BE
self.clear_cache()
def clear_cache(self):
# used by mcmc_sweep()
self.egroups = None
self.nsampler = None
self.sweep_vertices = None
self.partition_stats = libcommunity.overlap_partition_stats()
self.edges_dl = False
def __del__(self):
try:
BlockState.__del__(self)
except (TypeError, AttributeError):
pass
self.emat = None
def __repr__(self):
return "<OverlapBlockState object with %d blocks,%s for graph %s, at 0x%x>" % \
......
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