QuantEcon.py
QuantEcon.py copied to clipboard
ENH: make calls to `compute_fixed_point` allocate less memory
The idea is quite simple: whenever we call compute_fixed_point(T, ...)
we should update the definition of T
so that any temporary arrays can be optionally supplied by the caller. See the new compute_lt_price
function in the LucasTree
class of quantecon/models/lucastree.py for an example (there we avoid allocating Tf
on each iteration).
@spencerlyon2 This is done, right? Can we close?
@jstac, I don't think so. This is the line we would need to change. In that line we would want new_v
to be passed directly into T
when it is called and T
would update it inplace. Note that this will require a change to the T
functions also.
What about an 'inplace' option such that compute_fixed_point(T, v, inplace=True)
would assume T
to be a function T(v0, v1, ...)
with the output being stored in v1
?
The alternative would be to assume a call like T(v0, out=v1)
. In that case it is possible to automatically check whether T has an output argument.
Both options would preserve backward compatibility.