Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for modules wrapping flint #39

Merged
merged 21 commits into from
Apr 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
build/*
dist/*
src/flint/*.c
src/flint/*.html
doc/build/*
fmake*
*.whl
Expand All @@ -13,3 +14,4 @@ MANIFEST
.local
*.egg-info
.coverage
*.swp
1 change: 1 addition & 0 deletions bin/activate
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export C_INCLUDE_PATH=$(pwd)/.local/include
export LIBRARY_PATH=$(pwd)/.local/lib
export LD_LIBRARY_PATH=$(pwd)/.local/lib
export PYTHONPATH=$(pwd)/src
source .local/venv/bin/activate
4 changes: 2 additions & 2 deletions bin/coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ export PYTHON_FLINT_COVERAGE=true

python setup.py build_ext --inplace

coverage run test/test.py
pytest --cov flint test/test.py
coverage run --append test/dtest.py

coverage report -m
#coverage report -m
coverage html
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
name='python-flint',
cmdclass={'build_ext': build_ext},
ext_modules=cythonize(ext_modules, compiler_directives=compiler_directives),
#ext_modules=cythonize(ext_modules, compiler_directives=compiler_directives, annotate=True),
packages=['flint'],
package_dir={'': 'src'},
description='Bindings for FLINT and Arb',
Expand Down
16 changes: 13 additions & 3 deletions src/flint/fmpq_series.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ cdef class fmpq_series(flint_series):
if val is not None:
if typecheck(val, fmpq_series):
fmpq_poly_set(self.val, (<fmpq_series>val).val)
self.prec = min((<fmpz_series>val).prec, getcap())
self.prec = min((<fmpq_series>val).prec, getcap())
elif typecheck(val, fmpz_series):
fmpq_poly_set_fmpz_poly(self.val, (<fmpz_series>val).val)
self.prec = min((<fmpz_series>val).prec, getcap())
Expand All @@ -62,6 +62,15 @@ cdef class fmpq_series(flint_series):
raise ZeroDivisionError("cannot create fmpq_series with zero denominator")
fmpq_poly_scalar_div_fmpz(self.val, self.val, (<fmpz>den).val)

def _equal_repr(s, t):
cdef bint r
if not typecheck(t, fmpq_series):
return False
r = fmpq_poly_equal((<fmpq_series>s).val, (<fmpq_series>t).val)
if r:
r = (<fmpq_series>s).prec == (<fmpq_series>t).prec
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the kind of equality comparison we want for series?

  • A series cannot compare equal to anything that is not a series e.g. fmpq_series([1]) != 1
  • An fmpz_series can compare equal to an fmpq_series: fmpq_series([1]) == fmpz_series([1])
  • Two series with different prec compare unequal: fmpz_series([1],5) != fmpz_series([1],6)
  • Invalid series compare equal: fmpz_series([],-1) == fmpz_series([],-1)

return r

def __len__(self):
return fmpq_poly_length(self.val)

Expand Down Expand Up @@ -197,7 +206,7 @@ cdef class fmpq_series(flint_series):
u = fmpq_series.__new__(fmpq_series)

if fmpq_poly_is_zero((<fmpq_series>s).val):
u.cap = cap
(<fmpq_series>u).prec = cap
return u

sval = (<fmpq_series>s).valuation()
Expand Down Expand Up @@ -236,6 +245,7 @@ cdef class fmpq_series(flint_series):
return fmpq_series._div_(s, t)

# generic exponentiation (fallback code)
# XXX: use fmpq_poly_pow_trunc instead?
def __pow__(s, ulong exp, mod):
if mod is not None:
raise NotImplementedError("modular exponentiation")
Expand Down Expand Up @@ -308,7 +318,7 @@ cdef class fmpq_series(flint_series):
cdef bint one_constant_term(s):
if fmpq_poly_is_zero((<fmpq_series>s).val):
return False
if fmpz_is_one(&((<fmpq_series>s).val.coeffs[0])):
if fmpz_equal(&((<fmpq_series>s).val.coeffs[0]), (<fmpq_series>s).val.den):
return True
return False

Expand Down
9 changes: 9 additions & 0 deletions src/flint/fmpz_series.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ cdef class fmpz_series(flint_series):
fmpz_poly_set_list(self.val, [val])
fmpz_poly_truncate(self.val, max(0, self.prec))

def _equal_repr(self, other):
cdef bint r
if not typecheck(other, fmpz_series):
return False
r = fmpz_poly_equal((<fmpz_series>self).val, (<fmpz_series>other).val)
if r:
r = (<fmpz_series>self).prec == (<fmpz_series>other).prec
return r

def __len__(self):
return fmpz_poly_length(self.val)

Expand Down
Loading