Skip to content

Commit 045ee5c

Browse files
authored
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 3537c3a commit 045ee5c

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
@@ -572,3 +572,7 @@ _vecadjoint(A::Base.ReshapedArray{<:Any,1,<:AdjointAbsVec}) = adjoint(parent(A))
572572

573573
diagview(A::Transpose, k::Integer = 0) = _vectranspose(diagview(parent(A), -k))
574574
diagview(A::Adjoint, k::Integer = 0) = _vecadjoint(diagview(parent(A), -k))
575+
576+
# triu and tril
577+
triu!(A::AdjOrTransAbsMat, k::Integer = 0) = wrapperop(A)(tril!(parent(A), -k))
578+
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
@@ -798,4 +798,15 @@ end
798798
end
799799
end
800800

801+
@testset "triu!/tril!" begin
802+
@testset for sz in ((4,4), (3,4), (4,3))
803+
A = rand(sz...)
804+
B = similar(A)
805+
@testset for f in (adjoint, transpose), k in -3:3
806+
@test triu!(f(copy!(B, A)), k) == triu(f(A), k)
807+
@test tril!(f(copy!(B, A)), k) == tril!(f(A), k)
808+
end
809+
end
810+
end
811+
801812
end # module TestAdjointTranspose

0 commit comments

Comments
 (0)