Skip to content

Commit fa9dc53

Browse files
author
CindeeM
committed
RF: replace old code that has been included in numpy with corresponding numpy calls
1 parent 25e5345 commit fa9dc53

File tree

2 files changed

+9
-17
lines changed

2 files changed

+9
-17
lines changed

brainx/tests/test_util.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,8 @@ def test_make_cost_thresh_lookup():
5454
def test_cost_size():
5555
n_nodes = 5
5656
## NOTE DeprecationWarnings are ignored by default in 2.7
57-
npt.assert_warns(UserWarning, util.cost_size, n_nodes)
58-
def test_test_warning():
59-
npt.assert_warns(UserWarning, util.test_warning)
57+
#npt.assert_warns(UserWarning, util.cost_size, n_nodes)
58+
6059

6160

6261
class TestCost2Thresh(unittest.TestCase):

brainx/util.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ def format_matrix(data,s,b,lk,co,idc = [],costlist=[],nouptri = False):
6868
return cmat
6969

7070
def format_matrix2(data,s,sc,c,lk,co,idc = [],costlist=[],nouptri = False):
71-
""" Function which formats matrix for a particular subject and particular block (thresholds, upper-tris it) so that we can make a graph object out of it
71+
""" Function which formats matrix for a particular subject and
72+
particular block (thresholds, upper-tris it) so that we can
73+
make a graph object out of it
7274
7375
Parameters
7476
----------
@@ -169,9 +171,6 @@ def cost_size(nnodes):
169171
edges_short = tot_edges / 2
170172
return costs, tot_edges, edges_short
171173

172-
def test_warning():
173-
"""simple code to raise a warning"""
174-
warnings.warn('This is your warning')
175174

176175
def make_cost_array(n_nodes, cost=0.5):
177176
"""Make cost array of length cost * (the number of possible edges).
@@ -1003,7 +1002,7 @@ def tril_indices(n,k=0):
10031002
- triu_indices : similar function, for upper-triangular.
10041003
- mask_indices : generic function accepting an arbitrary mask function.
10051004
"""
1006-
return mask_indices(n,np.tril,k)
1005+
return np.tril_indices(n,k) #mask_indices(n,np.tril,k)
10071006

10081007

10091008
def tril_indices_from(arr,k=0):
@@ -1020,10 +1019,7 @@ def tril_indices_from(arr,k=0):
10201019
Diagonal offset (see tril() for details).
10211020
10221021
"""
1023-
if not arr.ndim==2 and arr.shape[0] == arr.shape[1]:
1024-
raise ValueError("input array must be 2-d and square")
1025-
return tril_indices(arr.shape[0],k)
1026-
1022+
return np.tril_indices_from(arr, k)
10271023

10281024
def triu_indices(n,k=0):
10291025
"""Return the indices for the upper-triangle of an (n,n) array.
@@ -1078,7 +1074,7 @@ def triu_indices(n,k=0):
10781074
- tril_indices : similar function, for lower-triangular.
10791075
- mask_indices : generic function accepting an arbitrary mask function.
10801076
"""
1081-
return mask_indices(n,np.triu,k)
1077+
return np.triu_indices(n,k) #mask_indices(n,np.triu,k)
10821078

10831079

10841080
def triu_indices_from(arr,k=0):
@@ -1095,10 +1091,7 @@ def triu_indices_from(arr,k=0):
10951091
Diagonal offset (see triu() for details).
10961092
10971093
"""
1098-
if not arr.ndim==2 and arr.shape[0] == arr.shape[1]:
1099-
raise ValueError("input array must be 2-d and square")
1100-
return triu_indices(arr.shape[0],k)
1101-
1094+
return np.tri_indices_from(arr, k)
11021095

11031096
def structured_rand_arr(size, sample_func=np.random.random,
11041097
ltfac=None, utfac=None, fill_diag=None):

0 commit comments

Comments
 (0)