Skip to content

Commit 4d8e1e3

Browse files
Use view macro to avoid memory allocation
1 parent d6b869c commit 4d8e1e3

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/matrixlu.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ function _optimizerrlu!(
159159
addpivot!(lu, A, newpivot)
160160
end
161161

162-
lu.L = tril(A[:, 1:lu.npivot])
163-
lu.U = triu(A[1:lu.npivot, :])
162+
lu.L = tril(@view A[:, 1:lu.npivot])
163+
lu.U = triu(@view A[1:lu.npivot, :])
164164
if any(isnan.(lu.L))
165165
error("lu.L contains NaNs")
166166
end
@@ -277,16 +277,16 @@ function arrlu(
277277
I2 = setdiff(1:matrixsize[1], I0)
278278
lu.rowpermutation = vcat(I0, I2)
279279
L2 = _batchf(I2, J0)
280-
cols2Lmatrix!(L2, lu.U[1:lu.npivot, 1:lu.npivot], leftorthogonal)
281-
lu.L = vcat(lu.L[1:lu.npivot, 1:lu.npivot], L2)
280+
cols2Lmatrix!(L2, (@view lu.U[1:lu.npivot, 1:lu.npivot]), leftorthogonal)
281+
lu.L = vcat((@view lu.L[1:lu.npivot, 1:lu.npivot]), L2)
282282
end
283283

284284
if size(lu.U, 2) < matrixsize[2]
285285
J2 = setdiff(1:matrixsize[2], J0)
286286
lu.colpermutation = vcat(J0, J2)
287287
U2 = _batchf(I0, J2)
288-
rows2Umatrix!(U2, lu.L[1:lu.npivot, 1:lu.npivot], leftorthogonal)
289-
lu.U = hcat(lu.U[1:lu.npivot, 1:lu.npivot], U2)
288+
rows2Umatrix!(U2, (@view lu.L[1:lu.npivot, 1:lu.npivot]), leftorthogonal)
289+
lu.U = hcat((@view lu.U[1:lu.npivot, 1:lu.npivot]), U2)
290290
end
291291

292292
return lu

0 commit comments

Comments
 (0)