mikkyang/rust-blas

Passing wrong LDA to BLAS

raineszm opened this issue · 0 comments

Sorry to pester.

The default implementation of Matrix<T> has RowMajor ordering but returns rows for lead_dim which is in turn used by BLAS as the LDA argument for the matrix. However, unless I'm just being dumb, for a row major ordered matrix, the leading dimension should be the number of columns. This appears to have not bee caught by the tests because they use square matrices. As a minimal example of the problem, consider,

        let a = (2, 3,
                 vec![
                 1.0, -3.0, 1.0,
                 2.0, -6.0, 2.0]);
        let x = vec![2.0, 1.0, 1.0];
        let mut y = vec![1.0, 2.0];
        let t = Transpose::NoTrans;

        Gemv::gemv(t, &1f32, &a, &x, &0f32, &mut y);

        assert_eq!(y, vec![0.0, 0.0]);

which will give an error like
BLAS error: Parameter lda passed to cblas_sgemv was 2, which is invalid.
depending on what BLAS implementation your using. The solution is either to have lead_dim default to cols or to have it determine the appropriate lead dimension by matching on the ordering. I have a fix in the bugfix branch of my fork if you'd like to use that.

Thanks!