Skip to content

Commit 081429f

Browse files
author
CindeeM
committed
BF: catch issue where nan in adjmatrix can lead to bad lookup table, and test
1 parent e5ea623 commit 081429f

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

brainx/tests/test_util.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ def test_make_cost_thresh_lookup():
5050
# costs in ascending order
5151
## last vector is same as second vector rounded to 2 decimals
5252
npt.assert_almost_equal(lookup.actual_cost, lookup.cost, decimal=2)
53+
# add nan to adj_mat to raise error
54+
adj_mat[2,:] = np.nan
55+
npt.assert_raises(ValueError, util.make_cost_thresh_lookup, adj_mat)
56+
5357

5458
def test_cost_size():
5559
n_nodes = 5

brainx/util.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,11 @@ def make_cost_thresh_lookup(adjacency_matrix):
192192
0.70
193193
194194
"""
195-
195+
## check for nan in matrix, sorting will behave badly if nan found
196+
if np.any(np.isnan(adjacency_matrix)):
197+
raise ValueError('NAN found in adjacency matrix, this will cause'\
198+
'improper behavior in sorting and improper results, '\
199+
'please remove all nan ')
196200
ind = np.triu_indices_from(adjacency_matrix, k = 1)
197201
edges = adjacency_matrix[ind]
198202
nedges = edges.shape[0]

0 commit comments

Comments
 (0)