findifftool/core.py
def clgrad(obj, exe, arg, delta=DELTA):
    """
    Returns numerical gradient function of given class method
    with respect to a class attribute
    Input: obj, general object
           exe (str), name of object method
           arg (str), name of object atribute
           delta(float, optional), finite difference step
    Output: gradient function object
    """
    f, x = get_method_and_copy_of_attribute(obj, exe, arg)
    def grad_f(*args, **kwargs):
        grad_val = numpy.zeros(x.shape)
        it = numpy.nditer(x, op_flags=['readwrite'], flags=['multi_index'])
        for xi in it:
            i = it.multi_index
            xi += delta/2
            fp = f(*args, **kwargs)
            xi -= delta
            fm = f(*args, **kwargs)
            xi += delta/2
            grad_val[i] = (fp - fm)/delta
        return grad_val
    return grad_f
def clgrad(obj, exe, arg, delta=DELTA):
    """
    Returns numerical gradient function of given class method
    with respect to a class attribute
    Input: obj, general object
           exe (str), name of object method
           arg (str), name of object atribute
           delta(float, optional), finite difference step
    Output: gradient function object
    """
    f, x = get_method_and_copy_of_attribute(obj, exe, arg)
    def grad_f(*args, **kwargs):
        grad_val = numpy.zeros(x.shape)
        it = numpy.nditer(x, op_flags=['readwrite'], flags=['multi_index'])
        for xi in it:
            i = it.multi_index
            xi += delta/2
            fp = f(*args, **kwargs)
            xi -= delta
            fm = f(*args, **kwargs)
            xi += delta/2
            grad_val[i] = (fp - fm)/delta
        return grad_val
    return grad_f
def clgrad ( obj , exe , arg , delta = DELTA ) : f , x = get_method_and_copy_of_attribute ( obj , exe , arg ) def grad_f ( * args , * * kwargs ) : grad_val = numpy . zeros ( x . shape ) it = numpy . nditer ( x , op_flags = [ 'readwrite' ] , flags = [ 'multi_index' ] ) for xi in it : i = it . multi_index xi += delta / 2 fp = f ( * args , * * kwargs ) xi -= delta fm = f ( * args , * * kwargs ) xi += delta / 2 grad_val [ i ] = ( fp - fm ) / delta return grad_val return grad_f
Returns numerical gradient function of given class method
    with respect to a class attribute
    Input: obj, general object
           exe (str), name of object method
           arg (str), name of object atribute
           delta(float, optional), finite difference step
    Output: gradient function object
Returns numerical gradient function of given class method with respect to a class attribute Input : obj general object exe ( str ) name of object method arg ( str ) name of object atribute delta ( float optional ) finite difference step Output : gradient function object