(&self, context: Context, arguments_types: Vec<Type>)
| 56 | #[typetag::serde] |
| 57 | impl CustomOperationBody for BinaryAdd { |
| 58 | fn instantiate(&self, context: Context, arguments_types: Vec<Type>) -> Result<Graph> { |
| 59 | validate_arguments_in_broadcast_bit_ops(arguments_types.clone(), &self.get_name())?; |
| 60 | let input_type0 = arguments_types[0].clone(); |
| 61 | let input_type1 = arguments_types[1].clone(); |
| 62 | |
| 63 | // Adder input consists of two binary strings x and y |
| 64 | let g = context.create_graph()?; |
| 65 | let (input0, input1) = pull_out_bits_pair(g.input(input_type0)?, g.input(input_type1)?)?; |
| 66 | let added = g.custom_op( |
| 67 | CustomOperation::new(BinaryAddTransposed { |
| 68 | overflow_bit: self.overflow_bit, |
| 69 | }), |
| 70 | vec![input0, input1], |
| 71 | )?; |
| 72 | let output = if self.overflow_bit { |
| 73 | g.create_tuple(vec![ |
| 74 | put_in_bits(added.tuple_get(0)?)?, |
| 75 | put_in_bits(added.tuple_get(1)?)?, |
| 76 | ])? |
| 77 | } else { |
| 78 | put_in_bits(added)? |
| 79 | }; |
| 80 | output.set_as_output()?; |
| 81 | g.finalize()?; |
| 82 | Ok(g) |
| 83 | } |
| 84 | |
| 85 | fn get_name(&self) -> String { |
| 86 | format!("BinaryAdd(overflow_bit={})", self.overflow_bit) |
nothing calls this directly
no test coverage detected