diff options
| author | Christoph Groth <christoph.groth@cea.fr> | 2025-01-09 21:59:23 +0100 |
|---|---|---|
| committer | Christoph Groth <christoph.groth@cea.fr> | 2025-01-09 22:22:38 +0100 |
| commit | 2ec9bbe18b57d0673a7065c23ca5d40184bf55ce (patch) | |
| tree | f958429017d1e76b5824e7fe29b88364f9efa25c /src | |
| parent | 0352f2f8b17d32aae62fdd020299c25060c223fd (diff) | |
New conversions allow to use a dynamic rank array with matmul
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.rs | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/main.rs b/src/main.rs index a8eec44..021e799 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -use mdarray::{view, array, tensor, Slice, Dim, Const, Dyn, expr::Expression}; +use mdarray::{view, array, tensor, Slice, Dim, Const, Dyn, Rank, expr::Expression, Dense}; // Indexing convention: C_ij <- A_ik * B_kj fn matmul<D0: Dim, D1: Dim, D2: Dim>( @@ -19,13 +19,14 @@ fn main() { let b = array![[0.0, 1.0], [1.0, 1.0]]; let b = b.reshape((Const::<2>, Dyn(!0))); - let mut c = tensor![[0.0; 2]; 3]; + // .into_dyn() replaces .reshape(DynRank::from_dims(&[2, 3])).into(): + let mut c: mdarray::Tensor<f64> = tensor![[0.0; 2]; 3].into_dyn(); dbg!(std::any::type_name_of_val(&a)); dbg!(std::any::type_name_of_val(&b)); dbg!(std::any::type_name_of_val(&c)); - matmul(&a.reshape((Dyn(3), Const::<2>)), &b, &mut c); + matmul(&a.reshape((Dyn(3), Const::<2>)), &b, &mut c.remap_mut()); assert_eq!(c, view![[4.0, 5.0], [5.0, 7.0], [6.0, 9.0]]); @@ -38,6 +39,7 @@ fn main() { dbg!(std::any::type_name_of_val(&e)); // permute - let f = c.permute::<1, 0>(); + let f = c.remap::<Rank<2>, Dense>(); + let f = f.permute::<1, 0>(); dbg!(std::any::type_name_of_val(&f)); } |
