Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/diagonal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,8 @@ end

function rmul!(A::AbstractMatrix, D::Diagonal)
matmul_size_check(size(A), size(D))
axes(A, 2) == axes(D.diag, 1) ||
throw(ArgumentError(lazy"second axis of A, $(axes(A,2)), does not match first axis of D, $(axes(D, 1))"))
for I in CartesianIndices(A)
row, col = Tuple(I)
@inbounds A[row, col] *= D.diag[col]
Expand Down Expand Up @@ -406,6 +408,8 @@ end

function lmul!(D::Diagonal, B::AbstractVecOrMat)
matmul_size_check(size(D), size(B))
axes(D.diag, 1) == axes(B, 1) ||
throw(ArgumentError(lazy"second axis of D, $(axes(D, 2)), does not match first axis of B, $(axes(B, 1))"))
for I in CartesianIndices(B)
row = I[1]
@inbounds B[I] = D.diag[row] * B[I]
Expand Down
2 changes: 2 additions & 0 deletions test/diagonal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,9 @@ end
D = Diagonal(1:4)
A = OffsetArray(rand(4,4), 2, 2)
@test_throws ArgumentError D * A
@test_throws ArgumentError lmul!(D, A)
@test_throws ArgumentError A * D
@test_throws ArgumentError rmul!(A, D)
@test_throws ArgumentError mul!(similar(A, size(A)), A, D)
@test_throws ArgumentError mul!(similar(A, size(A)), D, A)
end
Expand Down