diff --git a/stdlib/LinearAlgebra/src/blas.jl b/stdlib/LinearAlgebra/src/blas.jl index 661e9e2b15617..f62ed413703dc 100644 --- a/stdlib/LinearAlgebra/src/blas.jl +++ b/stdlib/LinearAlgebra/src/blas.jl @@ -664,8 +664,8 @@ for (fname, elty) in ((:dgemv_,:Float64), throw(DimensionMismatch("the transpose of A has dimensions $n, $m, X has length $(length(X)) and Y has length $(length(Y))")) end chkstride1(A) - lda = stride(A,2) - lda >= max(1, size(A,1)) || error("`stride(A,2)` must be at least `max(1, size(A,1))`") + stride(A,2) >= size(A,1) || size(A,1) == 0 || size(A,2) <= 1 || error("`lda` must be at least `max(1, size(A,1))`") + lda = max(1, size(A,1), stride(A,2)) sX = stride(X,1) pX = pointer(X, sX > 0 ? firstindex(X) : lastindex(X)) sY = stride(Y,1) diff --git a/stdlib/LinearAlgebra/test/blas.jl b/stdlib/LinearAlgebra/test/blas.jl index df29c171b2060..3410387b5e133 100644 --- a/stdlib/LinearAlgebra/test/blas.jl +++ b/stdlib/LinearAlgebra/test/blas.jl @@ -404,6 +404,9 @@ Random.seed!(100) @test_throws ErrorException BLAS.gemv(trans, view(A, 1:2:3, 1:2), view(v, 1:2)) @test_throws ErrorException BLAS.gemv(trans, view(A, 1:2, 2:-1:1), view(v, 1:2)) end + # Cases that should work despite stride(A,2) < 1 + @test BLAS.gemv!('N', elty(1), zeros(elty, 0, 5), zeros(elty, 5), elty(1), zeros(elty, 0)) == elty[] # stride(A,2) == 0 + @test BLAS.gemv!('N', elty(1), view(A, :, 2:-1:2), elty[3], elty(2), elty[1,2,3]) == 3.0*A[:,2] + elty[2,4,6] # stride(A,2) == -3 end end @testset "gemm" begin