Package pypower :: Module util
[hide private]
[frames] | no frames]

Source Code for Module pypower.util

 1  # Copyright (C) 2011 Richard Lincoln 
 2  # 
 3  # PYPOWER is free software: you can redistribute it and/or modify 
 4  # it under the terms of the GNU General Public License as published 
 5  # by the Free Software Foundation, either version 3 of the License, 
 6  # or (at your option) any later version. 
 7  # 
 8  # PYPOWER is distributed in the hope that it will be useful, 
 9  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
10  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
11  # GNU General Public License for more details. 
12  # 
13  # You should have received a copy of the GNU General Public License 
14  # along with PYPOWER. If not, see <http://www.gnu.org/licenses/>. 
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