pbrod/numdifftools

Backward differentiation method fails with additional parameters

yusekiya opened this issue · 1 comments

numdifftools.Derivative(method='backward') has a bug.
The following code

import numdifftools as nd
def func(x, a):
    return a * x * x
df = nd.Derivative(func, method='backward')
df(0.0, 1.0)

outputs an error:

Traceback (most recent call last):
  File "qr_22224RvW.py", line 5, in <module>
    df(0.0, 1.0)
  File "c:\msys64\home\.anaconda\Lib\site-packages\numdifftools\core.py", line 995, in __call__
    results = self._derivative(xi, args, kwds)
  File "c:\msys64\home\.anaconda\Lib\site-packages\numdifftools\core.py", line 1190, in _derivative
    results = [diff(f, fxi, xi, h, *args, **kwds) for h in steps]
  File "c:\msys64\home\.anaconda\Lib\site-packages\numdifftools\core.py", line 1190, in <listcomp>
    results = [diff(f, fxi, xi, h, *args, **kwds) for h in steps]
  File "c:\msys64\home\.anaconda\Lib\site-packages\numdifftools\core.py", line 1213, in _backward
    return (f_x0i - fun(x0i - h))
TypeError: func() missing 1 required positional argument: 'a'

It seems that the arguments *args and **kwds are missing at the return of _backward in the Derivative class.

pbrod commented

Thanks. This is now resolved in version 0.9.11.