Skip to content

Commit 3feab93

Browse files
committed
Left vector multiply
1 parent b06ba20 commit 3feab93

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

src/wrappedmap.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import LinearAlgebra: AdjointAbsVec, TransposeAbsVec
2+
13
struct WrappedMap{T, A<:MapOrMatrix} <: LinearMap{T}
24
lmap::A
35
_issymmetric::Bool
@@ -71,3 +73,8 @@ Base.:(-)(A₁::AbstractMatrix, A₂::LinearMap) = -(WrappedMap(A₁), A₂)
7173

7274
Base.:(*)(A₁::LinearMap, A₂::AbstractMatrix) = *(A₁, WrappedMap(A₂))
7375
Base.:(*)(A₁::AbstractMatrix, A₂::LinearMap) = *(WrappedMap(A₁), A₂)
76+
77+
# An AdjointAbsVec isa AbstractMatrix but we handle it like a vector (Issue#99)
78+
# which is an exception to the left multiplication rule that makes a WrappedMap
79+
Base.:(*)(y::AdjointAbsVec, A::LinearMap) = adjoint(*(A', y'))
80+
Base.:(*)(y::TransposeAbsVec, A::LinearMap) = transpose(transpose(A) * transpose(y))

test/wrappedmap.jl

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,33 @@ using Test, LinearMaps, LinearAlgebra
1515
@test @inferred isposdef(MA)
1616
@test @inferred isposdef(MB)
1717
end
18+
19+
# y'*L is an exception to the left multiplication rule that makes a WrappedMap
20+
@testset "left mul vec" begin
21+
T = ComplexF32
22+
A = rand(T, 4, 5)
23+
x = rand(T, 5)
24+
y = rand(T, 4)
25+
L = LinearMap{T}(A)
26+
@test y'A y'L
27+
@test (y' * A) * x y' * (L * x) # associative
28+
@test transpose(y) * A transpose(y) * L
29+
30+
LL = L * [L' L'] # stress test with CompositeMap & BlockMap
31+
AA = A * [A' A']
32+
x = rand(T, 8)
33+
@test y'AA y'LL
34+
@test (y' * AA) * x y' * (LL * x) # associative
35+
@test transpose(y)*AA transpose(y)*LL
36+
37+
# mul! versions
38+
b1 = y'*L
39+
b2 = similar(b1)
40+
mul!(b2, y', A)
41+
@test b1 b2
42+
43+
b1 = transpose(y)*L
44+
b2 = similar(b1)
45+
mul!(b2, transpose(y), A)
46+
@test b1 b2
47+
end

0 commit comments

Comments
 (0)