Skip to content

Commit

Permalink
add tests for fq_default init from context
Browse files Browse the repository at this point in the history
  • Loading branch information
GiacomoPope committed Aug 7, 2024
1 parent 3c93c45 commit 0a9d276
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/flint/test/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -3597,6 +3597,7 @@ def test_fq_default():
gf_5_2 = flint.fq_default_ctx(5, 2)

# GF((2**127 - 1)^2)
gf_127 = flint.fq_default_ctx(2**127 - 1, 2)
gf_127_2 = flint.fq_default_ctx(2**127 - 1, 2)

assert (gf_5 == gf_5_) is True
Expand All @@ -3616,9 +3617,16 @@ def test_fq_default():
assert str(gf_5) == "Context for fq_default in GF(5)"
assert str(gf_5_2) == "Context for fq_default in GF(5^2)[x]/(x^2 + 4*x + 2)"

# coercision
assert gf_5(1) == gf_5(flint.fmpz(1)) == gf_5.one()
assert gf_5(-1) == gf_5(flint.fmpz(-1)) == -gf_5.one()
assert gf_5([0, 1]) == gf_5(flint.fmpz_poly([0, 1])) == gf_5.gen()
R = flint.fmpz_mod_poly_ctx(5)
assert gf_5.gen() == gf_5(R.gen()) == gf_5(flint.nmod_poly([0, 1], 5))

# test fq_default element arithemtic

for gf in [gf_5, gf_5_2, gf_127_2]:
for gf in [gf_5, gf_5_2, gf_127, gf_127_2]:

assert (gf(0) == gf.zero()) is True
assert (gf(0) != gf.zero()) is False
Expand Down
10 changes: 9 additions & 1 deletion src/flint/types/fq_default.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,15 @@ cdef class fq_default_ctx:
cdef set_any_as_fq_default(self, fq_default_t fq_ele, obj):
# For small integers we can convert directly
if typecheck(obj, int) and obj.bit_length() < 32:
fq_default_set_si(fq_ele, <slong>obj, self.val)
if obj < 0:
fq_default_set_si(fq_ele, <slong>obj, self.val)
else:
fq_default_set_ui(fq_ele, <ulong>obj, self.val)
return 0

# For fmpz we can also convert directly
if typecheck(obj, fmpz):
fq_default_set_fmpz(fq_ele, (<fmpz>obj).val, self.val)
return 0

# Assumes that the modulus of the polynomial matches
Expand Down

0 comments on commit 0a9d276

Please sign in to comment.