Bug in matrix times subarray with decreasing index

linearalgebra

#1

Simple MWE:

A = ones(2,2)
v = [1.0; 2.0]
A * v # [3.0; 3.0]
A * v[2:-1:1] # [3.0; 3.0]
A * view(v, 2:-1:1) # [2.0; 2.0] ????

Is this a bug?


#2

Yes. The matrix multiplication ultimately dispatches to BLAS gemv:

via

BLAS gemv probably assumes that the stride is nonnegative. LinearAlgebra.generic_matvecmul! does do the right thing though, so the latter method could just check for a negative stride and fall back to that.


#3

Poster the issue. Thanks.