tensorlogic_infer/
dummy_tensor.rs1#[derive(Debug, Clone)]
8pub struct DummyTensor {
9 pub name: String,
10 pub shape: Vec<usize>,
11 pub data: Vec<f64>,
12}
13
14impl DummyTensor {
15 pub fn new(name: impl Into<String>, shape: Vec<usize>) -> Self {
16 let size: usize = shape.iter().product();
17 DummyTensor {
18 name: name.into(),
19 shape,
20 data: vec![0.0; size],
21 }
22 }
23
24 pub fn with_data(name: impl Into<String>, shape: Vec<usize>, data: Vec<f64>) -> Self {
25 assert_eq!(shape.iter().product::<usize>(), data.len());
26 DummyTensor {
27 name: name.into(),
28 shape,
29 data,
30 }
31 }
32
33 pub fn size(&self) -> usize {
34 self.shape.iter().product()
35 }
36
37 pub fn zeros(name: impl Into<String>, shape: Vec<usize>) -> Self {
38 Self::new(name, shape)
39 }
40
41 pub fn ones(name: impl Into<String>, shape: Vec<usize>) -> Self {
42 let size: usize = shape.iter().product();
43 DummyTensor {
44 name: name.into(),
45 shape,
46 data: vec![1.0; size],
47 }
48 }
49}