Skip to content

Commit

Permalink
enforce int_type between matrices in MatGSO
Browse files Browse the repository at this point in the history
fixes #101
  • Loading branch information
malb committed Nov 1, 2017
1 parent ba55c6a commit 7c343f3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
30 changes: 25 additions & 5 deletions src/fpylll/fplll/gso.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -115,27 +115,47 @@ cdef class MatGSO:
documentation.
:param float_type: A floating point type, i.e. an element of ``fpylll.fpylll.float_types``.
If ``float_type="mpfr"`` set precision with ``set_precision()`` before constructing this
object and do not change the precision during the lifetime of this object.
Note that matching integer types for ``B``, ``U`` and ``UinvT`` are enforced::
>>> from fpylll import IntegerMatrix, LLL, GSO
>>> B = IntegerMatrix.random(5, 'uniform', bits = 8, int_type = "long")
>>> M = GSO.Mat(B, U = IntegerMatrix.identity(B.nrows))
Traceback (most recent call last):
...
TypeError: U.int_type != B.int_type
>>> from fpylll import IntegerMatrix, LLL, GSO
>>> B = IntegerMatrix.random(5, 'uniform', bits=8, int_type="long")
>>> M = GSO.Mat(B, U = IntegerMatrix.identity(B.nrows, int_type="long"))
.. note:: If ``float_type="mpfr"`` set precision with ``set_precision()`` before
constructing this object and do not change the precision during the lifetime of this
object.
"""

if U is None:
self.U = IntegerMatrix(0, 0)
elif isinstance(U, IntegerMatrix):
if U.nrows != B.nrows:
raise ValueError("U.nrows != B.nrows")
if U.int_type != B.int_type:
raise TypeError("U.int_type != B.int_type")
self.U = U
else:
raise TypeError("type of U (%s) not supported"%type(U))

if UinvT is None:
self.UinvT = IntegerMatrix(0, 0)
elif isinstance(UinvT, IntegerMatrix):
if U is None:
raise ValueError("Uinvt != None but U != None.")
raise ValueError("Uinvt != None but U == None.")
if UinvT.nrows != B.nrows:
raise ValueError("UinvT.nrows != B.nrows")
self.UinvT = UinvT
if UinvT.int_type != B.int_type:
raise TypeError("UinvT.int_type != B.int_type")
else:
raise TypeError("type of UinvT (%s) not supported"%type(UinvT))

cdef Matrix[Z_NR[mpz_t]] *b_m = <Matrix[Z_NR[mpz_t]]*>B._core.mpz
cdef Matrix[Z_NR[mpz_t]] *u_m = <Matrix[Z_NR[mpz_t]]*>self.U._core.mpz
Expand Down Expand Up @@ -737,7 +757,7 @@ cdef class MatGSO:
>>> M.update_gso()
True
>>> M.get_r(1, 0)
890.0
483.0
"""
preprocess_indices(i, j, self.d, self.d)
Expand Down
8 changes: 4 additions & 4 deletions tests/test_gso.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ def test_gso_init():
M = GSO.Mat(copy(A), float_type=float_type)
del M

U = IntegerMatrix(m, m)
U = IntegerMatrix(m, m, int_type=int_type)
M = GSO.Mat(copy(A), U=U, float_type=float_type)
del M

UinvT = IntegerMatrix(m, m)
UinvT = IntegerMatrix(m, m, int_type=int_type)
M = GSO.Mat(copy(A), U=U, UinvT=UinvT, float_type=float_type)
del M

Expand Down Expand Up @@ -53,12 +53,12 @@ def test_gso_int_gram_enabled():
assert M.transform_enabled is False

if m and n:
U = IntegerMatrix(m, m)
U = IntegerMatrix(m, m, int_type=int_type)
M = GSO.Mat(copy(A), U=U, float_type=float_type)
assert M.transform_enabled is True
assert M.inverse_transform_enabled is False

UinvT = IntegerMatrix(m, m)
UinvT = IntegerMatrix(m, m, int_type=int_type)
M = GSO.Mat(copy(A), U=U, UinvT=UinvT, float_type=float_type)
assert M.transform_enabled is True
assert M.inverse_transform_enabled is True
Expand Down

0 comments on commit 7c343f3

Please sign in to comment.