almacenamiento de la función calculada en el disco para un acceso rápido en Python

There are two parts to my question. One: I have to do a double integration on a grid

answer = integrate (  f(x,y) times besselfunction(x,y))

Now, I have read that the besselfunction can be precomputed and saved to disk for fast access. How do I do this? Right now, I am evaluating the besselfunction from scipy.special as it is required.

Second question: I have numerically integrated a differential equation and I use the splined solution to solve other differential equations. However the splined solution is slow. Is there a way to make this faster?

preguntado el 28 de agosto de 11 a las 03:08

1 Respuestas

You seem to be looking for an on-disk memoization solution.
You could probably make a memoization decorator that uses berkeleydb to store the results of all function calls computed so far onto disk (if you can carry the resulting berkeleydb file around to every machine you run your program on and don't mind it becoming really huge, you would need to compute the function for a given set of args only once ... I don't know if this is such a good idea in context of what you are doing here though)
Googling for "memoize decorator disk" seems to bring up some interesting solutions to your problem.
This one in particular looks kinda promising -

Respondido 28 ago 11, 07:08

I should have mentioned that I know very little about python. I looked at incpy. If I install incpy does it mean that any new python programme will automatically run in incpy (I wouldn't want that) and I read it can't be used with numpy arrays. I imagined that what I am after is something that people would regularly want to do - alifranco

i don't have incpy myself, but reading that page, I see incpy comes with its own executable (Incpy/python.exe) and so will run only when you call that executable.. it does not seem like it will overwrite the default python executable on your machine, so I think you are safe on that front - Aditya Mukherji

that page seems to say it will work with numpy, sorry to hear you found some problem - Aditya Mukherji

Your use case if somewhat different from most other ones I have seen. You can google for 'memoize decorator' to see plenty of solutions that store every result computed so far into a dict, but this will be a bad idea in your case because you will call it with so many different args, the dict will soon run out of memory. A lot of website-makers use memcached which only stores the last K (x, f(x)) combinations, while you want to store everything so far. - Aditya Mukherji

You want persistent memoization.. i have personally never needed such a thing.. since you know very little about python, you can either wait for somebody else to come give a better answer to your question, or ask someone who knows more python to program the decorator I described in my initial answer. Have you done any analysis to see how often are the same (x,y) combinations provided to the function over its runtime? If every (x,y) is provided only once, then memoization won't really save you any time atleast for the program's first run - Aditya Mukherji

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.