dimforge / dimforge/nalgebra

Slow matrix-vector multiplication

Open
#334 6 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
4.8k
Forks
565
PR merge metrics
No merged PRs in 30d

Description

I was trying to speed up my neural network calculations (which involve many matrix-vector multiplications and found that simply writing the multiplication with a reference to the matrix rather than the matrix itself produced a 36% reduction in run-time.

Is there any reason why `m*v` should be so much slower than `&m*v`? If not, would it be possible to make them both fast?

Example:
```
extern crate nalgebra;
use nalgebra::*;

fn main() {
let mut s = 0f64;

let m:MatrixMN = zero();
let mut v:VectorN = zero();
let mut r:VectorN = zero();

for _ in 0..10000000 {
r = &m*v; // fast
// r = m*v; // slow
s += r.iter().sum::();
}

println!("{}", s);
}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.