rstsr/lib.rs
1#![doc = include_str!("../notes_to_api_doc.md")]
2#![doc = include_str!("../readme.md")]
3pub mod prelude;
4
5#[test]
6fn test() {
7 use crate::prelude::*;
8
9 // 3x2 matrix with c-contiguous memory layout
10 let a = rt::asarray((vec![6., 2., 7., 4., 8., 5.], [3, 2].c()));
11
12 // 2x4x3 matrix by arange and reshaping
13 let b = rt::arange(24.);
14 let b = b.reshape((-1, 4, 3));
15 // in one line, you can also
16 // let b = rt::arange(24.).into_shape((-1, 4, 3));
17
18 // broadcasted matrix multiplication
19 let c = b % a;
20
21 // print layout of the result
22 println!("{:?}", c.layout());
23 // output:
24 // 3-Dim (dyn), contiguous: Cc
25 // shape: [2, 4, 2], stride: [8, 2, 1], offset: 0
26
27 // print the result
28 println!("{:6.1}", c)
29 // output:
30 // [[[ 23.0 14.0]
31 // [ 86.0 47.0]
32 // [ 149.0 80.0]
33 // [ 212.0 113.0]]
34 //
35 // [[ 275.0 146.0]
36 // [ 338.0 179.0]
37 // [ 401.0 212.0]
38 // [ 464.0 245.0]]]
39}