Skip to content

Commit d4a8f7c

Browse files
Merge pull request #217 from oscarbenjamin/pr_pxd_files
Autogenerate all flintlib .pxd files from FLINT docs
2 parents 137e7a6 + a51dc42 commit d4a8f7c

File tree

170 files changed

+2499
-2303
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

170 files changed

+2499
-2303
lines changed

bin/all_rst_to_pxd.sh

Lines changed: 147 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,154 @@
11
#!/usr/bin/env bash
22

3-
FLINT_DOC_DIR=$1
4-
53
set -e
64

7-
modules="\
8-
fmpz\
9-
fmpz_factor\
10-
fmpz_poly\
11-
fmpz_poly_factor\
12-
fmpz_mat\
13-
fmpz_lll\
14-
arf\
15-
arb\
16-
arb_poly\
17-
arb_mat\
18-
acb\
19-
acb_poly\
20-
acb_mat\
21-
"
5+
if [ $# -eq 0 ]
6+
then
7+
echo "Usage: bin/all_rst_to_pxd.sh /path/to/flint/doc/source"
8+
exit 1
9+
fi
10+
11+
FLINT_DOC_DIR=$1
12+
13+
modules=(
14+
# "flint"
15+
"mpoly"
16+
# "thread_pool"
17+
# "machine_vectors"
18+
# "gr"
19+
# "gr_domains"
20+
# "gr_generic"
21+
# "gr_implementing"
22+
# "gr_mat"
23+
# "gr_mpoly"
24+
# "gr_poly"
25+
# "gr_special"
26+
# "gr_vec"
27+
"ulong_extras"
28+
"fmpz"
29+
# "fmpz_extras"
30+
"fmpz_factor"
31+
"fmpz_lll"
32+
"fmpz_mat"
33+
"fmpz_mpoly"
34+
"fmpz_mpoly_factor"
35+
"fmpz_mpoly_q"
36+
"fmpz_poly"
37+
"fmpz_poly_factor"
38+
# "fmpz_poly_mat"
39+
# "fmpz_poly_q"
40+
"fmpz_vec"
41+
# "long_extras"
42+
# "longlong"
43+
# "mpn_extras"
44+
# "aprcl"
45+
"arith"
46+
# "fft"
47+
# "fft_small"
48+
# "qsieve"
49+
"fmpq"
50+
"fmpq_mat"
51+
"fmpq_mpoly"
52+
"fmpq_mpoly_factor"
53+
"fmpq_poly"
54+
"fmpq_vec"
55+
"nmod"
56+
"nmod_mat"
57+
"nmod_mpoly"
58+
"nmod_mpoly_factor"
59+
"nmod_poly"
60+
"nmod_poly_factor"
61+
# "nmod_poly_mat"
62+
"nmod_vec"
63+
# "mpn_mod"
64+
"fmpz_mod"
65+
"fmpz_mod_mat"
66+
"fmpz_mod_mpoly"
67+
"fmpz_mod_mpoly_factor"
68+
"fmpz_mod_poly"
69+
"fmpz_mod_poly_factor"
70+
"fmpz_mod_vec"
71+
"dirichlet"
72+
# "dlog"
73+
# "bool_mat"
74+
# "perm"
75+
# "qfb"
76+
# "nf"
77+
# "nf_elem"
78+
# "fmpzi"
79+
# "qqbar"
80+
"mag"
81+
# "nfloat"
82+
"arf"
83+
# "acf"
84+
"arb"
85+
# "arb_calc"
86+
"arb_fmpz_poly"
87+
# "arb_fpwrap"
88+
"arb_hypgeom"
89+
"arb_mat"
90+
"arb_poly"
91+
"acb"
92+
"acb_calc"
93+
"acb_dft"
94+
"acb_dirichlet"
95+
"acb_elliptic"
96+
"acb_hypgeom"
97+
"acb_mat"
98+
"acb_modular"
99+
"acb_poly"
100+
"acb_theta"
101+
"bernoulli"
102+
# "hypgeom"
103+
"partitions"
104+
# "ca"
105+
# "ca_ext"
106+
# "ca_field"
107+
# "ca_mat"
108+
# "ca_poly"
109+
# "ca_vec"
110+
# "calcium"
111+
# "fexpr"
112+
# "fexpr_builtin"
113+
"fq"
114+
# "fq_embed"
115+
"fq_mat"
116+
"fq_poly"
117+
"fq_poly_factor"
118+
# "fq_vec"
119+
"fq_nmod"
120+
# "fq_nmod_embed"
121+
"fq_nmod_mat"
122+
# "fq_nmod_mpoly"
123+
# "fq_nmod_mpoly_factor"
124+
"fq_nmod_poly"
125+
"fq_nmod_poly_factor"
126+
# "fq_nmod_vec"
127+
"fq_zech"
128+
# "fq_zech_embed"
129+
"fq_zech_mat"
130+
"fq_zech_poly"
131+
"fq_zech_poly_factor"
132+
# "fq_zech_vec"
133+
"fq_default"
134+
"fq_default_mat"
135+
"fq_default_poly"
136+
"fq_default_poly_factor"
137+
# "padic"
138+
# "padic_mat"
139+
# "padic_poly"
140+
# "qadic"
141+
# "double_extras"
142+
# "double_interval"
143+
# "d_mat"
144+
# "d_vec"
145+
# "mpfr_mat"
146+
# "mpfr_vec"
147+
)
22148

23-
for module in $modules; do
149+
for module in ${modules[@]}; do
24150
echo "Processing $module"
25-
bin/rst_to_pxd.py flint/$module --flint-doc-dir=$FLINT_DOC_DIR > src/flint/flintlib/$module.pxd
151+
bin/rst_to_pxd.py flint/$module \
152+
--flint-doc-dir=$FLINT_DOC_DIR \
153+
> src/flint/flintlib/functions/$module.pxd
26154
done

bin/rst_to_pxd.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,14 @@ def get_cython_struct_types(file):
6262
l = line.strip()
6363
if l[:8] == "ctypedef":
6464
if l[-1] == ']':
65+
# ctypedef foo foo_t[0]
6566
l = l[:l.rfind('[')]
67+
elif '(' in l:
68+
# ctypedef int (*foo_func)(...)
69+
l = l[l.index('('):].lstrip('(*')
70+
l = l[:l.index(')')]
6671
else:
72+
# ctypedef foo:
6773
l = l.strip(':')
6874
ret.append(l.split()[-1])
6975
return ret
@@ -72,12 +78,14 @@ def fill_import_dict(pyflintlibdir):
7278
"""
7379
Get a map from cython structs to the pxd that defines them
7480
"""
75-
with os.scandir(pyflintlibdir) as entry:
81+
import_dict['fmpq_struct'] = 'types.fmpq'
82+
83+
with os.scandir(pyflintlibdir + '/types') as entry:
7684
for f in entry:
7785
if fnmatch.fnmatch(f.name, "*.pxd"):
7886
with open(f.path) as pxd:
7987
for t in get_cython_struct_types(pxd):
80-
import_dict[t] = f.name.split('.')[0]
88+
import_dict[t] = 'types.' + f.name.split('.')[0]
8189

8290
def undecorate(str):
8391
"""
@@ -86,12 +94,13 @@ def undecorate(str):
8694
ret = str.strip()
8795
if ' ' in ret:
8896
ret = ret[:ret.rfind(' ')]
89-
ret = re.sub(type_modifers, '', ret)
90-
return ret.strip()
97+
ret = re.sub(type_modifers, '', ret).strip()
98+
return ret
9199

92100
def get_parameter_types(str):
93101
params = str[str.find("(") + 1 : str.rfind(")")].split(",")
94-
params.append(str.split()[0])
102+
ret_type = str.split('(')[0].rsplit(' ', 1)[0]
103+
params.append(ret_type)
95104
return [undecorate(s) for s in params if s]
96105

97106
def clean_types(function):

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ build-backend = "mesonpy"
5959
# resolved.
6060
max-line-length = 120
6161
ignore = ['E129','E501','E741','E743']
62-
exclude = 'src/flint/flintlib/.*'
62+
exclude = 'src/flint/flintlib/functions.*'
6363

6464
[tool.spin]
6565
package = "flint"

src/flint/flint_base/flint_base.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from flint.flintlib.mpoly cimport ordering_t
1+
from flint.flintlib.types.mpoly cimport ordering_t
22

33
cdef class flint_elem:
44
pass

src/flint/flint_base/flint_base.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
from flint.flintlib.flint cimport (
1+
from flint.flintlib.types.flint cimport (
22
FLINT_BITS as _FLINT_BITS,
33
FLINT_VERSION as _FLINT_VERSION,
44
__FLINT_RELEASE as _FLINT_RELEASE,
55
slong
66
)
77
from flint.utils.flint_exceptions import DomainError
8-
from flint.flintlib.mpoly cimport ordering_t
8+
from flint.flintlib.types.mpoly cimport ordering_t
99
from flint.flint_base.flint_context cimport thectx
1010
from flint.flint_base.flint_base cimport Ordering
1111
from flint.utils.typecheck cimport typecheck

src/flint/flint_base/flint_context.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from flint.flintlib.arf_types cimport (
1+
from flint.flintlib.types.arf cimport (
22
arf_rnd_t,
33
)
44

src/flint/flint_base/flint_context.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from flint.flintlib.arf_types cimport arf_rnd_t
2-
from flint.flintlib.flint cimport (
1+
from flint.flintlib.types.arf cimport arf_rnd_t
2+
from flint.flintlib.types.flint cimport (
33
flint_cleanup,
44
flint_get_num_threads,
55
flint_set_num_threads

src/flint/flintlib/acb_dft.pxd

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/flint/flintlib/acb_modular.pxd

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)