Skip to content

Commit 0b085cc

Browse files
author
CindeeM
committed
RF: change logic to prevent empty partition in newman_partition to make more readable based on suggestion by @stefanv
1 parent e42d407 commit 0b085cc

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

brainx/modularity.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1359,7 +1359,9 @@ def _divide_partition(p, max_div=np.inf):
13591359
# if the mask is all True or all False, this will not split the partition
13601360
# and would create an empty partition
13611361
# catch by checking max vector contains pos and neg values
1362-
if np.abs(v_max.sum()) == np.abs(v_max).sum():
1362+
is_positive = np.sign(v_max) >= 0
1363+
is_negative = np.sign(v_max) <= 0
1364+
if np.all(is_positive) or np.all(is_negative):
13631365
return [p]
13641366
s = np.ones_like(v_max)
13651367
s[mask] = -1

0 commit comments

Comments
 (0)