Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,8 @@ pass.)
### Polynomials

The file [`polynomials.py`](src/dilithium_py/polynomials/polynomials_generic.py) contains the classes
`GenericPolynomialRing` and
`GenericPolynomial`. This implements the univariate polynomial ring
`PolynomialRingGeneric` and
`PolynomialGeneric`. This implements the univariate polynomial ring

$$
R_q = \mathbb{F}_q[X] /(X^n + 1)
Expand All @@ -348,7 +348,7 @@ ring $R_{11} = \mathbb{F}_{11}[X] /(X^8 + 1)$ in the following way:
#### Example

```python
>>> R = GenericPolynomialRing(11, 8)
>>> R = PolynomialRingGeneric(11, 8)
>>> x = R.gen()
>>> f = 3*x**3 + 4*x**7
>>> g = R.random_element(); g
Expand All @@ -363,25 +363,25 @@ ring $R_{11} = \mathbb{F}_{11}[X] /(X^8 + 1)$ in the following way:

### Modules

The file [`modules.py`](src/dilithium_py/modules/modules_generic.py) contains the classes `GenericModule` and `GenericMatrix`.
The file [`modules.py`](src/dilithium_py/modules/modules_generic.py) contains the classes `ModuleGeneric` and `MatrixGeneric`.
A module is a generalisation of a vector space, where the field
of scalars is replaced with a ring. In the case of Dilithium, we
need the module with the ring $R_q$ as described above.

`GenericMatrix` allows elements of the module to be of size $m \times n$
`MatrixGeneric` allows elements of the module to be of size $m \times n$
For Dilithium, we need vectors of length $k$ and $l$ and a matrix
of size $l \times k$.

As an example of the operations we can perform with out `GenericModule`
As an example of the operations we can perform with out `ModuleGeneric`
lets revisit the ring from the previous example:

#### Example

```python
>>> R = GenericPolynomialRing(11, 8)
>>> R = PolynomialRingGeneric(11, 8)
>>> x = R.gen()
>>>
>>> M = GenericModule(R)
>>> M = ModuleGeneric(R)
>>> # We create a matrix by feeding the coefficients to M
>>> A = M([[x + 3*x**2, 4 + 3*x**7], [3*x**3 + 9*x**7, x**4]])
>>> A
Expand Down
2 changes: 1 addition & 1 deletion src/dilithium_py/modules/modules_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def dot(self, other):
def __repr__(self):
m, n = self.dim()

if m == 1:
if m == 1 and n == 1:
return str(self._data[0])

max_col_width = [max(len(str(self[i, j])) for i in range(m)) for j in range(n)]
Expand Down
8 changes: 8 additions & 0 deletions tests/test_module_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,11 @@ def test_print(self):
su = "[1 + 2*x, 3 + 4*x + 5*x^2 + 6*x^3]"
self.assertEqual(str(A), sA)
self.assertEqual(str(u), su)

A = self.M([self.R(1), self.R(2), self.R(3)])
sA = "[1, 2, 3]"
self.assertEqual(str(A), sA)

A = self.M([[self.R(1)], [self.R(2)], [self.R(3)]])
sA = "[1]\n[2]\n[3]"
self.assertEqual(str(A), sA)