fplll / fpylll

A Python interface for https://github.com/fplll/fplll
GNU General Public License v2.0
123 stars 62 forks source link

IntegerMatrix.from_matrix does not support numpy arrays #251

Closed verdiverdiverdi closed 1 year ago

verdiverdiverdi commented 1 year ago
import numpy as np
from fpylll import IntegerMatrix
B = np.eye(5)
Bfpy = IntegerMatrix.from_matrix(B)

gives

NotImplementedError: Type '<class 'numpy.float64'>' not supported

that ultimately comes from set_matrix calling _set (here) which calls assign_mpz (here).

This is not the end of the world, as one can do double list comprehension and cast to a python int -- but it would be nice if from_matrix supported numpy arrays natively.

malb commented 1 year ago

It's not quite clear to me what should happen here. Would we just round?

verdiverdiverdi commented 1 year ago

Apologies, I meant e.g.

import numpy as np
from fpylll import IntegerMatrix
B = np.eye(5, dtype=np.int32)
Bfpy = IntegerMatrix.from_matrix(B)

which gives

NotImplementedError: Type '<class 'numpy.int32'>' not supported

which seems true for all integer types numpy understands.

verdiverdiverdi commented 1 year ago

I guess the solution is just to do this casting to a python integer "behind the scenes" in these cases?

malb commented 1 year ago

Yup, I agree with that. Shouldn't be too hard to add.