Wasn’t sure if this belongs in first-steps or performance - happy to move it…
What is best practice implementation of the following in Julia.
The objective is to minimize run time. There is no requirement that this be thread safe, but if it can be that would be a benefit.
You have a (large) array/vector, X.
The make|break requirement is that X^q (in julian: X.^q
) is not allowed to be recalculated, 1 \le q \le p.
A function f(p) calculates: X^1,X^2, X^3...X^p
A user script is: f(4) then later f(7), etc.
When the user resets X the calculated values X^q, q=1..p are also reset.
What is Julia best practice implementation to avoid recalculating X^q, q=1...4, when the user script comes to run f(7)
In an OO language, where f(p)
is a method of an instance of a class, you’d possibly do something like store X and the calculated values, X^q, in Class attributes. Managing when those class values should be wiped is delegated to class level methods, e.g. on some file read event when X is created.
I’m trying to work out best practice way of mapping this to Julia.
Appreciate any hints or tips.