I stumbled across the function *circshift* today in the Julia 
documentation. I have a use case for a slight extension of that function. I 
wonder whether it might be useful for others.

Assume you are generating vectors iteratively and you store those vectors 
as the columns of a matrix. Let's say you only need the last N generated 
vectors and thus the matrix has N columns.
If the number of iterations exceed N then you need to shift the columns to 
the left and overwrite the right-most column. A very crude implementation 
would be:

function circupdate(A, x)
    A = circshift(A, [0; -1])
    for i = 1:size(A, 1)
        A[i, end] = x[i]
    end
    return A
end

where x is the newest vector you are storing in the matrix A.

Considering memory usage I was thinking on a *circshift!* function which 
overwrites the input and adding an optional argument to facilitate what I 
tried to accomplish with the crude code above.

Reply via email to