Commit d6716457 authored by Tiago Peixoto's avatar Tiago Peixoto

Add "g" parameter to Nested/Overlap/CovariateBlockState.copy()

parent 60a97dff
......@@ -243,14 +243,14 @@ class BlockState(object):
def copy(self, b=None, B=None, deg_corr=None, clabel=None, overlap=False):
def copy(self, g=None, b=None, B=None, deg_corr=None, clabel=None, overlap=False):
r"""Copies the block state. The parameters override the state properties, and
have the same meaning as in the constructor. If ``overlap=True`` an
instance of :class:`~graph_tool.community.OverlapBlockState` is
returned."""
if not overlap:
state = BlockState(self.g,
state = BlockState(self.g if g is None else g,
eweight=self.eweight,
vweight=self.vweight,
b=self.b.copy() if b is None else b,
......@@ -260,7 +260,7 @@ class BlockState(object):
max_BE=self.max_BE,
ignore_degrees=self.ignore_degrees)
else:
state = OverlapBlockState(self.g,
state = OverlapBlockState(self.g if g is None else g,
b=b if b is not None else self.b,
B=(self.B if b is None else None) if B is None else B,
clabel=self.clabel if clabel is None else clabel,
......
......@@ -468,11 +468,11 @@ class CovariateBlockState(BlockState):
self.__init__(**state)
return state
def copy(self, b=None, B=None, deg_corr=None, clabel=None, overlap=None,
layers=None, ec=None):
def copy(self, g=None, b=None, B=None, deg_corr=None, clabel=None,
overlap=None, layers=None, ec=None):
r"""Copies the block state. The parameters override the state properties, and
have the same meaning as in the constructor."""
state = CovariateBlockState(self.g,
state = CovariateBlockState(self.g if g is None else g,
ec=self.ec if ec is None else ec,
eweight=self.eweight,
vweight=self.vweight,
......
......@@ -158,11 +158,13 @@ class NestedBlockState(object):
" degree corrected," if self.deg_corr else "",
str(self.g), len(self.levels), str([(s.N, s.B) for s in self.levels]), id(self))
def copy(self, ec=None, layers=None, deg_corr=None, overlap=None, clabel=None):
def copy(self, g=None, bs=None, ec=None, layers=None, deg_corr=None,
overlap=None, clabel=None):
r"""Copies the block state. The parameters override the state properties, and
have the same meaning as in the constructor.."""
bs = [s.b.a for s in self.levels]
if bs is None:
bs = [s.b.a for s in self.levels]
if overlap is None:
overlap = self.overlap
elif self.overlap and not overlap:
......@@ -174,8 +176,8 @@ class NestedBlockState(object):
deg_corr = self.deg_corr
if layers is None:
layers = self.layers
return NestedBlockState(self.g, self.eweight, self.vweight,
self.ec if ec is None else ec, bs,
return NestedBlockState(self.g if g is None else g, self.eweight,
self.vweight, self.ec if ec is None else ec, bs,
layers=layers, deg_corr=deg_corr,
overlap=overlap, clabel=clabel,
max_BE=self.levels[0].max_BE)
......
......@@ -254,13 +254,13 @@ class OverlapBlockState(BlockState):
self.partition_stats = libcommunity.overlap_partition_stats()
def copy(self, b=None, B=None, deg_corr=None, clabel=None, overlap=True):
def copy(self, g=None, b=None, B=None, deg_corr=None, clabel=None, overlap=True):
r"""Copies the block state. The parameters override the state properties, and
have the same meaning as in the constructor. If ``overlap=False`` an
instance of :class:`~graph_tool.community.BlockState` is returned."""
if overlap:
state = OverlapBlockState(self.g,
state = OverlapBlockState(self.g if g is None else g,
eweight=self.eweight,
vweight=self.vweight,
b=self.b if b is None else b,
......@@ -273,7 +273,7 @@ class OverlapBlockState(BlockState):
eindex=self.eindex,
max_BE=self.max_BE)
else:
state = BlockState(self.base_g,
state = BlockState(self.base_g if g is None else g,
b=b if b is not None else self.get_nonoverlap_blocks(),
B=B,
clabel=clabel if clabel is not None else 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