Skip to content

Commit a462e5a

Browse files
committed
Restrict to real/complex numbers
1 parent a359c7c commit a462e5a

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/adjtrans.jl

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

516-
rmul!(X::AdjOrTrans, s::Number) = (lmul!(wrapperop(X)(s), parent(X)); X)
517-
lmul!(s::Number, X::AdjOrTrans) = (rmul!(parent(X), wrapperop(X)(s)); X)
516+
# we use (n A^T) = (A n)^T, which holds if the product of n and the elements of A is commutative
517+
rmul!(X::AdjOrTrans{<:Union{Real,Complex}}, s::Union{Real,Complex}) = (lmul!(wrapperop(X)(s), parent(X)); X)
518+
lmul!(s::Union{Real,Complex}, X::AdjOrTrans{<:Union{Real,Complex}}) = (rmul!(parent(X), wrapperop(X)(s)); X)
518519

519520
# Adjoint/Transpose-vector * vector
520521
*(u::AdjointAbsVec{<:Number}, v::AbstractVector{<:Number}) = dot(u.parent, v)

test/adjtrans.jl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ isdefined(Main, :LinearAlgebraTestHelpers) || Base.include(Main, TESTHELPERS)
1212

1313
using Main.LinearAlgebraTestHelpers.OffsetArrays
1414
using Main.LinearAlgebraTestHelpers.ImmutableArrays
15+
using Main.LinearAlgebraTestHelpers.Quaternions
1516

1617
@testset "Adjoint and Transpose inner constructor basics" begin
1718
intvec, intmat = [1, 2], [1 2; 3 4]
@@ -811,7 +812,8 @@ end
811812

812813
@testset "lmul!/rmul! by numbers" begin
813814
@testset "$(eltype(A))" for A in (rand(4, 4), rand(ComplexF64,4,4),
814-
fill([1 2; 3 4], 4, 4))
815+
fill([1 2; 3 4], 4, 4),
816+
fill(Quaternion(1,2,3,4), 4, 4))
815817
B = copy(A)
816818
@testset for op in (transpose, adjoint)
817819
A .= B
@@ -824,6 +826,13 @@ end
824826
A .= B
825827
@test rmul!(op(A), -2im) == op(B) * -2im
826828
end
829+
if eltype(A) <: Quaternion
830+
A .= B
831+
q = Quaternion(0,1,4,7)
832+
@test lmul!(q, op(A)) == q * op(B)
833+
A .= B
834+
@test rmul!(op(A), q) == op(B) * q
835+
end
827836
end
828837
end
829838
end

0 commit comments

Comments
 (0)