Reusing results of previous function calls

3 visualizaciones (últimos 30 días)
Anton Treialt
Anton Treialt el 10 de Sept. de 2018
Respondida: Jonathan A el 9 de Oct. de 2019
I have a function that is called repeatedly and many function calls have exactly the same inputs. I would like to store the inputs and corresponding results of each call to reuse them, so that if the function is called again with previously used inputs, it would just return the previously computed value, rather than computing it again. In Python you have decorator (@functools.lru_cache) to do this.
What is the best way to implement this functionality in MATLAB?
  1 comentario
madhan ravi
madhan ravi el 10 de Sept. de 2018
Can you upload your code? And function file/s

Iniciar sesión para comentar.

Respuesta aceptada

Stephen23
Stephen23 el 10 de Sept. de 2018
Editada: Stephen23 el 10 de Sept. de 2018

Más respuestas (1)

Jonathan A
Jonathan A el 9 de Oct. de 2019
I also looked in this direction but was looking also with the additional feature of persistency across Matlab sessions and a kind of compilation step that builds a dependency graph between functions, such that it is possilbe to executes only parts of the functions to get intermediate results rapidly. This is pretty useful to me when I have complex workflows to manage. Basically, I implemented a class that encapsulates cachedcall and that allows to build a DAG functions. Hope this helps.

Categorías

Más información sobre Performance and Memory en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by