Skip to content

Commit afe2f9c

Browse files
committed
Remove branches in copyto_unaliased
1 parent 9b6de95 commit afe2f9c

File tree

1 file changed

+32
-12
lines changed

1 file changed

+32
-12
lines changed

src/triangular.jl

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -617,29 +617,49 @@ end
617617
end
618618
# for strided matrices, we explicitly loop over the arrays to improve cache locality
619619
# This fuses the copytrito! for the two halves
620+
@propagate_inbounds function copyto_unaliased_stored!(dest, U::UpperTriangular, col)
621+
for row in firstindex(dest,1):col
622+
dest[row,col] = U.data[row,col]
623+
end
624+
dest
625+
end
626+
@propagate_inbounds function copyto_unaliased_stored!(dest, U::UnitUpperTriangular, col)
627+
for row in firstindex(dest,1):col-1
628+
dest[row,col] = U.data[row,col]
629+
end
630+
dest[col, col] = U[BandIndex(0,col)]
631+
dest
632+
end
633+
@propagate_inbounds function copyto_unaliased_stored!(dest, U::LowerTriangular, col)
634+
for row in col:lastindex(dest,1)
635+
dest[row,col] = L.data[row,col]
636+
end
637+
dest
638+
end
639+
@propagate_inbounds function copyto_unaliased_stored!(dest, U::UnitLowerTriangular, col)
640+
dest[col, col] = U[BandIndex(0,col)]
641+
for row in col+1:lastindex(dest,1)
642+
dest[row,col] = L.data[row,col]
643+
end
644+
dest
645+
end
620646
@inline function copyto_unaliased!(dest::StridedMatrix, U::UpperOrUnitUpperTriangular{<:Any, <:StridedMatrix})
621647
@boundscheck checkbounds(dest, axes(U)...)
622-
isunit = U isa UnitUpperTriangular
623648
for col in axes(dest,2)
624-
for row in firstindex(dest,1):col-isunit
625-
@inbounds dest[row,col] = U.data[row,col]
626-
end
627-
for row in col+!isunit:lastindex(dest,1)
628-
@inbounds dest[row,col] = U[row,col]
649+
@inbounds copyto_unaliased_stored!(dest, U, col)
650+
for row in col+1:lastindex(dest,1)
651+
@inbounds dest[row,col] = diagzero(U,row,col)
629652
end
630653
end
631654
return dest
632655
end
633656
@inline function copyto_unaliased!(dest::StridedMatrix, L::LowerOrUnitLowerTriangular{<:Any, <:StridedMatrix})
634657
@boundscheck checkbounds(dest, axes(L)...)
635-
isunit = L isa UnitLowerTriangular
636658
for col in axes(dest,2)
637-
for row in firstindex(dest,1):col-!isunit
638-
@inbounds dest[row,col] = L[row,col]
639-
end
640-
for row in col+isunit:lastindex(dest,1)
641-
@inbounds dest[row,col] = L.data[row,col]
659+
for row in firstindex(dest,1):col-1
660+
@inbounds dest[row,col] = diagzero(L,row,col)
642661
end
662+
@inbounds copyto_unaliased_stored!(dest, L, col)
643663
end
644664
return dest
645665
end

0 commit comments

Comments
 (0)