I am implementing Gaussian Elimination using Julia. The important thing is, when doing the elimination the row vectors are kept updating row by row. While writing a for loop to iterate over the row vector and assigning new value to it one by one does not allocate memory, I wonder whether there are any better solutions (but not package functions) that can do the vector assignment (like I need to update the old vector with an older vector and some basic calculation) without memory allocation?
A, B, C is a matrix below, for example I want to do: A[1] = C[2] + B[2]
Any other efficient ways?
First of all, you will get much better results if you do gausian elimination by column since Julia is column major. Secondly you can use broadcasting to do row/column updates without allocations. (you’ll also want to look at @views)
which is equivalent to the broadcast! function. The only problem is that you cannot shift the index (A[1] and B[2],C[2] in your example) but it can easily be solved using views. For example,
vA = @view A[1:end-1]
vB = @view B[2:end]
vC = @view C[2:end]
vA .= vC .+ vB