tfhe: get rid of constant generics

This commit is contained in:
2025-08-13 19:31:43 +00:00
parent 2a9cbc71de
commit bb3288f211
16 changed files with 729 additions and 582 deletions

View File

@@ -19,7 +19,6 @@ pub mod tuple_ring;
pub mod ntt;
// expose objects
pub use complex::C;
pub use matrix::Matrix;
pub use torus::T64;

View File

@@ -6,11 +6,7 @@
//! generics; but once using real-world parameters, the stack could not handle
//! it, so moved to use Vec instead of fixed-sized arrays, and adapted the NTT
//! implementation to that too.
use crate::{
ring::{Ring, RingParam},
ring_nq::Rq,
zq::Zq,
};
use crate::{ring::RingParam, ring_nq::Rq, zq::Zq};
use std::collections::HashMap;
@@ -197,6 +193,7 @@ const fn const_inv_mod(q: u64, x: u64) -> u64 {
#[cfg(test)]
mod tests {
use super::*;
use crate::Ring;
use anyhow::Result;

View File

@@ -1,16 +1,11 @@
//! Polynomial ring Z[X]/(X^N+1)
//!
use anyhow::Result;
use itertools::zip_eq;
use rand::{distributions::Distribution, Rng};
use std::array;
use std::borrow::Borrow;
use std::fmt;
use std::iter::Sum;
use std::ops::{Add, AddAssign, Mul, MulAssign, Neg, Sub, SubAssign};
use crate::Ring;
use std::ops::{Add, AddAssign, Mul, Neg, Sub, SubAssign};
// TODO rename to not have name conflicts with the Ring trait (R: Ring)
// PolynomialRing element, where the PolynomialRing is R = Z[X]/(X^n +1)

View File

@@ -4,8 +4,6 @@
use anyhow::{anyhow, Result};
use itertools::zip_eq;
use rand::{distributions::Distribution, Rng};
use std::array;
use std::borrow::Borrow;
use std::fmt;
use std::iter::Sum;
use std::ops::{Add, AddAssign, Mul, Neg, Sub, SubAssign};

View File

@@ -9,7 +9,6 @@
use itertools::zip_eq;
use rand::{distributions::Distribution, Rng};
use std::array;
use std::iter::Sum;
use std::ops::{Add, AddAssign, Mul, Neg, Sub, SubAssign};

View File

@@ -1,15 +1,9 @@
//! This file implements the struct for an Tuple of Ring Rq elements and its
//! operations, which are performed element-wise.
use anyhow::Result;
use itertools::zip_eq;
use rand::{distributions::Distribution, Rng};
use rand_distr::{Normal, Uniform};
use std::iter::Sum;
use std::{
array,
ops::{Add, Mul, Neg, Sub},
};
use std::ops::{Add, Mul, Neg, Sub};
use crate::{Ring, RingParam};
@@ -28,23 +22,23 @@ impl<R: Ring> TR<R> {
assert_eq!(r.len(), k);
Self { k, r }
}
pub fn zero(k: usize, r_params: &RingParam) -> Self {
pub fn zero(k: usize, r_param: &RingParam) -> Self {
Self {
k,
r: (0..k).into_iter().map(|_| R::zero(r_params)).collect(),
r: (0..k).into_iter().map(|_| R::zero(r_param)).collect(),
}
}
pub fn rand(
mut rng: impl Rng,
dist: impl Distribution<f64>,
k: usize,
r_params: &RingParam,
r_param: &RingParam,
) -> Self {
Self {
k,
r: (0..k)
.into_iter()
.map(|_| R::rand(&mut rng, &dist, r_params))
.map(|_| R::rand(&mut rng, &dist, r_param))
.collect(),
}
}

View File

@@ -1,5 +1,4 @@
use rand::{distributions::Distribution, Rng};
use std::borrow::Borrow;
use std::fmt;
use std::ops::{Add, AddAssign, Div, Mul, Neg, Sub, SubAssign};