arnaucube
arnaucube/fhe-studyPublic Self-hosted repository
fhe-study/arith/src/traits.rs
arith/src/traits.rsRaw
 1use anyhow::Result;
 2use rand::{distributions::Distribution, Rng};
 3use std::fmt::Debug;
 4use std::iter::Sum;
 5use std::ops::{Add, AddAssign, Mul, Sub, SubAssign};
 6
 7/// Represents a ring element. Currently implemented by ring.rs#R and ringq.rs#Rq.
 8pub trait Ring:
 9    Sized
10    + Add<Output = Self>
11    + AddAssign
12    + Sum
13    + Sub<Output = Self>
14    + SubAssign
15    + Mul<Output = Self>
16    + Mul<u64, Output = Self> // scalar mul
17    + PartialEq
18    + Debug
19    + Clone
20    + Sum<<Self as Add>::Output>
21    + Sum<<Self as Mul>::Output>
22{
23    /// C defines the coefficient type
24    type C: Debug + Clone;
25
26    fn coeffs(&self) -> Vec<Self::C>;
27    fn zero() -> Self;
28    // note/wip/warning: dist (0,q) with f64, will output more '0=q' elements than other values
29    fn rand(rng: impl Rng, dist: impl Distribution<f64>) -> Self;
30}