This commit is contained in:
Jean-Philippe Bossuat
2025-02-04 17:13:46 +01:00
parent e4a976ec9e
commit a790ff37cc
14 changed files with 1097 additions and 683 deletions

77
base2k/src/infos.rs Normal file
View File

@@ -0,0 +1,77 @@
use crate::{VecZnx, VmpPMat};
pub trait Infos {
/// Returns the ring degree of the receiver.
fn n(&self) -> usize;
/// Returns the base two logarithm of the ring dimension of the receiver.
fn log_n(&self) -> usize;
/// Returns the number of limbs of the receiver.
/// This method is equivalent to [Infos::cols].
fn limbs(&self) -> usize;
/// Returns the number of columns of the receiver.
/// This method is equivalent to [Infos::limbs].
fn cols(&self) -> usize;
/// Returns the number of rows of the receiver.
fn rows(&self) -> usize;
}
impl Infos for VecZnx {
/// Returns the base 2 logarithm of the [VecZnx] degree.
fn log_n(&self) -> usize {
(usize::BITS - (self.n - 1).leading_zeros()) as _
}
/// Returns the [VecZnx] degree.
fn n(&self) -> usize {
self.n
}
/// Returns the number of limbs of the [VecZnx].
fn limbs(&self) -> usize {
self.data.len() / self.n
}
/// Returns the number of limbs of the [VecZnx].
fn cols(&self) -> usize {
self.data.len() / self.n
}
/// Returns the number of limbs of the [VecZnx].
fn rows(&self) -> usize {
1
}
}
impl Infos for VmpPMat {
/// Returns the ring dimension of the [VmpPMat].
fn n(&self) -> usize {
self.n
}
fn log_n(&self) -> usize {
(usize::BITS - (self.n() - 1).leading_zeros()) as _
}
/// Returns the number of limbs of each [VecZnxDft].
/// This method is equivalent to [Self::cols].
fn limbs(&self) -> usize {
self.cols
}
/// Returns the number of rows (i.e. of [VecZnxDft]) of the [VmpPMat]
fn rows(&self) -> usize {
self.rows
}
/// Returns the number of cols of the [VmpPMat].
/// The number of cols refers to the number of limbs
/// of each [VecZnxDft].
/// This method is equivalent to [Self::limbs].
fn cols(&self) -> usize {
self.cols
}
}