th_rust/gate/
copy.rs

1use na::DMatrix;
2use crate::gate::Gate;
3use crate::pbit::GridPbit;
4
5pub struct Copy {
6	pbits: Vec<GridPbit>,
7	weight: DMatrix<i32>,
8	bias: Vec<i32>,
9}
10
11impl Copy {
12	pub fn new(m1: GridPbit, m2: GridPbit) -> Copy {
13		let weight = DMatrix::<i32>::from_vec(2, 2, vec![0, 1, 1, 0]);
14		let bias = vec![0, 0];
15		Copy { pbits: vec![m1, m2], weight, bias }
16	}
17}
18
19impl Gate for Copy {
20	fn pbits(&self) -> &Vec<GridPbit> {
21		&self.pbits
22	}
23
24	fn shape(&self) -> (usize, usize) {
25		(2, 2)
26	}
27
28	fn weight(&self) -> &DMatrix<i32> {
29		&self.weight
30	}
31
32	fn bias(&self) -> &Vec<i32> {
33		&self.bias
34	}
35}