1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 """PYPOWER utilities.
17 """
18
19
20 -def sub2ind(shape, I, J, row_major=False):
21 """Returns the linear indices of subscripts
22 """
23 if row_major:
24 ind = (I % shape[0]) * shape[1] + (J % shape[1])
25 else:
26 ind = (J % shape[1]) * shape[0] + (I % shape[0])
27
28 return ind.astype(int)
29
30
31 -def feval(func, *args, **kw_args):
32 """Evaluates the function C{func} using positional arguments C{args}
33 and keyword arguments C{kw_args}.
34 """
35 return eval(func)(*args, **kw_args)
36