Skip to content

Commit 4526d2b

Browse files
author
Jake Moss
committed
Simplify call argument checks
1 parent 72e220e commit 4526d2b

File tree

4 files changed

+11
-35
lines changed

4 files changed

+11
-35
lines changed

src/flint/types/fmpq_mpoly.pyx

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -542,17 +542,10 @@ cdef class fmpq_mpoly(flint_mpoly):
542542
fmpq vres
543543
slong nvars = self.ctx.nvars(), nargs = len(args)
544544

545-
if nargs < nvars:
546-
raise ValueError("not enough arguments provided")
547-
elif nargs > nvars:
548-
raise ValueError("more arguments provided than variables")
549-
550-
args_fmpq = tuple(any_as_fmpq(v) for v in args)
551-
for arg in args_fmpq:
552-
if arg is NotImplemented:
553-
raise TypeError(f"cannot coerce argument ('{arg}') to fmpq")
545+
if nargs != nvars:
546+
raise ValueError("number of generators does not match number of arguments")
554547

555-
V = fmpq_vec(args_fmpq, double_indirect=True)
548+
V = fmpq_vec(args, double_indirect=True)
556549
vres = fmpq.__new__(fmpq)
557550
if fmpq_mpoly_evaluate_all_fmpq(vres.val, self.val, V.double_indirect, self.ctx.val) == 0:
558551
raise ValueError("unreasonably large polynomial") # pragma: no cover

src/flint/types/fmpz_mod_mpoly.pyx

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -605,17 +605,10 @@ cdef class fmpz_mod_mpoly(flint_mpoly):
605605
fmpz vres
606606
slong nvars = self.ctx.nvars(), nargs = len(args)
607607

608-
if nargs < nvars:
609-
raise ValueError("not enough arguments provided")
610-
elif nargs > nvars:
611-
raise ValueError("more arguments provided than variables")
612-
613-
args_fmpz = tuple(any_as_fmpz(v) for v in args)
614-
for arg in args_fmpz:
615-
if arg is NotImplemented:
616-
raise TypeError(f"cannot coerce argument ('{arg}') to fmpz")
608+
if nargs != nvars:
609+
raise ValueError("number of generators does not match number of arguments") # TODO: fix for all of them
617610

618-
V = fmpz_vec(args_fmpz, double_indirect=True)
611+
V = fmpz_vec(args, double_indirect=True)
619612
vres = fmpz.__new__(fmpz)
620613
fmpz_mod_mpoly_evaluate_all_fmpz(vres.val, self.val, V.double_indirect, self.ctx.val)
621614
return vres

src/flint/types/fmpz_mpoly.pyx

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -520,17 +520,10 @@ cdef class fmpz_mpoly(flint_mpoly):
520520
fmpz vres
521521
slong nvars = self.ctx.nvars(), nargs = len(args)
522522

523-
if nargs < nvars:
524-
raise ValueError("not enough arguments provided")
525-
elif nargs > nvars:
526-
raise ValueError("more arguments provided than variables")
527-
528-
args_fmpz = tuple(any_as_fmpz(v) for v in args)
529-
for arg in args_fmpz:
530-
if arg is NotImplemented:
531-
raise TypeError(f"cannot coerce argument ('{arg}') to fmpz")
523+
if nargs != nvars:
524+
raise ValueError("number of generators does not match number of arguments")
532525

533-
V = fmpz_vec(args_fmpz, double_indirect=True)
526+
V = fmpz_vec(args, double_indirect=True)
534527
vres = fmpz.__new__(fmpz)
535528
if fmpz_mpoly_evaluate_all_fmpz(vres.val, self.val, V.double_indirect, self.ctx.val) == 0:
536529
raise ValueError("unreasonably large polynomial") # pragma: no cover

src/flint/types/nmod_mpoly.pyx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -686,13 +686,10 @@ cdef class nmod_mpoly(flint_mpoly):
686686
cdef:
687687
slong nvars = self.ctx.nvars(), nargs = len(args)
688688

689-
if nargs < nvars:
690-
raise ValueError("not enough arguments provided")
691-
elif nargs > nvars:
692-
raise ValueError("more arguments provided than variables")
689+
if nargs != nvars:
690+
raise ValueError("number of generators does not match number of arguments")
693691

694692
args = [int(x) for x in args]
695-
696693
cdef:
697694
# Using sizeof(ulong) here breaks on 64 windows machines because of the `ctypedef unsigned long ulong` in
698695
# flintlib/flint.pxd. Cython will inline this definition and then allocate the wrong amount of memory.

0 commit comments

Comments
 (0)