Skip to content

Commit 1fbd80a

Browse files
committed
bindings: auto-generate acb_calc and mag
1 parent 137e7a6 commit 1fbd80a

File tree

5 files changed

+104
-40
lines changed

5 files changed

+104
-40
lines changed

bin/all_rst_to_pxd.sh

Lines changed: 72 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,79 @@ FLINT_DOC_DIR=$1
44

55
set -e
66

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-
"
7+
modules=(
8+
"acb_calc"
9+
#"acb_dft"
10+
#"acb_dirichlet"
11+
#"acb_elliptic"
12+
#"acb_hypgeom"
13+
"acb_mat"
14+
#"acb_modular"
15+
"acb_poly"
16+
"acb"
17+
#"acb_theta"
18+
#"arb_fmpz_poly"
19+
#"arb_hypgeom"
20+
"arb_mat"
21+
"arb_poly"
22+
"arb"
23+
"arf"
24+
#"arith"
25+
#"bernoulli"
26+
#"dirichlet"
27+
#"fmpq_mat"
28+
#"fmpq_mpoly_factor"
29+
#"fmpq_mpoly"
30+
#"fmpq_poly"
31+
#"fmpq"
32+
#"fmpq_vec"
33+
"fmpz_factor"
34+
"fmpz_lll"
35+
"fmpz_mat"
36+
#"fmpz_mod_mat"
37+
#"fmpz_mod_mpoly_factor"
38+
#"fmpz_mod_mpoly"
39+
#"fmpz_mod_poly_factor"
40+
#"fmpz_mod_poly"
41+
#"fmpz_mod"
42+
#"fmpz_mod_vec"
43+
#"fmpz_mpoly_factor"
44+
#"fmpz_mpoly"
45+
#"fmpz_mpoly_q"
46+
"fmpz_poly_factor"
47+
"fmpz_poly"
48+
"fmpz"
49+
#"fmpz_vec"
50+
#"fq_default_mat"
51+
#"fq_default_poly_factor"
52+
#"fq_default_poly"
53+
#"fq_default"
54+
#"fq_mat"
55+
#"fq_nmod_mat"
56+
#"fq_nmod_poly_factor"
57+
#"fq_nmod_poly"
58+
#"fq_nmod"
59+
#"fq_poly_factor"
60+
#"fq_poly"
61+
#"fq"
62+
#"fq_zech_mat"
63+
#"fq_zech_poly_factor"
64+
#"fq_zech_poly"
65+
#"fq_zech"
66+
"mag"
67+
#"mpoly"
68+
#"nmod_mat"
69+
#"nmod_mpoly_factor"
70+
#"nmod_mpoly"
71+
#"nmod_poly_factor"
72+
#"nmod_poly"
73+
#"nmod"
74+
#"nmod_vec"
75+
#"partitions"
76+
#"ulong_extras"
77+
)
2278

23-
for module in $modules; do
79+
for module in ${modules[@]}; do
2480
echo "Processing $module"
2581
bin/rst_to_pxd.py flint/$module --flint-doc-dir=$FLINT_DOC_DIR > src/flint/flintlib/$module.pxd
2682
done

bin/rst_to_pxd.py

Lines changed: 6 additions & 0 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

src/flint/flintlib/acb_calc.pxd

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,13 @@
1-
from flint.flintlib.acb cimport acb_t, acb_ptr
2-
from flint.flintlib.mag cimport mag_t
1+
from flint.flintlib.acb_types cimport acb_calc_func_t, acb_calc_integrate_opt_t, acb_t
2+
from flint.flintlib.arb_types cimport arb_t, mag_t
3+
from flint.flintlib.arf_types cimport arf_t
34
from flint.flintlib.flint cimport slong
4-
from flint.flintlib.arb cimport arb_t
5-
from flint.flintlib.arf cimport arf_t
65

7-
cdef extern from "flint/acb_calc.h":
8-
ctypedef int (*acb_calc_func_t)(acb_ptr out, const acb_t inp, void * param, long order, long prec)
9-
10-
ctypedef struct acb_calc_integrate_opt_struct:
11-
long deg_limit
12-
long eval_limit
13-
long depth_limit
14-
int use_heap
15-
int verbose
166

17-
ctypedef acb_calc_integrate_opt_struct acb_calc_integrate_opt_t[1]
187

19-
# from /Users/davideinstein/projects/arb/doc/source/acb_calc.rst
8+
cdef extern from "flint/acb_calc.h":
209
int acb_calc_integrate(acb_t res, acb_calc_func_t func, void * param, const acb_t a, const acb_t b, slong rel_goal, const mag_t abs_tol, const acb_calc_integrate_opt_t options, slong prec)
2110
void acb_calc_integrate_opt_init(acb_calc_integrate_opt_t options)
2211
int acb_calc_integrate_gl_auto_deg(acb_t res, slong * num_eval, acb_calc_func_t func, void * param, const acb_t a, const acb_t b, const mag_t tol, slong deg_limit, int flags, slong prec)
2312
void acb_calc_cauchy_bound(arb_t bound, acb_calc_func_t func, void * param, const acb_t x, const arb_t radius, slong maxdepth, slong prec)
2413
int acb_calc_integrate_taylor(acb_t res, acb_calc_func_t func, void * param, const acb_t a, const acb_t b, const arf_t inner_radius, const arf_t outer_radius, slong accuracy_goal, slong prec)
25-

src/flint/flintlib/acb_types.pxd

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,15 @@ cdef extern from "flint/acb_mat.h":
3737

3838
cdef extern from "flint/acb_poly.h":
3939
acb_ptr acb_poly_get_coeff_ptr(arb_poly_t poly, slong n)
40+
41+
cdef extern from "flint/acb_calc.h":
42+
ctypedef int (*acb_calc_func_t)(acb_ptr out, const acb_t inp, void * param, slong order, slong prec)
43+
44+
ctypedef struct acb_calc_integrate_opt_struct:
45+
slong deg_limit
46+
slong eval_limit
47+
slong depth_limit
48+
int use_heap
49+
int verbose
50+
51+
ctypedef acb_calc_integrate_opt_struct acb_calc_integrate_opt_t[1]

src/flint/flintlib/mag.pxd

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
from flint.flintlib.flint cimport ulong, mp_limb_t, slong, flint_rand_t
2-
from flint.flintlib.fmpz cimport fmpz_struct, fmpz_t
3-
from flint.flintlib.fmpq cimport fmpq_struct, fmpq_t
4-
from flint.flintlib.arb_types cimport mag_t, mag_ptr
1+
from flint.flintlib.arb_types cimport mag_ptr, mag_t
2+
from flint.flintlib.flint cimport flint_rand_t, slong, ulong
3+
from flint.flintlib.fmpq cimport fmpq_t
4+
from flint.flintlib.fmpz_types cimport fmpz_t
5+
6+
# unknown type FILE
57

6-
cdef extern from "flint/mag.h":
78

8-
# from here on is parsed
9+
cdef extern from "flint/mag.h":
910
void mag_init(mag_t x)
1011
void mag_clear(mag_t x)
1112
void mag_swap(mag_t x, mag_t y)
@@ -22,7 +23,6 @@ cdef extern from "flint/mag.h":
2223
void mag_init_set(mag_t res, const mag_t x)
2324
void mag_set(mag_t res, const mag_t x)
2425
void mag_set_d(mag_t res, double x)
25-
# void mag_set_fmpr(mag_t res, const fmpr_t x)
2626
void mag_set_ui(mag_t res, ulong x)
2727
void mag_set_fmpz(mag_t res, const fmpz_t x)
2828
void mag_set_d_lower(mag_t res, double x)
@@ -35,7 +35,6 @@ cdef extern from "flint/mag.h":
3535
void mag_set_fmpz_2exp_fmpz_lower(mag_t res, const fmpz_t x, const fmpz_t y)
3636
double mag_get_d(const mag_t x)
3737
double mag_get_d_log2_approx(const mag_t x)
38-
# void mag_get_fmpr(fmpr_t res, const mag_t x)
3938
void mag_get_fmpq(fmpq_t res, const mag_t x)
4039
void mag_get_fmpz(fmpz_t res, const mag_t x)
4140
void mag_get_fmpz_lower(fmpz_t res, const mag_t x)
@@ -45,8 +44,11 @@ cdef extern from "flint/mag.h":
4544
void mag_min(mag_t res, const mag_t x, const mag_t y)
4645
void mag_max(mag_t res, const mag_t x, const mag_t y)
4746
void mag_print(const mag_t x)
47+
# void mag_fprint(FILE * file, const mag_t x)
4848
char * mag_dump_str(const mag_t x)
4949
int mag_load_str(mag_t x, const char * str)
50+
# int mag_dump_file(FILE * stream, const mag_t x)
51+
# int mag_load_file(mag_t x, FILE * stream)
5052
void mag_randtest(mag_t res, flint_rand_t state, slong expbits)
5153
void mag_randtest_special(mag_t res, flint_rand_t state, slong expbits)
5254
void mag_add(mag_t res, const mag_t x, const mag_t y)

0 commit comments

Comments
 (0)