summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorChristoph Groth <christoph.groth@cea.fr>2024-10-24 12:45:51 +0200
committerChristoph Groth <christoph.groth@cea.fr>2024-10-24 12:45:51 +0200
commitbf6dbef4ed28f3135eb48ed03ac31a7242f68340 (patch)
tree3a99f9baa114dde515f6e7517066c69280fe8f22 /src/main.rs
Official example, before API change
https://docs.rs/mdarray/0.6.1/mdarray/#example
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs
new file mode 100644
index 0000000..898142c
--- /dev/null
+++ b/src/main.rs
@@ -0,0 +1,22 @@
+use mdarray::{expr, grid, DSpan, Expression};
+
+fn matmul(a: &DSpan<f64, 2>, b: &DSpan<f64, 2>, c: &mut DSpan<f64, 2>) {
+ for (mut cj, bj) in c.cols_mut().zip(b.cols()) {
+ for (ak, bkj) in a.cols().zip(bj) {
+ for (cij, aik) in cj.expr_mut().zip(ak) {
+ *cij = aik.mul_add(*bkj, *cij);
+ }
+ }
+ }
+}
+
+fn main() {
+ let a = expr![[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]];
+ let b = expr![[0.0, 1.0], [1.0, 1.0]];
+
+ let mut c = grid![[0.0; 3]; 2];
+
+ matmul(&a, &b, &mut c);
+
+ assert_eq!(c, expr![[4.0, 5.0, 6.0], [5.0, 7.0, 9.0]]);
+}