@@ -126,22 +126,21 @@ cdef class nmod_mpoly_ctx(flint_mpoly_context):
126
126
try :
127
127
return < ulong> other
128
128
except OverflowError :
129
- return < ulong> (other % self .val.mod )
129
+ return < ulong> (other % self .modulus() )
130
130
elif typecheck(other, nmod):
131
- val = < nmod> other
132
- if val.modulus() != self .modulus():
131
+ if (< nmod> other).modulus() != self .modulus():
133
132
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()}"
135
134
)
136
- return val .val
135
+ return ( < nmod > other) .val
137
136
elif typecheck(other, fmpz):
138
137
return fmpz_get_nmod((< fmpz> other).val, self .val.mod)
139
138
elif typecheck(other, fmpz_mod):
140
- if other.ctx.modulus() != self .modulus():
139
+ if ( < fmpz_mod > other) .ctx.modulus() != self .modulus():
141
140
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()}"
143
142
)
144
- return fmpz_get_nmod((< fmpz > other).val, self .val.mod)
143
+ return fmpz_get_nmod((< fmpz_mod > other).val, self .val.mod)
145
144
else :
146
145
return NotImplemented
147
146
@@ -253,23 +252,12 @@ cdef class nmod_mpoly_ctx(flint_mpoly_context):
253
252
continue
254
253
255
254
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 :
271
257
raise TypeError (f" cannot coerce {repr(coeff)} to nmod_mpoly coefficient" )
272
258
259
+ nmod_mpoly_push_term_ui_ffmpz(res.val, coeff_scalar, exp_vec.val, self .val)
260
+
273
261
nmod_mpoly_sort_terms(res.val, self .val)
274
262
return res
275
263
0 commit comments