arnaucube
arnaucube/poulpyPublic Self-hosted repository
poulpy/base2k/src/infos.rs
base2k/src/infos.rsRaw
  1use crate::{VecZnx, VecZnxBorrow, VmpPMat};
  2
  3pub trait Infos {
  4    /// Returns the ring degree of the receiver.
  5    fn n(&self) -> usize;
  6
  7    /// Returns the base two logarithm of the ring dimension of the receiver.
  8    fn log_n(&self) -> usize;
  9
 10    /// Returns the number of limbs of the receiver.
 11    /// This method is equivalent to [Infos::cols].
 12    fn limbs(&self) -> usize;
 13
 14    /// Returns the number of columns of the receiver.
 15    /// This method is equivalent to [Infos::limbs].
 16    fn cols(&self) -> usize;
 17
 18    /// Returns the number of rows of the receiver.
 19    fn rows(&self) -> usize;
 20}
 21
 22impl Infos for VecZnx {
 23    /// Returns the base 2 logarithm of the [VecZnx] degree.
 24    fn log_n(&self) -> usize {
 25        (usize::BITS - (self.n - 1).leading_zeros()) as _
 26    }
 27
 28    /// Returns the [VecZnx] degree.
 29    fn n(&self) -> usize {
 30        self.n
 31    }
 32
 33    /// Returns the number of limbs of the [VecZnx].
 34    fn limbs(&self) -> usize {
 35        self.data.len() / self.n
 36    }
 37
 38    /// Returns the number of limbs of the [VecZnx].
 39    fn cols(&self) -> usize {
 40        self.data.len() / self.n
 41    }
 42
 43    /// Returns the number of limbs of the [VecZnx].
 44    fn rows(&self) -> usize {
 45        1
 46    }
 47}
 48
 49impl Infos for VecZnxBorrow {
 50    /// Returns the base 2 logarithm of the [VecZnx] degree.
 51    fn log_n(&self) -> usize {
 52        (usize::BITS - (self.n - 1).leading_zeros()) as _
 53    }
 54
 55    /// Returns the [VecZnx] degree.
 56    fn n(&self) -> usize {
 57        self.n
 58    }
 59
 60    /// Returns the number of limbs of the [VecZnx].
 61    fn limbs(&self) -> usize {
 62        self.limbs
 63    }
 64
 65    /// Returns the number of limbs of the [VecZnx].
 66    fn cols(&self) -> usize {
 67        self.limbs
 68    }
 69
 70    /// Returns the number of limbs of the [VecZnx].
 71    fn rows(&self) -> usize {
 72        1
 73    }
 74}
 75
 76impl Infos for VmpPMat {
 77    /// Returns the ring dimension of the [VmpPMat].
 78    fn n(&self) -> usize {
 79        self.n
 80    }
 81
 82    fn log_n(&self) -> usize {
 83        (usize::BITS - (self.n() - 1).leading_zeros()) as _
 84    }
 85
 86    /// Returns the number of limbs of each [VecZnxDft].
 87    /// This method is equivalent to [Self::cols].
 88    fn limbs(&self) -> usize {
 89        self.cols
 90    }
 91
 92    /// Returns the number of rows (i.e. of [VecZnxDft]) of the [VmpPMat]
 93    fn rows(&self) -> usize {
 94        self.rows
 95    }
 96
 97    /// Returns the number of cols of the [VmpPMat].
 98    /// The number of cols refers to the number of limbs  
 99    /// of each [VecZnxDft].
100    /// This method is equivalent to [Self::limbs].
101    fn cols(&self) -> usize {
102        self.cols
103    }
104}