[][src]Trait concrete_lib::types::Types

pub trait Types: Sized {
    type STorus;

    const TORUS_BIT: usize;
    const TORUS_MAX: Self;

    fn round_to_closest_multiple(x: Self, base_log: usize, level: usize) -> Self;
fn torus_small_sign_decompose(res: &mut [Self], val: Self, base_log: usize);
fn signed_decompose_one_level(
        value: Self,
        previous_carry: Self,
        base_log: usize,
        level: usize
    ) -> (Self, Self);
fn torus_to_f64(item: Self) -> f64;
fn f64_to_torus(item: f64) -> Self;
fn set_val_at_level_l(val: Self, base_log: usize, level_l: usize) -> Self;
fn torus_binary_representation(n: Self, base_log: usize) -> String;
fn torus_binary_comparison(t1: Self, t2: Self) -> String; }

Associated Types

type STorus

Loading content...

Associated Constants

const TORUS_BIT: usize

const TORUS_MAX: Self

Loading content...

Required methods

fn round_to_closest_multiple(x: Self, base_log: usize, level: usize) -> Self

fn torus_small_sign_decompose(res: &mut [Self], val: Self, base_log: usize)

fn signed_decompose_one_level(
    value: Self,
    previous_carry: Self,
    base_log: usize,
    level: usize
) -> (Self, Self)

fn torus_to_f64(item: Self) -> f64

fn f64_to_torus(item: f64) -> Self

fn set_val_at_level_l(val: Self, base_log: usize, level_l: usize) -> Self

fn torus_binary_representation(n: Self, base_log: usize) -> String

fn torus_binary_comparison(t1: Self, t2: Self) -> String

Loading content...

Implementations on Foreign Types

impl Types for u32[src]

type STorus = i32

fn round_to_closest_multiple(x: u32, base_log: usize, level: usize) -> u32[src]

Rounds a torus element to its closest torus element with only lv_tot * log_b MSB that can be different from zero

Comments

  • warning: panic when base_log*level >= TORUS_BIT if not in release mode

Example with binary representations:

round_to_closest_multiple(1100100...0,2,2) -> 11010...0 we will only keep 2*2 = 4 MSB so we can put a dot where the rounding happens, which is after the 4th MSB: 1100.1 is rounded to 1101

Arguments

  • x - element of the Torus to be rounded
  • base_log - number of bits for the base B (B=2^base_log)
  • level - number of blocks of the gadget matrix

Output

  • the rounded Torus element

Tests

  • test_round_to_closest_multiple: unit test
  • test_panic_round_to_closest_multiple: panic test when base_log*level == TORUS_BIT

fn torus_small_sign_decompose(res: &mut [u32], val: u32, base_log: usize)[src]

Computes a signed decomposition of a Torus element The base is B = 2^base_log We end up with coefficients in [-B/2, B/2[

Comments

  • used for the gadget decomposition
  • len(res) equals level
  • takes into account the case where a block is equals to 11...11 (only ones) to get the right carry

Arguments

  • res - a tensor of signed integers (output)
  • val - the Torus element to be decomposed
  • base_log - number of bits for the base B (B=2^base_log)

Tests

  • test_torus_small_sign_decompose: unit test

fn signed_decompose_one_level(
    value: u32,
    previous_carry: u32,
    base_log: usize,
    level: usize
) -> (u32, u32)
[src]

This function only gives the level-th piece of the signed decomposition of a value. To do so, it needs the value, the decomposition parameters and the carry from the previous level We end up with coefficients in [-B/2, B/2[

Arguments

  • value - the Torus value we are decomposing
  • previous_carry - the carry form the level+1 level
  • base_log - number of bits for the base B (B=2^base_log)
  • level - the level of the piece of decomposition we want

Tests

  • test_rsd: unit test

fn torus_to_f64(item: u32) -> f64[src]

Converts a torus item to a f64 in [0,1[

Arguments

  • item - a Torus element

Output

  • a f64 in [0,1[

fn f64_to_torus(item: f64) -> u32[src]

Converts a f64 in [0,1[ to a Torus element

Arguments

  • item - a f64 in [0,1[

Output

  • a Torus element

fn set_val_at_level_l(val: u32, base_log: usize, level_l: usize) -> u32[src]

Returns a Torus element with a some bits a the right place according to the base_log and level decomposition

Arguments

  • val - a Torus element containing on its LSB some bit we want to move at a precise place
  • base_log - decomposition log2 base
  • level_l - the desired level

Output

  • a torus element build as desired

fn torus_binary_representation(n: u32, base_log: usize) -> String[src]

Output a string with a binary representation of n (a torus element) if base_log!=0 then bits are packed from MSB to LSD into words of logbase bits if base_log==0 then all bits are in one word

Arguments

  • n - the Torus element we want its representation
  • base_log - decomposition log2 base

Output

  • a String with the binary representation

fn torus_binary_comparison(t1: u32, t2: u32) -> String[src]

Compares 2 Torus element and output a String with X when their bits differs

Arguments

  • t1 - the first Torus element
  • t2 - the second Torus element

Output

  • a String with the binary comparison

impl Types for u64[src]

type STorus = i64

fn round_to_closest_multiple(x: u64, base_log: usize, level: usize) -> u64[src]

Rounds a torus element to its closest torus element with only lv_tot * log_b MSB that can be different from zero

Comments

  • warning: panic when base_log*level >= TORUS_BIT if not in release mode

Example with binary representations:

round_to_closest_multiple(1100100...0,2,2) -> 11010...0 we will only keep 2*2 = 4 MSB so we can put a dot where the rounding happens, which is after the 4th MSB: 1100.1 is rounded to 1101

Arguments

  • x - element of the Torus to be rounded
  • base_log - number of bits for the base B (B=2^base_log)
  • level - number of blocks of the gadget matrix

Output

  • the rounded Torus element

Tests

  • test_round_to_closest_multiple: unit test
  • test_panic_round_to_closest_multiple: panic test when base_log*level == TORUS_BIT

fn torus_small_sign_decompose(res: &mut [u64], val: u64, base_log: usize)[src]

Computes a signed decomposition of a Torus element The base is B = 2^base_log We end up with coefficients in [-B/2, B/2[

Comments

  • used for the gadget decomposition
  • len(res) equals level
  • takes into account the case where a block is equals to 11...11 (only ones) to get the right carry

Arguments

  • res - a tensor of signed integers (output)
  • val - the Torus element to be decomposed
  • base_log - number of bits for the base B (B=2^base_log)

Tests

  • test_torus_small_sign_decompose: unit test

fn signed_decompose_one_level(
    value: u64,
    previous_carry: u64,
    base_log: usize,
    level: usize
) -> (u64, u64)
[src]

This function only gives the level-th piece of the signed decomposition of a value. To do so, it needs the value, the decomposition parameters and the carry from the previous level We end up with coefficients in [-B/2, B/2[

Arguments

  • value - the Torus value we are decomposing
  • previous_carry - the carry form the level+1 level
  • base_log - number of bits for the base B (B=2^base_log)
  • level - the level of the piece of decomposition we want

Tests

  • test_rsd: unit test

fn torus_to_f64(item: u64) -> f64[src]

Converts a torus item to a f64 in [0,1[

Arguments

  • item - a Torus element

Output

  • a f64 in [0,1[

fn f64_to_torus(item: f64) -> u64[src]

Converts a f64 in [0,1[ to a Torus element

Arguments

  • item - a f64 in [0,1[

Output

  • a Torus element

fn set_val_at_level_l(val: u64, base_log: usize, level_l: usize) -> u64[src]

Returns a Torus element with a some bits a the right place according to the base_log and level decomposition

Arguments

  • val - a Torus element containing on its LSB some bit we want to move at a precise place
  • base_log - decomposition log2 base
  • level_l - the desired level

Output

  • a torus element build as desired

fn torus_binary_representation(n: u64, base_log: usize) -> String[src]

Output a string with a binary representation of n (a torus element) if base_log!=0 then bits are packed from MSB to LSD into words of logbase bits if base_log==0 then all bits are in one word

Arguments

  • n - the Torus element we want its representation
  • base_log - decomposition log2 base

Output

  • a String with the binary representation

fn torus_binary_comparison(t1: u64, t2: u64) -> String[src]

Compares 2 Torus element and output a String with X when their bits differs

Arguments

  • t1 - the first Torus element
  • t2 - the second Torus element

Output

  • a String with the binary comparison
Loading content...

Implementors

Loading content...