Skip to content

Commit ea62e79

Browse files
committed
Rename get_context -> get
1 parent 764a026 commit ea62e79

File tree

6 files changed

+167
-172
lines changed

6 files changed

+167
-172
lines changed

src/flint/flint_base/flint_base.pyx

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ cdef class flint_mpoly_context(flint_elem):
354354
"""
355355
res: list[str] = []
356356

357-
# Provide a convenience method to avoid having to pass a nested tuple
357+
# To avoid having to pass a nested tuple we allow a tuple[str, int]
358358
if len(names) == 2 and isinstance(names[0], str) and isinstance(names[1], int):
359359
names = (names,)
360360

@@ -378,15 +378,10 @@ cdef class flint_mpoly_context(flint_elem):
378378
"""
379379
Create a key for the context cache via the variable names and the ordering.
380380
"""
381-
# A type hint of ``ordering: Ordering`` results in the error "TypeError: an integer is required" if a Ordering
382-
# object is not provided. This is pretty obtuse so we check its type ourselves
383-
# if not isinstance(ordering, Ordering):
384-
# raise TypeError(f"'ordering' ('{ordering}') is not an instance of flint.Ordering")
385-
386381
return cls.create_variable_names(names), Ordering(ordering) if not isinstance(ordering, Ordering) else ordering
387382

388383
@classmethod
389-
def get_context(cls, *args, **kwargs):
384+
def get(cls, *args, **kwargs):
390385
"""
391386
Retrieve or create a context via generator names, ``names`` and the ordering, ``ordering``.
392387
@@ -401,7 +396,7 @@ cdef class flint_mpoly_context(flint_elem):
401396

402397
@classmethod
403398
def from_context(cls, ctx: flint_mpoly_context):
404-
return cls.get_context(
399+
return cls.get(
405400
ordering=ctx.ordering(),
406401
names=ctx.names(),
407402
)
@@ -424,7 +419,7 @@ cdef class flint_mpoly_context(flint_elem):
424419
to ``1``. ``exp_vec``` defaults to ``(0,) * self.nvars()```.
425420
426421
>>> from flint import fmpz_mpoly_ctx, Ordering
427-
>>> ctx = fmpz_mpoly_ctx.get_context(('x', 2), 'lex')
422+
>>> ctx = fmpz_mpoly_ctx.get(('x', 2), 'lex')
428423
>>> ctx.term(coeff=5, exp_vec=(2, 3))
429424
5*x0^2*x1^3
430425
>>> ctx.term()
@@ -455,7 +450,7 @@ cdef class flint_mod_mpoly_context(flint_mpoly_context):
455450

456451
@classmethod
457452
def from_context(cls, ctx: flint_mod_mpoly_context):
458-
return cls.get_context(
453+
return cls.get(
459454
names=ctx.names(),
460455
modulus=ctx.modulus(),
461456
ordering=ctx.ordering(),
@@ -466,10 +461,10 @@ cdef class flint_mod_mpoly_context(flint_mpoly_context):
466461
Return whether the modulus is prime
467462
468463
>>> from flint import fmpz_mod_mpoly_ctx
469-
>>> ctx = fmpz_mod_mpoly_ctx.get_context(('z',), 2**127, 'degrevlex')
464+
>>> ctx = fmpz_mod_mpoly_ctx.get(('z',), 2**127, 'degrevlex')
470465
>>> ctx.is_prime()
471466
False
472-
>>> ctx = fmpz_mod_mpoly_ctx.get_context(('z',), 2**127 - 1, 'degrevlex')
467+
>>> ctx = fmpz_mod_mpoly_ctx.get(('z',), 2**127 - 1, 'degrevlex')
473468
>>> ctx.is_prime()
474469
True
475470
"""
@@ -747,7 +742,7 @@ cdef class flint_mpoly(flint_elem):
747742
In-place addition, mutates self.
748743
749744
>>> from flint import fmpz_mpoly_ctx
750-
>>> ctx = fmpz_mpoly_ctx.get_context(('x', 2), 'lex')
745+
>>> ctx = fmpz_mpoly_ctx.get(('x', 2), 'lex')
751746
>>> f = ctx.from_dict({(1, 0): 2, (0, 1): 3, (1, 1): 4})
752747
>>> f
753748
4*x0*x1 + 2*x0 + 3*x1
@@ -772,7 +767,7 @@ cdef class flint_mpoly(flint_elem):
772767
In-place subtraction, mutates self.
773768
774769
>>> from flint import fmpz_mpoly_ctx
775-
>>> ctx = fmpz_mpoly_ctx.get_context(('x', 2), 'lex')
770+
>>> ctx = fmpz_mpoly_ctx.get(('x', 2), 'lex')
776771
>>> f = ctx.from_dict({(1, 0): 2, (0, 1): 3, (1, 1): 4})
777772
>>> f
778773
4*x0*x1 + 2*x0 + 3*x1
@@ -797,7 +792,7 @@ cdef class flint_mpoly(flint_elem):
797792
In-place multiplication, mutates self.
798793
799794
>>> from flint import fmpz_mpoly_ctx
800-
>>> ctx = fmpz_mpoly_ctx.get_context(('x', 2), 'lex')
795+
>>> ctx = fmpz_mpoly_ctx.get(('x', 2), 'lex')
801796
>>> f = ctx.from_dict({(1, 0): 2, (0, 1): 3, (1, 1): 4})
802797
>>> f
803798
4*x0*x1 + 2*x0 + 3*x1
@@ -822,7 +817,7 @@ cdef class flint_mpoly(flint_elem):
822817
Returns True if ``self`` contains a term with exponent vector ``x`` and a non-zero coefficient.
823818
824819
>>> from flint import fmpq_mpoly_ctx, Ordering
825-
>>> ctx = fmpq_mpoly_ctx.get_context(('x', 2), 'lex')
820+
>>> ctx = fmpq_mpoly_ctx.get(('x', 2), 'lex')
826821
>>> p = ctx.from_dict({(0, 1): 2, (1, 1): 3})
827822
>>> (1, 1) in p
828823
True
@@ -843,7 +838,7 @@ cdef class flint_mpoly(flint_elem):
843838
Return the exponent vectors and coefficient of each term.
844839
845840
>>> from flint import fmpq_mpoly_ctx, Ordering
846-
>>> ctx = fmpq_mpoly_ctx.get_context(('x', 2), 'lex')
841+
>>> ctx = fmpq_mpoly_ctx.get(('x', 2), 'lex')
847842
>>> f = ctx.from_dict({(0, 0): 1, (1, 0): 2, (0, 1): 3, (1, 1): 4})
848843
>>> list(f.terms())
849844
[((1, 1), 4), ((1, 0), 2), ((0, 1), 3), ((0, 0), 1)]

src/flint/test/test_all.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2104,7 +2104,7 @@ def test_fmpz_mod_poly():
21042104
assert pow(f, 2**60, g) == pow(pow(f, 2**30, g), 2**30, g)
21052105
assert pow(R_gen, 2**60, g) == pow(pow(R_gen, 2**30, g), 2**30, g)
21062106

2107-
# Check other typechecks for pow_mod
2107+
# Check other typechecks for pow_mod
21082108
assert raises(lambda: pow(f, -2, g), ValueError)
21092109
assert raises(lambda: pow(f, 1, "A"), TypeError)
21102110
assert raises(lambda: pow(f, "A", g), TypeError)
@@ -2756,7 +2756,7 @@ def setbad(obj, i, val):
27562756
assert P([1, 1]) ** 2 == P([1, 2, 1])
27572757
assert raises(lambda: P([1, 1]) ** -1, ValueError)
27582758
assert raises(lambda: P([1, 1]) ** None, TypeError)
2759-
2759+
27602760
# XXX: Not sure what this should do in general:
27612761
p = P([1, 1])
27622762
mod = P([1, 1])
@@ -2816,32 +2816,32 @@ def setbad(obj, i, val):
28162816

28172817
def _all_mpolys():
28182818
return [
2819-
(flint.fmpz_mpoly, flint.fmpz_mpoly_ctx.get_context, flint.fmpz, False, flint.fmpz(0)),
2820-
(flint.fmpq_mpoly, flint.fmpq_mpoly_ctx.get_context, flint.fmpq, True, flint.fmpz(0)),
2819+
(flint.fmpz_mpoly, flint.fmpz_mpoly_ctx.get, flint.fmpz, False, flint.fmpz(0)),
2820+
(flint.fmpq_mpoly, flint.fmpq_mpoly_ctx.get, flint.fmpq, True, flint.fmpz(0)),
28212821
(
28222822
flint.fmpz_mod_mpoly,
2823-
lambda *args, **kwargs: flint.fmpz_mod_mpoly_ctx.get_context(*args, **kwargs, modulus=101),
2823+
lambda *args, **kwargs: flint.fmpz_mod_mpoly_ctx.get(*args, **kwargs, modulus=101),
28242824
lambda x: flint.fmpz_mod(x, flint.fmpz_mod_ctx(101)),
28252825
True,
28262826
flint.fmpz(101),
28272827
),
28282828
(
28292829
flint.fmpz_mod_mpoly,
2830-
lambda *args, **kwargs: flint.fmpz_mod_mpoly_ctx.get_context(*args, **kwargs, modulus=100),
2830+
lambda *args, **kwargs: flint.fmpz_mod_mpoly_ctx.get(*args, **kwargs, modulus=100),
28312831
lambda x: flint.fmpz_mod(x, flint.fmpz_mod_ctx(100)),
28322832
False,
28332833
flint.fmpz(100),
28342834
),
28352835
(
28362836
flint.nmod_mpoly,
2837-
lambda *args, **kwargs: flint.nmod_mpoly_ctx.get_context(*args, **kwargs, modulus=101),
2837+
lambda *args, **kwargs: flint.nmod_mpoly_ctx.get(*args, **kwargs, modulus=101),
28382838
lambda x: flint.nmod(x, 101),
28392839
True,
28402840
flint.fmpz(101),
28412841
),
28422842
(
28432843
flint.nmod_mpoly,
2844-
lambda *args, **kwargs: flint.nmod_mpoly_ctx.get_context(*args, **kwargs, modulus=100),
2844+
lambda *args, **kwargs: flint.nmod_mpoly_ctx.get(*args, **kwargs, modulus=100),
28452845
lambda x: flint.nmod(x, 100),
28462846
False,
28472847
flint.fmpz(100),
@@ -2944,7 +2944,7 @@ def quick_poly():
29442944
assert P({(0, 1): 3}, ctx=ctx) == ctx.from_dict({(0, 1): 3})
29452945

29462946
if P is flint.fmpq_mpoly:
2947-
ctx_z = flint.fmpz_mpoly_ctx.get_context((("x", 2),))
2947+
ctx_z = flint.fmpz_mpoly_ctx.get((("x", 2),))
29482948
assert quick_poly() == P(ctx_z.from_dict({(0, 0): 1, (0, 1): 2, (1, 0): 3, (2, 2): 4}))
29492949
assert P(ctx_z.from_dict({(0, 0): 1}), ctx=ctx) == P({(0, 0): 1}, ctx=ctx)
29502950

@@ -3314,8 +3314,8 @@ def test_fmpz_mpoly_vec():
33143314
for context, mpoly_vec in _all_mpoly_vecs():
33153315
has_groebner_functions = mpoly_vec is flint.fmpz_mpoly_vec
33163316

3317-
ctx = context.get_context((("x", 2),))
3318-
ctx1 = context.get_context((("x", 4),))
3317+
ctx = context.get((("x", 2),))
3318+
ctx1 = context.get((("x", 4),))
33193319
x, y = ctx.gens()
33203320

33213321
vec = mpoly_vec(3, ctx)
@@ -3344,7 +3344,7 @@ def test_fmpz_mpoly_vec():
33443344
assert raises(lambda: vec.__setitem__(0, ctx1.from_dict({})), IncompatibleContextError)
33453345

33463346
if has_groebner_functions:
3347-
ctx = context.get_context(("x", "y", "z"))
3347+
ctx = context.get(("x", "y", "z"))
33483348

33493349
# Examples here cannibalised from
33503350
# https://en.wikipedia.org/wiki/Gr%C3%B6bner_basis#Example_and_counterexample
@@ -3407,8 +3407,8 @@ def _all_polys_mpolys():
34073407
))
34083408
yield P, S, [x, y], is_field, characteristic
34093409

3410-
for P, get_context, S, is_field, characteristic in _all_mpolys():
3411-
ctx = get_context(("x", "y"))
3410+
for P, get, S, is_field, characteristic in _all_mpolys():
3411+
ctx = get(("x", "y"))
34123412
x, y = ctx.gens()
34133413
assert isinstance(x, (
34143414
flint.fmpz_mpoly,
@@ -4159,7 +4159,7 @@ def test_fq_default():
41594159

41604160
# p must be prime
41614161
assert raises(lambda: flint.fq_default_ctx(10), ValueError)
4162-
4162+
41634163
# degree must be positive
41644164
assert raises(lambda: flint.fq_default_ctx(11, -1), ValueError)
41654165

0 commit comments

Comments
 (0)