Skip to content

Commit 85e4ca7

Browse files
committed
added dimension check
1 parent 5dad812 commit 85e4ca7

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/linalg.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,11 @@ function _A_mul_Bt_or_Bc!(tfun::Function, C::StridedMatrix, A::AbstractMatrix, B
189189
end
190190

191191
function *(A::Diagonal, b::AbstractSparseVector)
192+
if size(A, 2) != length(b)
193+
throw(
194+
DimensionMismatch("The dimension of the matrix A $(size(A)) and of the vector b $(length(b))")
195+
)
196+
end
192197
T = promote_eltype(A, b)
193198
res = similar(b, T)
194199
nzind_b = nonzeroinds(b)

test/linalg.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,8 @@ end
683683
Ac = Diagonal(randn(Complex{Float64}, 10))
684684
@test norm(Ac * b - Ac * Vector(b)) <= 10eps()
685685
@test norm(Ac * b - Array(Ac) * b) <= 10eps()
686+
@test_throws DimensionMismatch A * [b; 1]
687+
@test_throws DimensionMismatch A * b[1:end-1]
686688
end
687689
end
688690

0 commit comments

Comments
 (0)