Skip to content

Commit 11584d4

Browse files
committed
Specialize lmul!/rmul! for adjoint/transpose
1 parent 3537c3a commit 11584d4

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/adjtrans.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,9 @@ function _dot_nonrecursive(u, v)
513513
end
514514
end
515515

516+
rmul!(X::AdjOrTrans, s::Number) = (rmul!(parent(X), s); X)
517+
lmul!(s::Number, X::AdjOrTrans) = (lmul!(s, parent(X)); X)
518+
516519
# Adjoint/Transpose-vector * vector
517520
*(u::AdjointAbsVec{<:Number}, v::AbstractVector{<:Number}) = dot(u.parent, v)
518521
*(u::TransposeAbsVec{T}, v::AbstractVector{T}) where {T<:Real} = dot(u.parent, v)

test/adjtrans.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,4 +798,14 @@ end
798798
end
799799
end
800800

801+
@testset "lmul!/rmul! by numbers" begin
802+
for A in (rand(4, 4), rand(ComplexF64,4,4),
803+
fill([1 2; 3 4], 4, 4))
804+
B = copy(A)
805+
@test lmul!(2, B) == 2 * A
806+
B .= A
807+
@test rmul!(B, 2) == A * 2
808+
end
809+
end
810+
801811
end # module TestAdjointTranspose

0 commit comments

Comments
 (0)