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

fix(nmod): Add nmod_ctx to store is_prime #179

Open
wants to merge 31 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
293ec24
fix(nmod): Add nmod_ctx to store is_prime
oscarbenjamin Aug 6, 2024
27e5e4c
Add nmod_poly_ctx
oscarbenjamin Aug 22, 2024
a88f881
Use nmod contexts for nmod_mat
oscarbenjamin Aug 22, 2024
ba9c1fd
Inline ctx.any_as_nmod for faster nmod.__mul__
oscarbenjamin Aug 22, 2024
8c2221b
Use nmod_ctx consistently in nmod_poly and nmod_mat
oscarbenjamin Aug 24, 2024
affe462
Use cython.no_gc to speed up nmod
oscarbenjamin Aug 24, 2024
6f04cdd
fix: check for non-prime modulus in nmod_poly
oscarbenjamin Aug 26, 2024
23389a5
test: Add nmod_poly with modulus=9 test case
oscarbenjamin Aug 26, 2024
f47188c
Use any_as_nmod rather than ctx.any_as_nmod
oscarbenjamin Aug 26, 2024
154b035
perf: use @cython.final for nmod_ctx.any_as_nmod
oscarbenjamin Aug 26, 2024
82af09e
Add nmod_ctx.new_nmod function
oscarbenjamin Aug 27, 2024
8d69a4e
Add nmod_poly_ctx and nmod_mat_ctx
oscarbenjamin Aug 27, 2024
c454681
Use no_gc for nmod
oscarbenjamin Aug 27, 2024
9062d32
Use setdefault for ctx caches
oscarbenjamin Aug 27, 2024
0fa5d42
pin cython commit for the coverage job
oscarbenjamin Aug 27, 2024
3abe283
Use an earlier Cython commit...
oscarbenjamin Aug 27, 2024
f7d27a5
Use Oscar's cython branch for coverage again
oscarbenjamin Aug 27, 2024
5b16c20
test: add tests for fmpz and fmpz_mat
oscarbenjamin Aug 28, 2024
9b3d7c4
test: add polys tests for div/sqrt
oscarbenjamin Aug 28, 2024
e7c1418
test: handle excluded lines in coverage plugin
oscarbenjamin Aug 28, 2024
0fa1dbf
fmpq: use fmpq_cmp for <,<=,>,>=
oscarbenjamin Aug 28, 2024
b605f97
Full coverage of nmod_poly and various fixes.
oscarbenjamin Aug 28, 2024
ff21556
Test nmod_mat_ctx
oscarbenjamin Aug 28, 2024
c06bc86
Use int(characteristic) for PyPy
oscarbenjamin Aug 28, 2024
3d39267
Use int for PyPy
oscarbenjamin Aug 28, 2024
58f3887
Use Cython master branch again after:
oscarbenjamin Aug 29, 2024
e837d99
Add @cython.no_gc to nmod_poly and nmod_mat
oscarbenjamin Aug 29, 2024
6d14958
Various lint fixes
oscarbenjamin Sep 1, 2024
a9215d0
Lint fixes
oscarbenjamin Sep 2, 2024
b1d5239
refactor: move nmod_ctx cdef methods to .pxd files
oscarbenjamin Sep 3, 2024
f84aad8
Merge remote-tracking branch 'upstream/main' into pr_nmod_ctx
oscarbenjamin Sep 5, 2024
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
4 changes: 4 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
[run]
plugins = coverage_plugin

[report]
exclude_also =
assert False
4 changes: 2 additions & 2 deletions .github/workflows/buildwheel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ jobs:

# Test that we can make a coverage build and report coverage
test_coverage_build:
name: Test coverage setuptools build
name: Test coverage build
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
Expand All @@ -202,7 +202,7 @@ jobs:
python-version: '3.12'
- run: sudo apt-get update
- run: sudo apt-get install libflint-dev
# Need Cython's master branch until 3.1 is released because of:
# Need Cython's master branch until 3.1 is released because we need:
# https://github.com/cython/cython/pull/6341
- run: pip install git+https://github.com/cython/cython.git@master
- run: pip install -r requirements-dev.txt
Expand Down
22 changes: 15 additions & 7 deletions coverage_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def get_cython_build_rules():


@cache
def parse_all_cfile_lines():
def parse_all_cfile_lines(exclude_patterns=None):
"""Parse all generated C files from the build directory."""
#
# Each .c file can include code generated from multiple Cython files (e.g.
Expand All @@ -80,7 +80,7 @@ def parse_all_cfile_lines():

for c_file, _ in get_cython_build_rules():

cfile_lines = parse_cfile_lines(c_file)
cfile_lines = parse_cfile_lines(c_file, exclude_patterns=exclude_patterns)

for cython_file, line_map in cfile_lines.items():
if cython_file == '(tree fragment)':
Expand All @@ -94,15 +94,22 @@ def parse_all_cfile_lines():
return all_code_lines


def parse_cfile_lines(c_file):
def parse_cfile_lines(c_file, exclude_patterns=None):
"""Use Cython's coverage plugin to parse the C code."""
from Cython.Coverage import Plugin
return Plugin()._parse_cfile_lines(c_file)
p = Plugin()
p._excluded_line_patterns = list(exclude_patterns)
return p._parse_cfile_lines(c_file)


class Plugin(CoveragePlugin):
"""A coverage plugin for a spin/meson project with Cython code."""

def configure(self, config):
# Entry point for coverage "configurer".
# Read the regular expressions from the coverage config that match lines to be excluded from coverage.
self.exclude_patterns = tuple(config.get_option("report:exclude_lines"))

def file_tracer(self, filename):
"""Find a tracer for filename to handle trace events."""
path = Path(filename)
Expand All @@ -121,7 +128,7 @@ def file_tracer(self, filename):
def file_reporter(self, filename):
"""Return a file reporter for filename."""
srcfile = Path(filename).relative_to(src_dir)
return CyFileReporter(srcfile)
return CyFileReporter(srcfile, exclude_patterns=self.exclude_patterns)


class CyFileTracer(FileTracer):
Expand Down Expand Up @@ -157,14 +164,15 @@ def get_source_filename(filename):
class CyFileReporter(FileReporter):
"""File reporter for Cython or Python files (.pyx,.pxd,.py)."""

def __init__(self, srcpath):
def __init__(self, srcpath, exclude_patterns):
abspath = (src_dir / srcpath)
assert abspath.exists()

# filepath here needs to match dynamic_source_filename
super().__init__(str(abspath))

self.srcpath = srcpath
self.exclude_patterns = exclude_patterns

def relative_filename(self):
"""Path displayed in the coverage reports."""
Expand All @@ -173,7 +181,7 @@ def relative_filename(self):
def lines(self):
"""Set of line numbers for possibly traceable lines."""
srcpath = str(self.srcpath)
all_line_maps = parse_all_cfile_lines()
all_line_maps = parse_all_cfile_lines(exclude_patterns=self.exclude_patterns)
line_map = all_line_maps[srcpath]
return set(line_map)

Expand Down
Loading
Loading