mirror of
https://github.com/arnaucube/fhe-study.git
synced 2026-01-24 04:33:52 +01:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user