Skip to content

Commit 29a195c

Browse files
jishnubdkarrasch
authored andcommitted
Specialize triu! and tril! for adj/trans (#1385)
We may forward the operation to the parent, which would usually ensure that the loops are cache-friendly.
1 parent f26ced1 commit 29a195c

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/adjtrans.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,3 +556,7 @@ _vecadjoint(A::Base.ReshapedArray{<:Any,1,<:AdjointAbsVec}) = adjoint(parent(A))
556556

557557
diagview(A::Transpose, k::Integer = 0) = _vectranspose(diagview(parent(A), -k))
558558
diagview(A::Adjoint, k::Integer = 0) = _vecadjoint(diagview(parent(A), -k))
559+
560+
# triu and tril
561+
triu!(A::AdjOrTransAbsMat, k::Integer = 0) = wrapperop(A)(tril!(parent(A), -k))
562+
tril!(A::AdjOrTransAbsMat, k::Integer = 0) = wrapperop(A)(triu!(parent(A), -k))

test/adjtrans.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,4 +760,15 @@ end
760760
end
761761
end
762762

763+
@testset "triu!/tril!" begin
764+
@testset for sz in ((4,4), (3,4), (4,3))
765+
A = rand(sz...)
766+
B = similar(A)
767+
@testset for f in (adjoint, transpose), k in -3:3
768+
@test triu!(f(copy!(B, A)), k) == triu(f(A), k)
769+
@test tril!(f(copy!(B, A)), k) == tril!(f(A), k)
770+
end
771+
end
772+
end
773+
763774
end # module TestAdjointTranspose

0 commit comments

Comments
 (0)