hello_world/
main.rs

1use constensor_core::{Cpu, Graph, GraphTensor, Tensor, R1, R2};
2
3fn main() {
4    let mut graph: Graph<f32> = Graph::empty();
5    let _arange = GraphTensor::<R1<10>, f32, Cpu>::arange(&mut graph, 0., 1.);
6    let a = GraphTensor::<R2<3, 4>, f32, Cpu>::fill(&mut graph, 1.0);
7    let b = GraphTensor::<R2<3, 4>, f32, Cpu>::fill(&mut graph, 2.0);
8    let c = GraphTensor::<R2<3, 4>, f32, Cpu>::fill(&mut graph, 3.0);
9    let d = GraphTensor::<R2<3, 4>, f32, Cpu>::fill(&mut graph, 4.0);
10    let res = a * b + c;
11    let _out = res + d;
12
13    graph.optimize();
14
15    graph.visualize("graph.png").unwrap();
16
17    let compiled: constensor_core::CompiledGraph<R2<3, 4>, f32, Cpu> = graph.compile().unwrap();
18    let res = compiled.run().unwrap();
19
20    let tensor: Tensor<R2<3, 4>, f32, Cpu> = res;
21
22    assert_eq!(tensor.data().unwrap().to_vec(), vec![vec![9.0; 4]; 3],);
23}