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 columns of the receiver.
11    /// This method is equivalent to [Infos::limbs].
12    fn cols(&self) -> usize;
13
14    /// Returns the number of rows of the receiver.
15    fn rows(&self) -> usize;
16}
17
18impl Infos for VecZnx {
19    /// Returns the base 2 logarithm of the [VecZnx] degree.
20    fn log_n(&self) -> usize {
21        (usize::BITS - (self.n - 1).leading_zeros()) as _
22    }
23
24    /// Returns the [VecZnx] degree.
25    fn n(&self) -> usize {
26        self.n
27    }
28
29    /// Returns the number of limbs of the [VecZnx].
30    fn cols(&self) -> usize {
31        self.data.len() / self.n
32    }
33
34    /// Returns the number of limbs of the [VecZnx].
35    fn rows(&self) -> usize {
36        1
37    }
38}
39
40impl Infos for VecZnxBorrow {
41    /// Returns the base 2 logarithm of the [VecZnx] degree.
42    fn log_n(&self) -> usize {
43        (usize::BITS - (self.n - 1).leading_zeros()) as _
44    }
45
46    /// Returns the [VecZnx] degree.
47    fn n(&self) -> usize {
48        self.n
49    }
50
51    /// Returns the number of limbs of the [VecZnx].
52    fn cols(&self) -> usize {
53        self.limbs
54    }
55
56    /// Returns the number of limbs of the [VecZnx].
57    fn rows(&self) -> usize {
58        1
59    }
60}
61
62impl Infos for VmpPMat {
63    /// Returns the ring dimension of the [VmpPMat].
64    fn n(&self) -> usize {
65        self.n
66    }
67
68    fn log_n(&self) -> usize {
69        (usize::BITS - (self.n() - 1).leading_zeros()) as _
70    }
71
72    /// Returns the number of rows (i.e. of [VecZnxDft]) of the [VmpPMat]
73    fn rows(&self) -> usize {
74        self.rows
75    }
76
77    /// Returns the number of cols of the [VmpPMat].
78    /// The number of cols refers to the number of limbs  
79    /// of each [VecZnxDft].
80    /// This method is equivalent to [Self::limbs].
81    fn cols(&self) -> usize {
82        self.cols
83    }
84}