Skip to content

Commit d6b869c

Browse files
Optimize swaprow! and swapcol!
1 parent b764487 commit d6b869c

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/matrixlu.jl

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,19 @@ function rrLU{T}(A::AbstractMatrix{T}; leftorthogonal::Bool=true) where {T}
9696
end
9797

9898
function swaprow!(lu::rrLU{T}, A::AbstractMatrix{T}, a, b) where {T}
99-
lu.rowpermutation[[a, b]] = lu.rowpermutation[[b, a]]
100-
A[[a, b], :] = A[[b, a], :]
99+
lurp = lu.rowpermutation
100+
lurp[a], lurp[b] = lurp[b], lurp[a]
101+
@inbounds for j in axes(A, 2)
102+
A[a, j], A[b, j] = A[b, j], A[a, j]
103+
end
101104
end
102105

103106
function swapcol!(lu::rrLU{T}, A::AbstractMatrix{T}, a, b) where {T}
104-
lu.colpermutation[[a, b]] = lu.colpermutation[[b, a]]
105-
A[:, [a, b]] = A[:, [b, a]]
107+
lucp = lu.colpermutation
108+
lucp[a], lucp[b] = lucp[b], lucp[a]
109+
@inbounds for i in axes(A, 1)
110+
A[i, a], A[i, b] = A[i, b], A[i, a]
111+
end
106112
end
107113

108114
function addpivot!(lu::rrLU{T}, A::AbstractMatrix{T}, newpivot) where {T}

0 commit comments

Comments
 (0)