fit T64 into the 'Ring' trait, this is to use it in tfhe instead of using Tn<1> which is more tedious

This commit is contained in:
2025-07-27 19:22:41 +00:00
parent 81306edf05
commit 4f89caef1e
4 changed files with 69 additions and 15 deletions

View File

@@ -10,7 +10,7 @@
use rand::{distributions::Distribution, Rng};
use std::array;
use std::iter::Sum;
use std::ops::{Add, AddAssign, Mul, Sub, SubAssign};
use std::ops::{Add, AddAssign, Mul, Neg, Sub, SubAssign};
use crate::{ring::Ring, torus::T64, Rq, Zq};
@@ -34,7 +34,7 @@ impl<const N: usize> Ring for Tn<N> {
}
fn rand(mut rng: impl Rng, dist: impl Distribution<f64>) -> Self {
Self(array::from_fn(|_| T64::rand_f64(&mut rng, &dist)))
Self(array::from_fn(|_| T64::rand(&mut rng, &dist)))
}
fn from_vec(coeffs: Vec<Self::C>) -> Self {
@@ -152,6 +152,14 @@ impl<const N: usize> SubAssign for Tn<N> {
}
}
impl<const N: usize> Neg for Tn<N> {
type Output = Self;
fn neg(self) -> Self::Output {
Tn(array::from_fn(|i| -self.0[i]))
}
}
impl<const N: usize> PartialEq for Tn<N> {
fn eq(&self, other: &Self) -> bool {
self.0 == other.0