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

Function test_inline_iterate

ciphercore-base/src/inline/inline_ops.rs:672–721  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

670
671 #[test]
672 fn test_inline_iterate() {
673 let helper = |mode| -> Result<()> {
674 let c = create_context()?;
675
676 let g0 = c.create_graph()?;
677 {
678 let i01 = g0.input(scalar_type(BIT))?;
679 let i02 = g0.input(scalar_type(BIT))?;
680 let sum12 = g0.add(i01.clone(), i02.clone())?;
681 let out = g0.create_tuple(vec![sum12.clone(), sum12.clone()])?;
682 out.set_name("CreateTuple output")?;
683 g0.set_output_node(out)?;
684 g0.finalize()?;
685 }
686
687 let g1 = c.create_graph()?;
688 {
689 let i21 = g1.input(scalar_type(BIT))?;
690 let i22 = g1.input(scalar_type(BIT))?;
691 let i23 = g1.input(scalar_type(BIT))?;
692 let o1 = g1.tuple_get(g1.call(g0.clone(), vec![i21, i22])?, 0)?;
693 let input_vec = g1.repeat(i23, 5)?;
694 let o2 = g1.iterate(g0.clone(), o1, input_vec)?;
695 o2.set_name("Iterate output")?;
696 let o3 = g1.tuple_get(o2, 0)?;
697 g1.set_output_node(o3.clone())?;
698 g1.finalize()?;
699 }
700 c.set_main_graph(g1.clone())?;
701 c.finalize()?;
702 let c_out = inline_operations(
703 c.clone(),
704 InlineConfig {
705 default_mode: mode,
706 ..Default::default()
707 },
708 )?;
709 assert_eq!(c_out.get_graphs().len(), 1);
710 verify_on_all_inputs(g1.clone(), c_out.get_main_graph()?)?;
711 // Check names
712 let inlined_g = c_out.get_main_graph()?;
713 let named_iterate_result = c_out.retrieve_node(inlined_g.clone(), "Iterate output");
714 assert!(named_iterate_result.is_ok());
715 let named_iterate = named_iterate_result?;
716 assert_eq!(named_iterate.get_operation(), Operation::CreateTuple);
717 Ok(())
718 };
719 helper(InlineMode::Simple).unwrap();
720 helper(InlineMode::DepthOptimized(DepthOptimizationLevel::Extreme)).unwrap();
721 }
722
723 #[test]
724 fn test_nested_iterate() {

Callers

nothing calls this directly

Calls 15

inline_operationsFunction · 0.85
verify_on_all_inputsFunction · 0.85
cloneMethod · 0.80
create_contextFunction · 0.50
scalar_typeFunction · 0.50
create_graphMethod · 0.45
inputMethod · 0.45
addMethod · 0.45
create_tupleMethod · 0.45
set_nameMethod · 0.45
set_output_nodeMethod · 0.45
finalizeMethod · 0.45

Tested by

no test coverage detected