e2nIEE / pandapower
1
# Copyright (c) 1996-2015 PSERC. All rights reserved.
2
# Use of this source code is governed by a BSD-style
3
# license that can be found in the LICENSE file.
4

5 1
"""PYPOWER utilities.
6
"""
7

8

9 1
def sub2ind(shape, I, J, row_major=False):
10
    """Returns the linear indices of subscripts
11
    """
12 1
    if row_major:
13 0
        ind = (I % shape[0]) * shape[1] + (J % shape[1])
14
    else:
15 1
        ind = (J % shape[1]) * shape[0] + (I % shape[0])
16

17 1
    return ind.astype(int)
18

19

20 1
def feval(func, *args, **kw_args):
21
    """Evaluates the function C{func} using positional arguments C{args}
22
    and keyword arguments C{kw_args}.
23
    """
24 0
    return eval(func)(*args, **kw_args)
25

26

27 1
def have_fcn(name):
28 1
    try:
29 1
        __import__(name)
30 0
        return True
31 1
    except ImportError:
32 1
        return False

Read our documentation on viewing source code .

Loading