0

I performed the following calculation:

from sympy import mpmath as mp
mp.besseljzero(1000, 100)

which understandably took some time > 10s if not more (didn't time it).

Subsequent calls were significantly faster which made me think it caches the results. I was wondering what other functions/caclulations sympy cahces?

Does this mean if I want to calculate mp.besseljzero(n, m) for n < N and m < M it's best to calculate mp.besseljzero(N-1, M-1) and then access the other results?

Thanks in advance.

I should add that I found this info on sympy FAQ. It seems that some sort of caching is supported. If there is more documentation you can point me to that would be helpful!

https://github.com/sympy/sympy/wiki/Faq

evan54
  • 3,585
  • 5
  • 34
  • 61

1 Answers1

2

mpmath has its own memoization, separate from the rest of Sympy, which resets when the precision changes.

SymPy has a cache, which caches the most expensive operations. In SymPy versions before 0.7.6, the cache is unbounded, which can lead to memory issues. In 0.7.6 upward, the cache is an LRU cache, which uses less memory, but is a little slower. To get the speed back, you can install the package fastcache, which is an LRU cache written in C, which improves the performance by quite a bit.

The FAQ page you reference shows how to disable the cache, or clear it manually.

asmeurer
  • 86,894
  • 26
  • 169
  • 240
  • does this mean it caches all results? I'm a bit confused as to what actually get's cached. Also, with regards to sympy caching vs mpmath caching in my example which of the two is happening? – evan54 Nov 19 '14 at 19:54
  • No, only certain functions are cached. I'm not sure about mpmath, but for SymPy only core functions that are run many times are cached. – asmeurer Nov 19 '14 at 20:44
  • 1
    For your example, you are using only mpmath, so the SymPy cache does not come into play. – asmeurer Nov 19 '14 at 20:44