Skip to content

Calling BLAS and negative step views #813

@ghost

Description

@ghost
M = [2. 3.; 0. 0.] 
a = [1.,2.,3.]

v = view(a,3:-1:2)
@test M * v ≈ M * Vector(v)

should pass but fails
Evaluated: [9.0, 0.0] ≈ [12.0, 0.0]

Found while looking at #768, present on a recent 1.7.0-DEV, and 1.4.1.

Looking at LinearAlgebra/blas.jl, it seems there might be more functions which do not correctly handle negative stride yet, that is, the case of a StridedVector being a SubArray.

For the above example, there should be a fix similar to PR JuliaLang/julia#39751. If so, one should probably add an inline function computing the pointer to the first element (in the sense of having the lowest address in memory) of a StridedVector, and use this function when BLAS.dgemv is called for StridedVectors (and make the change from JuliaLang/julia#39751 use this function, too/take the code from there).

Warning: This is based on the assumption that the step size can be negative in the BLAS function.
Reading dgemv.f, I got the impression that negative strides are supported for dgemv in OpenBLAS StridedVector's.
Also page 40 of blas-report.pdf sounds like other BLAS functions should support negative stride for vectors.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions