-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
include left matrix multiply and some fixes
- Loading branch information
Showing
2 changed files
with
56 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,34 +17,51 @@ function left_tester(L::LinearMap{T}) where {T} | |
@test transpose(y) * A ≈ transpose(y) * L | ||
|
||
# mul! | ||
α = rand(T); β = rand(T) | ||
b1 = y' * A | ||
b2 = similar(b1) | ||
mul!(b2, y', L) # 3-arg | ||
@test b1 ≈ b2 | ||
mul!(b2, y', L, true, false) # 5-arg | ||
@test b1 ≈ b2 | ||
bt = copy(b1')' | ||
# bm = Matrix(bt) # TODO: this requires a generalization of the output to AbstractVecOrMat | ||
@test mul!(b2, y', L) ≈ mul!(bt, y', L)# ≈ mul!(bm, y', L)# 3-arg | ||
@test mul!(b2, y', L) === b2 | ||
@test b1 ≈ b2 ≈ bt | ||
b3 = copy(b2) | ||
mul!(b3, y', L, α, β) | ||
@test b3 ≈ b2*β + b1*α | ||
|
||
b1 = transpose(y) * A | ||
b2 = similar(b1) | ||
mul!(b2, transpose(y), L) # 3-arg | ||
@test b1 ≈ b2 | ||
mul!(b2, transpose(y), L, true, false) # 5-arg | ||
@test b1 ≈ b2 | ||
bt = transpose(copy(transpose(b1))) | ||
@test mul!(b2, transpose(y), L) ≈ mul!(bt, transpose(y), L) | ||
@test b1 ≈ b2 ≈ bt | ||
b3 = copy(b2) | ||
mul!(b3, transpose(y), L, α, β) | ||
@test b3 ≈ b2*β + b1*α | ||
|
||
Y = rand(T, M, 3) | ||
X = similar(Y, 3, N) | ||
Xt = copy(X')' | ||
@test Y'L isa LinearMap | ||
@test Matrix(Y'L) ≈ Y'A | ||
@test mul!(X, Y', L) ≈ mul!(Xt, Y', L) ≈ Y'A | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
dkarrasch
Author
Member
|
||
@test mul!(Xt, Y', L) === Xt | ||
@test mul!(copy(X), Y', L, α, β) ≈ X*β + Y'A*α | ||
@test mul!(X, Y', L) === X | ||
@test mul!(X, Y', L, α, β) === X | ||
|
||
true | ||
end | ||
|
||
|
||
@testset "left mul vec" begin | ||
@testset "left multiplication" begin | ||
T = ComplexF32 | ||
M,N = 5,5 | ||
N = 5 | ||
L = LinearMap{T}(cumsum, reverse ∘ cumsum ∘ reverse, N) | ||
|
||
@test left_tester(L) # FunctionMap | ||
@test left_tester(L'*L) # CompositeMap | ||
@test left_tester(2L) # ScaledMap | ||
@test left_tester(kron(L,L')) # KroneckerMap | ||
@test left_tester(2L+3L') # LinearCombination | ||
@test left_tester(kron(L, L')) # KroneckerMap | ||
@test left_tester(2L + 3L') # LinearCombination | ||
@test left_tester([L L]) # BlockMap | ||
|
||
W = LinearMap(randn(T,5,4)) | ||
|
This
mul!(X, Y', L)
confuses me because on inputX
is an Array, but the multiplyY'*L
usually becomes aLinearMap
so we can't really store the result "in place" in an Array, right?If I follow what is going on here, we have a perhaps unusual situation where
Y'L
returns aLinearMap
but the correspondingmul!
version returns an Array. Personally I would prefer anArray
in both cases so this feels like a step in a good direction but I wonder if it could catch users by surprise.