Skip to content

Commit e66a07e

Browse files
committed
Hide any_as_scalar and scalar_as_mpoly functions
1 parent 8b2a3ee commit e66a07e

File tree

5 files changed

+47
-47
lines changed

5 files changed

+47
-47
lines changed

src/flint/flint_base/flint_base.pyx

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -379,10 +379,10 @@ cdef class flint_mpoly_context(flint_elem):
379379
nametup=ctx.names()
380380
)
381381

382-
def any_as_scalar(self, other):
382+
def _any_as_scalar(self, other):
383383
raise NotImplementedError("abstract method")
384384

385-
def scalar_as_mpoly(self, other):
385+
def _scalar_as_mpoly(self, other):
386386
raise NotImplementedError("abstract method")
387387

388388
def compatible_context_check(self, other):
@@ -505,7 +505,7 @@ cdef class flint_mpoly(flint_elem):
505505
self.context().compatible_context_check(other.context())
506506
return self._add_mpoly_(other)
507507

508-
other = self.context().any_as_scalar(other)
508+
other = self.context()._any_as_scalar(other)
509509
if other is NotImplemented:
510510
return NotImplemented
511511

@@ -516,7 +516,7 @@ cdef class flint_mpoly(flint_elem):
516516
self.context().compatible_context_check(other.context())
517517
return self._add_mpoly_(other)
518518

519-
other = self.context().any_as_scalar(other)
519+
other = self.context()._any_as_scalar(other)
520520
if other is NotImplemented:
521521
return NotImplemented
522522

@@ -527,7 +527,7 @@ cdef class flint_mpoly(flint_elem):
527527
self.context().compatible_context_check(other.context())
528528
return self._sub_mpoly_(other)
529529

530-
other = self.context().any_as_scalar(other)
530+
other = self.context()._any_as_scalar(other)
531531
if other is NotImplemented:
532532
return NotImplemented
533533

@@ -538,7 +538,7 @@ cdef class flint_mpoly(flint_elem):
538538
self.context().compatible_context_check(other.context())
539539
return self._rsub_mpoly_(other)
540540

541-
other = self.context().any_as_scalar(other)
541+
other = self.context()._any_as_scalar(other)
542542
if other is NotImplemented:
543543
return NotImplemented
544544

@@ -549,7 +549,7 @@ cdef class flint_mpoly(flint_elem):
549549
self.context().compatible_context_check(other.context())
550550
return self._mul_mpoly_(other)
551551

552-
other = self.context().any_as_scalar(other)
552+
other = self.context()._any_as_scalar(other)
553553
if other is NotImplemented:
554554
return NotImplemented
555555

@@ -560,7 +560,7 @@ cdef class flint_mpoly(flint_elem):
560560
self.context().compatible_context_check(other.context())
561561
return self._mul_mpoly_(other)
562562

563-
other = self.context().any_as_scalar(other)
563+
other = self.context()._any_as_scalar(other)
564564
if other is NotImplemented:
565565
return NotImplemented
566566

@@ -586,20 +586,20 @@ cdef class flint_mpoly(flint_elem):
586586
self._division_check(other)
587587
return self._divmod_mpoly_(other)
588588

589-
other = self.context().any_as_scalar(other)
589+
other = self.context()._any_as_scalar(other)
590590
if other is NotImplemented:
591591
return NotImplemented
592592

593-
other = self.context().scalar_as_mpoly(other)
593+
other = self.context()._scalar_as_mpoly(other)
594594
self._division_check(other)
595595
return self._divmod_mpoly_(other)
596596

597597
def __rdivmod__(self, other):
598-
other = self.context().any_as_scalar(other)
598+
other = self.context()._any_as_scalar(other)
599599
if other is NotImplemented:
600600
return NotImplemented
601601

602-
other = self.context().scalar_as_mpoly(other)
602+
other = self.context()._scalar_as_mpoly(other)
603603
other._division_check(self)
604604
return self._rdivmod_mpoly_(other)
605605

@@ -609,7 +609,7 @@ cdef class flint_mpoly(flint_elem):
609609
self._division_check(other)
610610
return self._truediv_mpoly_(other)
611611

612-
other = self.context().any_as_scalar(other)
612+
other = self.context()._any_as_scalar(other)
613613
if other is NotImplemented:
614614
return NotImplemented
615615

@@ -618,15 +618,15 @@ cdef class flint_mpoly(flint_elem):
618618
if res is not NotImplemented:
619619
return res
620620

621-
other = self.context().scalar_as_mpoly(other)
621+
other = self.context()._scalar_as_mpoly(other)
622622
return self._truediv_mpoly_(other)
623623

624624
def __rtruediv__(self, other):
625-
other = self.context().any_as_scalar(other)
625+
other = self.context()._any_as_scalar(other)
626626
if other is NotImplemented:
627627
return NotImplemented
628628

629-
other = self.context().scalar_as_mpoly(other)
629+
other = self.context()._scalar_as_mpoly(other)
630630
other._division_check(self)
631631
return self._rtruediv_mpoly_(other)
632632

@@ -636,20 +636,20 @@ cdef class flint_mpoly(flint_elem):
636636
self._division_check(other)
637637
return self._floordiv_mpoly_(other)
638638

639-
other = self.context().any_as_scalar(other)
639+
other = self.context()._any_as_scalar(other)
640640
if other is NotImplemented:
641641
return NotImplemented
642642

643-
other = self.context().scalar_as_mpoly(other)
643+
other = self.context()._scalar_as_mpoly(other)
644644
self._division_check(other)
645645
return self._floordiv_mpoly_(other)
646646

647647
def __rfloordiv__(self, other):
648-
other = self.context().any_as_scalar(other)
648+
other = self.context()._any_as_scalar(other)
649649
if other is NotImplemented:
650650
return NotImplemented
651651

652-
other = self.context().scalar_as_mpoly(other)
652+
other = self.context()._scalar_as_mpoly(other)
653653
other._division_check(self)
654654
return self._rfloordiv_mpoly_(other)
655655

@@ -659,20 +659,20 @@ cdef class flint_mpoly(flint_elem):
659659
self._division_check(other)
660660
return self._mod_mpoly_(other)
661661

662-
other = self.context().any_as_scalar(other)
662+
other = self.context()._any_as_scalar(other)
663663
if other is NotImplemented:
664664
return NotImplemented
665665

666-
other = self.context().scalar_as_mpoly(other)
666+
other = self.context()._scalar_as_mpoly(other)
667667
self._division_check(other)
668668
return self._mod_mpoly_(other)
669669

670670
def __rmod__(self, other):
671-
other = self.context().any_as_scalar(other)
671+
other = self.context()._any_as_scalar(other)
672672
if other is NotImplemented:
673673
return NotImplemented
674674

675-
other = self.context().scalar_as_mpoly(other)
675+
other = self.context()._scalar_as_mpoly(other)
676676
other._division_check(self)
677677
return self._rmod_mpoly_(other)
678678

@@ -695,7 +695,7 @@ cdef class flint_mpoly(flint_elem):
695695
self._iadd_mpoly_(other)
696696
return
697697

698-
other_scalar = self.context().any_as_scalar(other)
698+
other_scalar = self.context()._any_as_scalar(other)
699699
if other_scalar is NotImplemented:
700700
raise NotImplementedError(f"cannot add {type(self)} and {type(other)}")
701701

@@ -720,7 +720,7 @@ cdef class flint_mpoly(flint_elem):
720720
self._isub_mpoly_(other)
721721
return
722722

723-
other_scalar = self.context().any_as_scalar(other)
723+
other_scalar = self.context()._any_as_scalar(other)
724724
if other_scalar is NotImplemented:
725725
raise NotImplementedError(f"cannot subtract {type(self)} and {type(other)}")
726726

@@ -745,7 +745,7 @@ cdef class flint_mpoly(flint_elem):
745745
self._imul_mpoly_(other)
746746
return
747747

748-
other_scalar = self.context().any_as_scalar(other)
748+
other_scalar = self.context()._any_as_scalar(other)
749749
if other_scalar is NotImplemented:
750750
raise NotImplementedError(f"cannot multiply {type(self)} and {type(other)}")
751751

src/flint/types/fmpq_mpoly.pyx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ cdef class fmpq_mpoly_ctx(flint_mpoly_context):
102102
fmpq_mpoly_ctx_init(self.val, nvars, ordering_py_to_c(ordering))
103103
super().__init__(nvars, names)
104104

105-
def any_as_scalar(self, other):
105+
def _any_as_scalar(self, other):
106106
if isinstance(other, int):
107107
return any_as_fmpq(other)
108108
elif typecheck(other, fmpz):
@@ -114,8 +114,8 @@ cdef class fmpq_mpoly_ctx(flint_mpoly_context):
114114
else:
115115
return NotImplemented
116116

117-
def scalar_as_mpoly(self, other: fmpq):
118-
# non-fmpq scalars should first be converted via self.any_as_scalar
117+
def _scalar_as_mpoly(self, other: fmpq):
118+
# non-fmpq scalars should first be converted via self._any_as_scalar
119119
return self.constant(<fmpq>other)
120120

121121
def nvars(self):

src/flint/types/fmpz_mod_mpoly.pyx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ cdef class fmpz_mod_mpoly_ctx(flint_mpoly_context):
133133
raise ValueError("must provide either 'names' or 'nametup'")
134134
return key
135135

136-
def any_as_scalar(self, other):
136+
def _any_as_scalar(self, other):
137137
if isinstance(other, int):
138138
return any_as_fmpz(other)
139139
elif typecheck(other, nmod):
@@ -157,8 +157,8 @@ cdef class fmpz_mod_mpoly_ctx(flint_mpoly_context):
157157
else:
158158
return NotImplemented
159159

160-
def scalar_as_mpoly(self, other: fmpz):
161-
# non-fmpz scalars should first be converted via self.any_as_scalar
160+
def _scalar_as_mpoly(self, other: fmpz):
161+
# non-fmpz scalars should first be converted via self._any_as_scalar
162162
return self.constant(<fmpz>other)
163163

164164
def nvars(self):
@@ -270,7 +270,7 @@ cdef class fmpz_mod_mpoly_ctx(flint_mpoly_context):
270270
continue
271271

272272
exp_vec = fmpz_vec(exps)
273-
coeff_scalar = self.any_as_scalar(coeff)
273+
coeff_scalar = self._any_as_scalar(coeff)
274274
if coeff_scalar is NotImplemented:
275275
raise TypeError(f"cannot coerce {repr(coeff)} to nmod_mpoly coefficient")
276276

@@ -425,7 +425,7 @@ cdef class fmpz_mod_mpoly(flint_mpoly):
425425
raise ValueError("exponent vector provided does not match number of variables")
426426
exp_vec = fmpz_vec(x, double_indirect=True)
427427

428-
coeff = self.ctx.any_as_scalar(y)
428+
coeff = self.ctx._any_as_scalar(y)
429429
if coeff is NotImplemented:
430430
raise TypeError("provided coefficient not coercible to fmpz")
431431
fmpz_mod_mpoly_set_coeff_fmpz_fmpz(self.val, (<fmpz>coeff).val, exp_vec.double_indirect, self.ctx.val)
@@ -566,7 +566,7 @@ cdef class fmpz_mod_mpoly(flint_mpoly):
566566

567567
if nargs != nvars:
568568
raise ValueError("number of generators does not match number of arguments")
569-
args = [self.ctx.any_as_scalar(x) for x in args]
569+
args = [self.ctx._any_as_scalar(x) for x in args]
570570
V = fmpz_vec(args, double_indirect=True)
571571
vres = fmpz.__new__(fmpz)
572572
fmpz_mod_mpoly_evaluate_all_fmpz(vres.val, self.val, V.double_indirect, self.ctx.val)
@@ -656,7 +656,7 @@ cdef class fmpz_mod_mpoly(flint_mpoly):
656656
fmpz_mod_mpoly res
657657
slong i
658658

659-
args = tuple((self.ctx.variable_to_index(k), self.ctx.any_as_scalar(v)) for k, v in dict_args.items())
659+
args = tuple((self.ctx.variable_to_index(k), self.ctx._any_as_scalar(v)) for k, v in dict_args.items())
660660
for (_, v), old in zip(args, dict_args.values()):
661661
if v is NotImplemented:
662662
raise TypeError(f"cannot coerce {type(old)} to fmpz")

src/flint/types/fmpz_mpoly.pyx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ cdef class fmpz_mpoly_ctx(flint_mpoly_context):
106106
fmpz_mpoly_ctx_init(self.val, nvars, ordering_py_to_c(ordering))
107107
super().__init__(nvars, names)
108108

109-
def any_as_scalar(self, other):
109+
def _any_as_scalar(self, other):
110110
if isinstance(other, int):
111111
return any_as_fmpz(other)
112112
elif typecheck(other, fmpz):
@@ -116,8 +116,8 @@ cdef class fmpz_mpoly_ctx(flint_mpoly_context):
116116
else:
117117
return NotImplemented
118118

119-
def scalar_as_mpoly(self, other: fmpz):
120-
# non-fmpz scalars should first be converted via self.any_as_scalar
119+
def _scalar_as_mpoly(self, other: fmpz):
120+
# non-fmpz scalars should first be converted via self._any_as_scalar
121121
return self.constant(<fmpz>other)
122122

123123
def nvars(self):

src/flint/types/nmod_mpoly.pyx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ cdef class nmod_mpoly_ctx(flint_mpoly_context):
128128
raise ValueError("must provide either 'names' or 'nametup'")
129129
return key
130130

131-
def any_as_scalar(self, other):
131+
def _any_as_scalar(self, other):
132132
if isinstance(other, int):
133133
try:
134134
return <ulong>other
@@ -151,8 +151,8 @@ cdef class nmod_mpoly_ctx(flint_mpoly_context):
151151
else:
152152
return NotImplemented
153153

154-
def scalar_as_mpoly(self, other: ulong):
155-
# non-ulong scalars should first be converted via self.any_as_scalar
154+
def _scalar_as_mpoly(self, other: ulong):
155+
# non-ulong scalars should first be converted via self._any_as_scalar
156156
return self.constant(<ulong>other)
157157

158158
def nvars(self):
@@ -259,7 +259,7 @@ cdef class nmod_mpoly_ctx(flint_mpoly_context):
259259
continue
260260

261261
exp_vec = fmpz_vec(exps)
262-
coeff_scalar = self.any_as_scalar(coeff)
262+
coeff_scalar = self._any_as_scalar(coeff)
263263
if coeff_scalar is NotImplemented:
264264
raise TypeError(f"cannot coerce {repr(coeff)} to nmod_mpoly coefficient")
265265

@@ -402,7 +402,7 @@ cdef class nmod_mpoly(flint_mpoly):
402402

403403
exp_vec = fmpz_vec(x, double_indirect=True)
404404

405-
coeff = self.ctx.any_as_scalar(y)
405+
coeff = self.ctx._any_as_scalar(y)
406406
if coeff is NotImplemented:
407407
raise TypeError("provided coefficient not coercible to ulong")
408408
nmod_mpoly_set_coeff_ui_fmpz(self.val, coeff, exp_vec.double_indirect, self.ctx.val)
@@ -542,7 +542,7 @@ cdef class nmod_mpoly(flint_mpoly):
542542
if nargs != nvars:
543543
raise ValueError("number of generators does not match number of arguments")
544544

545-
args = [self.ctx.any_as_scalar(x) for x in args]
545+
args = [self.ctx._any_as_scalar(x) for x in args]
546546
cdef:
547547
# Using sizeof(ulong) here breaks on 64 windows machines because of the ``ctypedef unsigned long ulong`` in
548548
# flintlib/flint.pxd. Cython will inline this definition and then allocate the wrong amount of memory.
@@ -634,7 +634,7 @@ cdef class nmod_mpoly(flint_mpoly):
634634
nmod_mpoly res
635635
slong i
636636

637-
args = tuple((self.ctx.variable_to_index(k), self.ctx.any_as_scalar(v)) for k, v in dict_args.items())
637+
args = tuple((self.ctx.variable_to_index(k), self.ctx._any_as_scalar(v)) for k, v in dict_args.items())
638638
for (_, v), old in zip(args, dict_args.values()):
639639
if v is NotImplemented:
640640
raise TypeError(f"cannot coerce {type(old)} to ulong")

0 commit comments

Comments
 (0)