Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix blas mat-vec multiplication on array with only 1 nontrivial dimension #585

Merged
merged 3 commits into from
Sep 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions blas-tests/tests/oper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ fn dot_product() {
assert_eq!(a.dot(&b), dot as i32);
}

#[test]
fn mat_vec_product_1d() {
let a = arr2(&[[1.], [2.]]);
let b = arr1(&[1., 2.]);
let ans = arr1(&[5.]);
assert_eq!(a.t().dot(&b), ans);
}

// test that we can dot product with a broadcast array
#[test]
fn dot_product_0() {
Expand Down
8 changes: 6 additions & 2 deletions src/linalg/impl_linalg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -588,8 +588,12 @@ pub fn general_mat_vec_mul<A, S1, S2, S3>(alpha: A,
{
let a_trans = CblasNoTrans;
let a_stride = match layout {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to add a comment, e.g.

                        // Determine stride between rows or columns. Note that the stride is
                        // adjusted to at least `k` or `m` to handle the case of a matrix with a
                        // trivial (length 1) dimension, since the stride for the trivial dimension
                        // may be arbitrary.

CBLAS_LAYOUT::CblasRowMajor => a.strides()[0] as blas_index,
CBLAS_LAYOUT::CblasColMajor => a.strides()[1] as blas_index,
CBLAS_LAYOUT::CblasRowMajor => {
a.strides()[0].max(k as isize) as blas_index
}
CBLAS_LAYOUT::CblasColMajor => {
a.strides()[1].max(m as isize) as blas_index
}
};

let x_stride = x.strides()[0] as blas_index;
Expand Down