Skip to content

Commit ea3e805

Browse files
committed
Remove all parametric test machinery, which is super fragile.
Also, turn empty module exceptions into a function call so we can gradually refactor that out and allow for empty modules.
1 parent 31cf4f5 commit ea3e805

File tree

6 files changed

+95
-386
lines changed

6 files changed

+95
-386
lines changed

brainx/modularity.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@
2929
# Our own modules
3030
import util
3131

32+
#-----------------------------------------------------------------------------
33+
# Functions
34+
#-----------------------------------------------------------------------------
35+
def empty_module(msg='Empty module'):
36+
"""Raise an exception if an empty module is found"""
37+
38+
raise ValueError(msg)
39+
40+
3241
#-----------------------------------------------------------------------------
3342
# Class declarations
3443
#-----------------------------------------------------------------------------
@@ -348,9 +357,9 @@ def apply_module_split(self, m, n1, n2, split_modules, e_new, a_new):
348357

349358
# For now, rather than renumbering, just check if this ever happens
350359
if len(self.index[m1])<1:
351-
raise ValueError('Empty module after module split, old mod')
360+
empty_module('Empty module after module split, old mod')
352361
if len(self.index[m2])<1:
353-
raise ValueError('Empty module after module split, new mod')
362+
empty_module('Empty module after module split, new mod')
354363

355364
def node_update(self, n, m1, m2):
356365
"""Moves a single node within or between modules
@@ -452,7 +461,7 @@ def apply_node_update(self, n, m1, m2, node_moved_mods, e_new, a_new):
452461

453462
# This checks whether there is an empty module. If so, renames the keys.
454463
if len(self.index[m1])<1:
455-
raise ValueError('Empty module after node move')
464+
empty_module('Empty module after node move')
456465
#self.index.pop(m1)
457466
#rename_keys(self.index,m1)
458467
#if m1 < m2:
@@ -1005,9 +1014,9 @@ def mutual_information(d1, d2):
10051014
# the entire partitions, we look for this problem at this stage, and bail
10061015
# if there was an empty module.
10071016
## if (nsum_row==0).any():
1008-
## raise ValueError("Empty module in second partition.")
1017+
## empty_module("Empty module in second partition.")
10091018
## if (nsum_col==0).any():
1010-
## raise ValueError("Empty module in first partition.")
1019+
## empty_module("Empty module in first partition.")
10111020

10121021
# nn is the total number of nodes
10131022
nn = nsum_row.sum()
@@ -1136,7 +1145,7 @@ def simulated_annealing(g, p0=None, temperature = 50, temp_scaling = 0.995, tmin
11361145
graph_partition.modularity(), 11)
11371146
for mod in graph_partition.index:
11381147
if len(graph_partition.index[mod]) < 1:
1139-
raise ValueError('Empty module after module %s,SA' % (movetype))
1148+
empty_module('Empty module after module %s,SA' % (movetype))
11401149

11411150

11421151
#maybe store the best one here too?
@@ -1206,7 +1215,7 @@ def simulated_annealing(g, p0=None, temperature = 50, temp_scaling = 0.995, tmin
12061215

12071216
for mod in graph_partition.index:
12081217
if len(graph_partition.index[mod]) < 1:
1209-
raise ValueError('Empty module after ndoe move,SA')
1218+
empty_module('Empty module after ndoe move,SA')
12101219

12111220

12121221
#else:
@@ -1264,7 +1273,7 @@ def simulated_annealing(g, p0=None, temperature = 50, temp_scaling = 0.995, tmin
12641273

12651274
for mod in graph_part_final.index:
12661275
if len(graph_part_final.index[mod]) < 1:
1267-
raise ValueError('LAST CHECK: Empty module after module %s,SA' % (movetype))
1276+
empty_module('LAST CHECK: Empty module after module %s,SA' % (movetype))
12681277

12691278
if extra_info:
12701279
extra_dict = dict(energy = energy_array, temp = temp_array)

brainx/recarrutil.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ def op(a1, a2, out=None):
126126
# For methods in the array interface that take an axis argument, the pattern is
127127
# always the same: extrude, operate, intrude. So we just auto-generate these
128128
# functions here.
129-
binops = [('add',np.add), ('subtract',np.subtract), ('multiply',np.multiply), ('divide',np.divide) ]
129+
binops = [('add', np.add), ('subtract', np.subtract),
130+
('multiply', np.multiply), ('divide', np.divide) ]
130131
#binops = [('add',np.add), np.subtract, np.multiply, np.divide ]
131132
for name, func in binops:
132133
exec "%s = binop_factory(func)" % name
@@ -171,18 +172,19 @@ def test_reductions():
171172
ymeth = getattr(y, fname)
172173
for axis in [None,0,1,-1,-2]:
173174
zred = reduction(z,axis)
174-
yield(nt.assert_equal, zred.x, xmeth(axis))
175-
yield(nt.assert_equal, zred.y, ymeth(axis))
175+
nt.assert_equal(zred.x, xmeth(axis))
176+
nt.assert_equal(zred.y, ymeth(axis))
176177

177178

178179
def test_binops():
179180
x, y, z, w = mk_xyzw()
181+
binop_names = [n for (n, op) in binops]
180182
for fname in binop_names:
181183
op = eval(fname)
182184
npop = getattr(np, fname)
183185
opres = op(z,w)
184-
yield(nt.assert_equal, opres.x, npop(z.x, w.x) )
185-
yield(nt.assert_equal, opres.y, npop(z.y, w.y) )
186+
nt.assert_equal(opres.x, npop(z.x, w.x))
187+
nt.assert_equal(opres.y, npop(z.y, w.y))
186188

187189
# Test support utilities
188190

brainx/tests/decotest.py

Lines changed: 0 additions & 281 deletions
This file was deleted.

0 commit comments

Comments
 (0)