| 603 | } |
| 604 | |
| 605 | fn truncate_helper(st: ScalarType, scale: u128) -> Result<()> { |
| 606 | let helper = |t: Type, |
| 607 | input: Vec<u128>, |
| 608 | input_status: IOStatus, |
| 609 | output_parties: Vec<IOStatus>, |
| 610 | inline_config: InlineConfig| |
| 611 | -> Result<()> { |
| 612 | let mpc_context = prepare_context( |
| 613 | t.clone(), |
| 614 | input_status.clone(), |
| 615 | output_parties.clone(), |
| 616 | scale, |
| 617 | inline_config, |
| 618 | )?; |
| 619 | let mpc_graph = mpc_context.get_main_graph()?; |
| 620 | |
| 621 | let mpc_input = prepare_input(input.clone(), input_status.clone(), t.clone())?; |
| 622 | |
| 623 | let expected = if t.get_scalar_type().is_signed() { |
| 624 | input |
| 625 | .iter() |
| 626 | .map(|x| { |
| 627 | let val = *x as i64; |
| 628 | let res = val / (scale as i64); |
| 629 | res as u128 |
| 630 | }) |
| 631 | .collect() |
| 632 | } else { |
| 633 | input |
| 634 | .iter() |
| 635 | .map(|x| { |
| 636 | let val = *x; |
| 637 | let res = val / (scale as u128); |
| 638 | res |
| 639 | }) |
| 640 | .collect() |
| 641 | }; |
| 642 | check_output(mpc_graph, mpc_input, expected, output_parties, t.clone())?; |
| 643 | |
| 644 | Ok(()) |
| 645 | }; |
| 646 | let inline_config_simple = InlineConfig { |
| 647 | default_mode: InlineMode::Simple, |
| 648 | ..Default::default() |
| 649 | }; |
| 650 | let helper_runs = |inputs: Vec<u128>, t: Type| -> Result<()> { |
| 651 | helper( |
| 652 | t.clone(), |
| 653 | inputs.clone(), |
| 654 | IOStatus::Party(2), |
| 655 | vec![IOStatus::Party(0), IOStatus::Party(1), IOStatus::Party(2)], |
| 656 | inline_config_simple.clone(), |
| 657 | )?; |
| 658 | helper( |
| 659 | t.clone(), |
| 660 | inputs.clone(), |
| 661 | IOStatus::Shared, |
| 662 | vec![IOStatus::Party(0), IOStatus::Party(1), IOStatus::Party(2)], |