Skip to content

Commit 805fd34

Browse files
committed
Replace numpy + memoryview with malloc
1 parent e0512bc commit 805fd34

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

src/flint/types/nmod_mpoly.pyx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ from flint.flintlib.ulong_extras cimport n_is_prime
6464

6565
from cpython.object cimport Py_EQ, Py_NE
6666
cimport libc.stdlib
67-
import numpy as np
6867

6968
cdef dict _nmod_mpoly_ctx_cache = {}
7069

@@ -578,8 +577,20 @@ cdef class nmod_mpoly(flint_mpoly):
578577
elif nargs > nvars:
579578
raise ValueError("more arguments provided than variables")
580579

581-
cdef ulong[::1] V = np.asarray(args, dtype=np.uint)
582-
return nmod_mpoly_evaluate_all_ui(self.val, &(V[0]), self.ctx.val)
580+
cdef:
581+
ulong res
582+
ulong *V = <ulong *>libc.stdlib.malloc(len(args) * sizeof(ulong))
583+
if V is NULL:
584+
raise MemoryError("malloc returned a null pointer") # pragma: no cover
585+
586+
try:
587+
for i in range(len(args)):
588+
V[i] = args[i]
589+
res = nmod_mpoly_evaluate_all_ui(self.val, V, self.ctx.val)
590+
finally:
591+
libc.stdlib.free(V)
592+
593+
return res
583594

584595
def iadd(self, other):
585596
"""

0 commit comments

Comments
 (0)