arnaucube
arnaucube/poulpyPublic Self-hosted repository
poulpy/base2k/src/infos.rs
base2k/src/infos.rsRaw
 1use crate::{VecZnx, 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 VmpPMat {
50    /// Returns the ring dimension of the [VmpPMat].
51    fn n(&self) -> usize {
52        self.n
53    }
54
55    fn log_n(&self) -> usize {
56        (usize::BITS - (self.n() - 1).leading_zeros()) as _
57    }
58
59    /// Returns the number of limbs of each [VecZnxDft].
60    /// This method is equivalent to [Self::cols].
61    fn limbs(&self) -> usize {
62        self.cols
63    }
64
65    /// Returns the number of rows (i.e. of [VecZnxDft]) of the [VmpPMat]
66    fn rows(&self) -> usize {
67        self.rows
68    }
69
70    /// Returns the number of cols of the [VmpPMat].
71    /// The number of cols refers to the number of limbs  
72    /// of each [VecZnxDft].
73    /// This method is equivalent to [Self::limbs].
74    fn cols(&self) -> usize {
75        self.cols
76    }
77}