@@ -126,22 +126,21 @@ cdef class nmod_mpoly_ctx(flint_mpoly_context):
126126 try :
127127 return < ulong> other
128128 except OverflowError :
129- return < ulong> (other % self .val.mod )
129+ return < ulong> (other % self .modulus() )
130130 elif typecheck(other, nmod):
131- val = < nmod> other
132- if val.modulus() != self .modulus():
131+ if (< nmod> other).modulus() != self .modulus():
133132 raise DomainError(
134- f" modulus does not match, got {val .modulus()}, expected {self.modulus()}"
133+ f" modulus does not match, got {(<nmod>other) .modulus()}, expected {self.modulus()}"
135134 )
136- return val .val
135+ return ( < nmod > other) .val
137136 elif typecheck(other, fmpz):
138137 return fmpz_get_nmod((< fmpz> other).val, self .val.mod)
139138 elif typecheck(other, fmpz_mod):
140- if other.ctx.modulus() != self .modulus():
139+ if ( < fmpz_mod > other) .ctx.modulus() != self .modulus():
141140 raise DomainError(
142- f" modulus does not match, got {other.ctx.modulus()}, expected {self.modulus()}"
141+ f" modulus does not match, got {(<fmpz_mod> other) .ctx.modulus()}, expected {self.modulus()}"
143142 )
144- return fmpz_get_nmod((< fmpz > other).val, self .val.mod)
143+ return fmpz_get_nmod((< fmpz_mod > other).val, self .val.mod)
145144 else :
146145 return NotImplemented
147146
@@ -253,23 +252,12 @@ cdef class nmod_mpoly_ctx(flint_mpoly_context):
253252 continue
254253
255254 exp_vec = fmpz_vec(exps)
256-
257- if isinstance (coeff, int ) or typecheck(coeff, fmpz):
258- coeff_fmpz = any_as_fmpz(coeff)
259- if coeff_fmpz is NotImplemented :
260- raise TypeError (f" cannot coerce '{repr(coeff)}' to fmpz" )
261-
262- nmod_mpoly_push_term_ui_ffmpz(
263- res.val,
264- fmpz_get_nmod((< fmpz> coeff_fmpz).val, self .val.mod),
265- exp_vec.val,
266- self .val
267- )
268- elif typecheck(coeff, nmod):
269- nmod_mpoly_push_term_ui_ffmpz(res.val, int (coeff), exp_vec.val, self .val)
270- else :
255+ coeff_scalar = self .any_as_scalar(coeff)
256+ if coeff_scalar is NotImplemented :
271257 raise TypeError (f" cannot coerce {repr(coeff)} to nmod_mpoly coefficient" )
272258
259+ nmod_mpoly_push_term_ui_ffmpz(res.val, coeff_scalar, exp_vec.val, self .val)
260+
273261 nmod_mpoly_sort_terms(res.val, self .val)
274262 return res
275263
0 commit comments