Skip to content

Commit

Permalink
Merge pull request #4 from upupnoah/main
Browse files Browse the repository at this point in the history
docs: add some annotation for matrix concurrency
  • Loading branch information
upupnoah authored Jul 9, 2024
2 parents c73a65f + 3cd7cd6 commit f2f0af9
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ impl<T> Msg<T> {
// endregion: --- impls

// region: --- functions
// AB -> a.col == b.row (左乘)
// 最后的矩阵是一个 a.row * b.col 的矩阵
pub fn multiply<T>(a: &Matrix<T>, b: &Matrix<T>) -> Result<Matrix<T>>
where
T: Copy + Default + Add<Output = T> + AddAssign + Mul<Output = T> + Send + 'static,
Expand All @@ -127,6 +129,7 @@ where
// for i in 0..a.row {
// for j in 0..b.col {
// for k in 0..a.col {
// // data[i][j] += a[i][k] * b[k][j]
// data[i * b.col + j] += a.data[i * a.col + k] * b.data[k * b.col + j];
// }
// }
Expand Down Expand Up @@ -156,14 +159,14 @@ where
// map/reduce: map phase
for i in 0..a.row {
for j in 0..b.col {
let row = Vector::new(&a.data[i * a.col..(i + 1) * a.col]);
let row = Vector::new(&a.data[i * a.col..(i + 1) * a.col]); // a[i][k]
let col_data = b.data[j..]
.iter()
.step_by(b.col)
.copied()
.collect::<Vec<_>>();
let col = Vector::new(col_data);
let idx = i * b.col + j;
let col = Vector::new(col_data); // b[k][j]
let idx = i * b.col + j; // i,j -> idx
let input = MsgInput::new(idx, row, col);
let (tx, rx) = oneshot::channel();
let msg = Msg::new(input, tx);
Expand Down

0 comments on commit f2f0af9

Please sign in to comment.