MCPcopy Create free account
hub / github.com/ciphermodelabs/ciphercore / instantiate

Method instantiate

ciphercore-base/src/ops/adder.rs:58–83  ·  view source on GitHub ↗
(&self, context: Context, arguments_types: Vec<Type>)

Source from the content-addressed store, hash-verified

56#[typetag::serde]
57impl 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)

Callers

nothing calls this directly

Calls 14

pull_out_bits_pairFunction · 0.85
put_in_bitsFunction · 0.85
calculate_carry_bitsFunction · 0.85
cloneMethod · 0.80
get_nameMethod · 0.45
create_graphMethod · 0.45
inputMethod · 0.45
custom_opMethod · 0.45
create_tupleMethod · 0.45
set_as_outputMethod · 0.45
finalizeMethod · 0.45

Tested by

no test coverage detected