Skip to content

Commit f224a6f

Browse files
committed
prefer the use of .rows() instead of accessing data in _data
1 parent 8bab6bc commit f224a6f

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/dilithium_py/modules/modules.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def decompose(self, alpha):
5454
)
5555

5656
def __bit_pack(self, algorithm, *args):
57-
return b"".join(algorithm(poly, *args) for row in self._data for poly in row)
57+
return b"".join(algorithm(poly, *args) for row in self.rows() for poly in row)
5858

5959
def bit_pack_t1(self):
6060
algorithm = self.parent.ring.element.bit_pack_t1
@@ -81,24 +81,24 @@ def to_ntt(self):
8181
Convert every element of the matrix into NTT form
8282
"""
8383
data = [[x.to_ntt() for x in row] for row in self._data]
84-
return self.parent(data, transpose=self._transpose)
84+
return self.parent(data, self._transpose)
8585

8686
def from_ntt(self):
8787
"""
8888
Convert every element of the matrix from NTT form
8989
"""
9090
data = [[x.from_ntt() for x in row] for row in self._data]
91-
return self.parent(data, transpose=self._transpose)
91+
return self.parent(data, self._transpose)
9292

9393
def high_bits(self, alpha, is_ntt=False):
9494
matrix = [
95-
[ele.high_bits(alpha, is_ntt=is_ntt) for ele in row] for row in self._data
95+
[ele.high_bits(alpha, is_ntt=is_ntt) for ele in row] for row in self.rows()
9696
]
9797
return self.parent(matrix)
9898

9999
def low_bits(self, alpha, is_ntt=False):
100100
matrix = [
101-
[ele.low_bits(alpha, is_ntt=is_ntt) for ele in row] for row in self._data
101+
[ele.low_bits(alpha, is_ntt=is_ntt) for ele in row] for row in self.rows()
102102
]
103103
return self.parent(matrix)
104104

@@ -109,7 +109,7 @@ def make_hint(self, other, alpha):
109109
"""
110110
matrix = [
111111
[p.make_hint(q, alpha) for p, q in zip(r1, r2)]
112-
for r1, r2 in zip(self._data, other._data)
112+
for r1, r2 in zip(self.rows(), other.rows())
113113
]
114114
return self.parent(matrix)
115115

@@ -120,7 +120,7 @@ def make_hint_optimised(self, other, alpha):
120120
"""
121121
matrix = [
122122
[p.make_hint_optimised(q, alpha) for p, q in zip(r1, r2)]
123-
for r1, r2 in zip(self._data, other._data)
123+
for r1, r2 in zip(self.rows(), other.rows())
124124
]
125125
return self.parent(matrix)
126126

@@ -140,7 +140,7 @@ def sum_hint(self):
140140
Helper function to count the number of coeffs == 1
141141
in all the polynomials of a matrix
142142
"""
143-
return sum(c for row in self._data for p in row for c in p)
143+
return sum(c for row in self.rows() for p in row for c in p)
144144

145145

146146
class Vector(Matrix):

src/dilithium_py/modules/modules_generic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def __neg__(self):
8282
m, n = self.dim()
8383
return self.parent(
8484
[[-self[i, j] for j in range(n)] for i in range(m)],
85-
self._transpose,
85+
False,
8686
)
8787

8888
def __add__(self, other):

0 commit comments

Comments
 (0)