pbrod / numdifftools

Solve automatic numerical differentiation problems in one or more variables.
BSD 3-Clause "New" or "Revised" License
254 stars 44 forks source link

Working with numdifftools.Jacobian to find a Jacobian of a vector function #27

Closed Omer80 closed 7 years ago

Omer80 commented 7 years ago

Hello, I've opened a question in stackoverflow regarding a MemoryError that I get when I try to use numdifftools.Jacobian - link.

In [27]: m.initial_state.shape
Out[27]: (2048,)

In [28]: m.rhs_pde(m.initial_state).shape
Out[28]: (2048,)

In [29]: jac = nd.Jacobian(m.rhs_pde)(m.initial_state)
Traceback (most recent call last):

  File "<ipython-input-29-6bc47cd5a4d5>", line 1, in <module>
    jac = nd.Jacobian(m.rhs_pde)(m.initial_state)

  File "/home/anaconda2/lib/python2.7/site-packages/numdifftools/core.py", line 666, in __call__
    return super(Jacobian, self).__call__(np.atleast_1d(x), *args, **kwds)

  File "/home/anaconda2/lib/python2.7/site-packages/numdifftools/core.py", line 297, in __call__
    results = self._derivative(xi, args, kwds)

  File "/home/anaconda2/lib/python2.7/site-packages/numdifftools/core.py", line 656, in _derivative_nonzero_order
    results = [diff(f, fxi, xi, h, *args, **kwds) for h in steps]

  File "/home/anaconda2/lib/python2.7/site-packages/numdifftools/core.py", line 613, in _central
    increments = self._increments(n, h)

  File "/home/anaconda2/lib/python2.7/site-packages/numdifftools/core.py", line 609, in _increments
    return np.dot(self._identity(n), h)

  File "/home/anaconda2/lib/python2.7/site-packages/numdifftools/core.py", line 604, in _identity
    m = np.zeros((n, n, n))

MemoryError
pbrod commented 7 years ago

This is fixed in commit cb83ad23fbf3d02cd1130fc61568af6d1b397b78 with better memory handling.