-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
minor fixes in multiplication with Diagonals #31443
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ca1b555
a7b7a6e
5d1bcc8
fc1f32b
2fcfd2e
562412e
e215f89
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -172,7 +172,7 @@ end | |
|
||
function rmul!(A::AbstractMatrix, D::Diagonal) | ||
require_one_based_indexing(A) | ||
A .= A .* transpose(D.diag) | ||
A .= A .* permutedims(D.diag) | ||
return A | ||
end | ||
|
||
|
@@ -260,20 +260,20 @@ lmul!(A::Diagonal, B::Diagonal) = Diagonal(B.diag .= A.diag .* B.diag) | |
|
||
function lmul!(adjA::Adjoint{<:Any,<:Diagonal}, B::AbstractMatrix) | ||
A = adjA.parent | ||
return lmul!(conj(A.diag), B) | ||
return lmul!(adjoint(A), B) | ||
end | ||
function lmul!(transA::Transpose{<:Any,<:Diagonal}, B::AbstractMatrix) | ||
A = transA.parent | ||
return lmul!(A.diag, B) | ||
return lmul!(transpose(A), B) | ||
end | ||
|
||
function rmul!(A::AbstractMatrix, adjB::Adjoint{<:Any,<:Diagonal}) | ||
B = adjB.parent | ||
return rmul!(A, conj(B.diag)) | ||
return rmul!(A, adjoint(B)) | ||
end | ||
function rmul!(A::AbstractMatrix, transB::Transpose{<:Any,<:Diagonal}) | ||
B = transB.parent | ||
return rmul!(A, B.diag) | ||
return rmul!(A, transpose(B)) | ||
end | ||
|
||
# Get ambiguous method if try to unify AbstractVector/AbstractMatrix here using AbstractVecOrMat | ||
|
@@ -552,10 +552,9 @@ end | |
*(x::Adjoint{<:Any,<:AbstractVector}, D::Diagonal) = Adjoint(map((t,s) -> t'*s, D.diag, parent(x))) | ||
*(x::Adjoint{<:Any,<:AbstractVector}, D::Diagonal, y::AbstractVector) = | ||
mapreduce(t -> t[1]*t[2]*t[3], +, zip(x, D.diag, y)) | ||
*(x::Transpose{<:Any,<:AbstractVector}, D::Diagonal) = Transpose(map(*, D.diag, parent(x))) | ||
*(x::Transpose{<:Any,<:AbstractVector}, D::Diagonal) = Transpose(map((t,s) -> transpose(t)*s, D.diag, parent(x))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this change the behavior? Was this previously non-recursive? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here's why I call this a bugfix and think it's worthy of a backport: julia> A = reshape([[1 2; 3 4], zeros(Int,2,2), zeros(Int, 2, 2), [5 6; 7 8]], 2, 2)
2×2 Array{Array{Int64,2},2}:
[1 2; 3 4] [0 0; 0 0]
[0 0; 0 0] [5 6; 7 8]
julia> adjoint(1:2) * A
1×2 Adjoint{Adjoint{Int64,Array{Int64,2}},Array{Array{Int64,2},1}}:
[1 2; 3 4] [10 12; 14 16]
julia> transpose(1:2) * A
1×2 Transpose{Transpose{Int64,Array{Int64,2}},Array{Array{Int64,2},1}}:
[1 2; 3 4] [10 12; 14 16]
julia> adjoint(1:2) * Diagonal(A)
1×2 Adjoint{Adjoint{Int64,Array{Int64,2}},Array{Array{Int64,2},1}}:
[1 2; 3 4] [10 12; 14 16]
julia> transpose(1:2) * Diagonal(A)
1×2 Transpose{Transpose{Int64,Array{Int64,2}},Array{Array{Int64,2},1}}:
[1 3; 2 4] [10 14; 12 16] |
||
*(x::Transpose{<:Any,<:AbstractVector}, D::Diagonal, y::AbstractVector) = | ||
mapreduce(t -> t[1]*t[2]*t[3], +, zip(x, D.diag, y)) | ||
# TODO: these methods will yield row matrices, rather than adjoint/transpose vectors | ||
|
||
function cholesky!(A::Diagonal, ::Val{false} = Val(false); check::Bool = true) | ||
info = 0 | ||
|
Uh oh!
There was an error while loading. Please reload this page.