Skip to content

Autogenerate all flintlib .pxd files #217

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

Merged
merged 15 commits into from
Sep 5, 2024
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
166 changes: 147 additions & 19 deletions bin/all_rst_to_pxd.sh
Original file line number Diff line number Diff line change
@@ -1,26 +1,154 @@
#!/usr/bin/env bash

FLINT_DOC_DIR=$1

set -e

modules="\
fmpz\
fmpz_factor\
fmpz_poly\
fmpz_poly_factor\
fmpz_mat\
fmpz_lll\
arf\
arb\
arb_poly\
arb_mat\
acb\
acb_poly\
acb_mat\
"
if [ $# -eq 0 ]
then
echo "Usage: bin/all_rst_to_pxd.sh /path/to/flint/doc/source"
exit 1
fi

FLINT_DOC_DIR=$1

modules=(
# "flint"
"mpoly"
# "thread_pool"
# "machine_vectors"
# "gr"
# "gr_domains"
# "gr_generic"
# "gr_implementing"
# "gr_mat"
# "gr_mpoly"
# "gr_poly"
# "gr_special"
# "gr_vec"
"ulong_extras"
"fmpz"
# "fmpz_extras"
"fmpz_factor"
"fmpz_lll"
"fmpz_mat"
"fmpz_mpoly"
"fmpz_mpoly_factor"
"fmpz_mpoly_q"
"fmpz_poly"
"fmpz_poly_factor"
# "fmpz_poly_mat"
# "fmpz_poly_q"
"fmpz_vec"
# "long_extras"
# "longlong"
# "mpn_extras"
# "aprcl"
"arith"
# "fft"
# "fft_small"
# "qsieve"
"fmpq"
"fmpq_mat"
"fmpq_mpoly"
"fmpq_mpoly_factor"
"fmpq_poly"
"fmpq_vec"
"nmod"
"nmod_mat"
"nmod_mpoly"
"nmod_mpoly_factor"
"nmod_poly"
"nmod_poly_factor"
# "nmod_poly_mat"
"nmod_vec"
# "mpn_mod"
"fmpz_mod"
"fmpz_mod_mat"
"fmpz_mod_mpoly"
"fmpz_mod_mpoly_factor"
"fmpz_mod_poly"
"fmpz_mod_poly_factor"
"fmpz_mod_vec"
"dirichlet"
# "dlog"
# "bool_mat"
# "perm"
# "qfb"
# "nf"
# "nf_elem"
# "fmpzi"
# "qqbar"
"mag"
# "nfloat"
"arf"
# "acf"
"arb"
# "arb_calc"
"arb_fmpz_poly"
# "arb_fpwrap"
"arb_hypgeom"
"arb_mat"
"arb_poly"
"acb"
"acb_calc"
"acb_dft"
"acb_dirichlet"
"acb_elliptic"
"acb_hypgeom"
"acb_mat"
"acb_modular"
"acb_poly"
"acb_theta"
"bernoulli"
# "hypgeom"
"partitions"
# "ca"
# "ca_ext"
# "ca_field"
# "ca_mat"
# "ca_poly"
# "ca_vec"
# "calcium"
# "fexpr"
# "fexpr_builtin"
"fq"
# "fq_embed"
"fq_mat"
"fq_poly"
"fq_poly_factor"
# "fq_vec"
"fq_nmod"
# "fq_nmod_embed"
"fq_nmod_mat"
# "fq_nmod_mpoly"
# "fq_nmod_mpoly_factor"
"fq_nmod_poly"
"fq_nmod_poly_factor"
# "fq_nmod_vec"
"fq_zech"
# "fq_zech_embed"
"fq_zech_mat"
"fq_zech_poly"
"fq_zech_poly_factor"
# "fq_zech_vec"
"fq_default"
"fq_default_mat"
"fq_default_poly"
"fq_default_poly_factor"
# "padic"
# "padic_mat"
# "padic_poly"
# "qadic"
# "double_extras"
# "double_interval"
# "d_mat"
# "d_vec"
# "mpfr_mat"
# "mpfr_vec"
)

for module in $modules; do
for module in ${modules[@]}; do
echo "Processing $module"
bin/rst_to_pxd.py flint/$module --flint-doc-dir=$FLINT_DOC_DIR > src/flint/flintlib/$module.pxd
bin/rst_to_pxd.py flint/$module \
--flint-doc-dir=$FLINT_DOC_DIR \
> src/flint/flintlib/functions/$module.pxd
done
19 changes: 14 additions & 5 deletions bin/rst_to_pxd.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,14 @@ def get_cython_struct_types(file):
l = line.strip()
if l[:8] == "ctypedef":
if l[-1] == ']':
# ctypedef foo foo_t[0]
l = l[:l.rfind('[')]
elif '(' in l:
# ctypedef int (*foo_func)(...)
l = l[l.index('('):].lstrip('(*')
l = l[:l.index(')')]
else:
# ctypedef foo:
l = l.strip(':')
ret.append(l.split()[-1])
return ret
Expand All @@ -72,12 +78,14 @@ def fill_import_dict(pyflintlibdir):
"""
Get a map from cython structs to the pxd that defines them
"""
with os.scandir(pyflintlibdir) as entry:
import_dict['fmpq_struct'] = 'types.fmpq'

with os.scandir(pyflintlibdir + '/types') as entry:
for f in entry:
if fnmatch.fnmatch(f.name, "*.pxd"):
with open(f.path) as pxd:
for t in get_cython_struct_types(pxd):
import_dict[t] = f.name.split('.')[0]
import_dict[t] = 'types.' + f.name.split('.')[0]

def undecorate(str):
"""
Expand All @@ -86,12 +94,13 @@ def undecorate(str):
ret = str.strip()
if ' ' in ret:
ret = ret[:ret.rfind(' ')]
ret = re.sub(type_modifers, '', ret)
return ret.strip()
ret = re.sub(type_modifers, '', ret).strip()
return ret

def get_parameter_types(str):
params = str[str.find("(") + 1 : str.rfind(")")].split(",")
params.append(str.split()[0])
ret_type = str.split('(')[0].rsplit(' ', 1)[0]
params.append(ret_type)
return [undecorate(s) for s in params if s]

def clean_types(function):
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ build-backend = "mesonpy"
# resolved.
max-line-length = 120
ignore = ['E129','E501','E741','E743']
exclude = 'src/flint/flintlib/.*'
exclude = 'src/flint/flintlib/functions.*'

[tool.spin]
package = "flint"
Expand Down
2 changes: 1 addition & 1 deletion src/flint/flint_base/flint_base.pxd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from flint.flintlib.mpoly cimport ordering_t
from flint.flintlib.types.mpoly cimport ordering_t

cdef class flint_elem:
pass
Expand Down
4 changes: 2 additions & 2 deletions src/flint/flint_base/flint_base.pyx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from flint.flintlib.flint cimport (
from flint.flintlib.types.flint cimport (
FLINT_BITS as _FLINT_BITS,
FLINT_VERSION as _FLINT_VERSION,
__FLINT_RELEASE as _FLINT_RELEASE,
slong
)
from flint.utils.flint_exceptions import DomainError
from flint.flintlib.mpoly cimport ordering_t
from flint.flintlib.types.mpoly cimport ordering_t
from flint.flint_base.flint_context cimport thectx
from flint.flint_base.flint_base cimport Ordering
from flint.utils.typecheck cimport typecheck
Expand Down
2 changes: 1 addition & 1 deletion src/flint/flint_base/flint_context.pxd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from flint.flintlib.arf_types cimport (
from flint.flintlib.types.arf cimport (
arf_rnd_t,
)

Expand Down
4 changes: 2 additions & 2 deletions src/flint/flint_base/flint_context.pyx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from flint.flintlib.arf_types cimport arf_rnd_t
from flint.flintlib.flint cimport (
from flint.flintlib.types.arf cimport arf_rnd_t
from flint.flintlib.types.flint cimport (
flint_cleanup,
flint_get_num_threads,
flint_set_num_threads
Expand Down
5 changes: 0 additions & 5 deletions src/flint/flintlib/acb_dft.pxd

This file was deleted.

19 changes: 0 additions & 19 deletions src/flint/flintlib/acb_modular.pxd

This file was deleted.

Loading
Loading