Skip to content

Commit

Permalink
Merge branch 'master' into python-3.11-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
malb committed Oct 13, 2023
2 parents b602cbc + e26f078 commit 7a00929
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 15 deletions.
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ RUN apt update && \

RUN git clone --branch $BRANCH https://github.com/fplll/fpylll && \
cd fpylll && \
pip3 install Cython && \
pip3 install -r requirements.txt && \
pip3 install -r suggestions.txt && \
CFLAGS=$CFLAGS CXXFLAGS=$CXXFLAGS python3 setup.py build -j $JOBS && \
Expand Down
5 changes: 2 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ We indicate active virtualenvs by the prefix ``(fpylll)``.

.. code-block:: bash
$ (fpylll) pip install Cython
$ (fpylll) pip install -r requirements.txt
to install the required Python packages (see above).
Expand Down Expand Up @@ -224,7 +223,6 @@ The instructions are very similar to the manual ones above.

.. code-block:: bash
$ (sage-sh) pip3 install Cython
$ (sage-sh) pip3 install -r requirements.txt
to install the required Python packages (see above).
Expand Down Expand Up @@ -298,7 +296,8 @@ from the top-level directory which runs all tests in ``tests/test_*.py``. We run

$ (fpylll) flake8 --max-line-length=120 --max-complexity=16 --ignore=E22,E241 src

Note that **fpylll** supports Python 2 and 3. In particular, tests are run using Python 2.7 and 3.5. See `.travis.yml <https://github.com/fplll/fpylll/blob/master/.travis.yml>`_ for details on automated testing.
Note that **fpylll** supports Python 3. In particular, tests are run using Python 3.8, 3.9 and 3.10. See `.tests.yml <https://github.com/fplll/fpylll/blob/master/.github/workflows/tests.yml>`_ for details on automated testing.


Attribution & License
---------------------
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Cython
Cython==0.29.36
pytest
cysignals
black
2 changes: 1 addition & 1 deletion src/fpylll/fplll/enumeration.pyx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
include "fpylll/config.pxi"


from cython.operator cimport dereference as deref, preincrement as inc

from libcpp.vector cimport vector
Expand Down
16 changes: 8 additions & 8 deletions src/fpylll/fplll/fplll.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@ cdef extern from "fplll/bkz_param.h" namespace "fplll":

string dump_gso_filename

vector[Strategy] load_strategies_json(const string &filename) nogil except+
vector[Strategy] load_strategies_json(const string &filename) except + nogil
const string default_strategy_path() nogil
const string default_strategy() nogil
const string strategy_full_path(const string &strategy_path) nogil
Expand All @@ -859,19 +859,19 @@ cdef extern from "fplll/bkz.h" namespace "fplll":
int svp_preprocessing(int kappa, int block_size, const BKZParam &param) nogil
int svp_postprocessing(int kappa, int block_size, const vector[FT] &solution) nogil

int svp_reduction(int kappa, int block_size, const BKZParam &param, int dual) nogil except +
int svp_reduction(int kappa, int block_size, const BKZParam &param, int dual) except + nogil

int tour(const int loop, int &kappa_max, const BKZParam &param, int min_row, int max_row) nogil except +
int sd_tour(const int loop, const BKZParam &param, int min_row, int max_row) nogil except +
int slide_tour(const int loop, const BKZParam &param, int min_row, int max_row) nogil except +
int tour(const int loop, int &kappa_max, const BKZParam &param, int min_row, int max_row) except + nogil
int sd_tour(const int loop, const BKZParam &param, int min_row, int max_row) except + nogil
int slide_tour(const int loop, const BKZParam &param, int min_row, int max_row) except + nogil

int hkz(int &kappaMax, const BKZParam &param, int min_row, int max_row) nogil except +
int hkz(int &kappaMax, const BKZParam &param, int min_row, int max_row) except + nogil

int bkz()

void rerandomize_block(int min_row, int max_row, int density) nogil except +
void rerandomize_block(int min_row, int max_row, int density) except + nogil

void dump_gso(const string filename, const string prefix, int append) nogil except +
void dump_gso(const string filename, const string prefix, int append) except + nogil

int status

Expand Down
2 changes: 2 additions & 0 deletions src/fpylll/fplll/integer_matrix.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,8 @@ cdef class IntegerMatrix:
>>> B[0,0]
1
IntegerMatrix also supports numpy's integer types, if numpy is supported.
See tests/test_numpy.py for example usage.
"""
self._type = check_int_type(int_type)

Expand Down
12 changes: 11 additions & 1 deletion src/fpylll/io.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ from cpython.version cimport PY_MAJOR_VERSION
from fplll.fplll cimport FT_DEFAULT, FT_DOUBLE, FT_LONG_DOUBLE, FT_DPE, FT_MPFR
from fplll.fplll cimport ZT_MPZ, ZT_LONG

# Note: this uses fpylll's numpy and not the global numpy package.
IF HAVE_NUMPY:
from .numpy import is_numpy_integer

IF HAVE_QD:
from fpylll.fplll.fplll cimport FT_DD, FT_QD

Expand All @@ -36,7 +40,7 @@ cdef int assign_Z_NR_mpz(Z_NR[mpz_t]& t, value) except -1:
cdef int assign_mpz(mpz_t& t, value) except -1:
"""
Assign Python integer to Z_NR[mpz_t]
"""
"""
if isinstance(value, int) and PY_MAJOR_VERSION == 2:
mpz_set_si(t, PyInt_AS_LONG(value))
return 0
Expand All @@ -49,6 +53,12 @@ cdef int assign_mpz(mpz_t& t, value) except -1:
mpz_set_pylong(t, value)
return 0

IF HAVE_NUMPY:
if is_numpy_integer(value):
value = long(value)
mpz_set_pylong(t, value)
return 0

raise NotImplementedError("Type '%s' not supported"%type(value))

cdef object mpz_get_python(mpz_srcptr z):
Expand Down
9 changes: 9 additions & 0 deletions src/fpylll/numpy.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ IF not HAVE_NUMPY:

import numpy
from numpy.__init__ cimport ndarray # TODO: that __init__ shouldn't be needed
from numpy.__init__ cimport integer as np_integer

def _dump_mu(ndarray[double, ndim=2, mode="c"] mu not None, MatGSO M, int kappa, int block_size):
u"""
Expand Down Expand Up @@ -130,3 +131,11 @@ def dump_r(MatGSO M, int kappa, int block_size):
r = ndarray(dtype='float64', shape=block_size)
_dump_r(r, M, kappa, block_size)
return r

def is_numpy_integer(value):
"""
Return true if value is a numpy integer, false otherwise.
:param value: the value to be checked.
:returns: True if value is a numpy integer, false otherwise.
"""
return isinstance(value, np_integer)
11 changes: 11 additions & 0 deletions tests/test_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,14 @@ def test_dump_r(nrows=10):

for i in range(nrows):
assert abs(M.get_r(i, i) - r[i]) < 0.001


def test_is_numpy_integer(nrows=10):
if not have_numpy:
return

import numpy as np
B = np.eye(nrows, dtype=np.int32)
Bfpy = IntegerMatrix.from_matrix(B)
for i in range(nrows):
assert Bfpy[i][i] == 1

0 comments on commit 7a00929

Please sign in to comment.