diff --git a/README.md b/README.md index 73e556f..c524905 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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 @@ -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 diff --git a/src/dilithium_py/modules/modules_generic.py b/src/dilithium_py/modules/modules_generic.py index d2cd56d..be4f06b 100644 --- a/src/dilithium_py/modules/modules_generic.py +++ b/src/dilithium_py/modules/modules_generic.py @@ -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)] diff --git a/tests/test_module_generic.py b/tests/test_module_generic.py index 4012bda..a5f663a 100644 --- a/tests/test_module_generic.py +++ b/tests/test_module_generic.py @@ -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)