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

Automatically generate fmpz_* pxds from FLINT headers #215

Merged
merged 7 commits into from
Sep 4, 2024

Conversation

oscarbenjamin
Copy link
Collaborator

This is a start towards having fully automatic updating of the flintlib .pxd files.

I have made a few improvements to the bin/rst_to_pxd.py script so that it can generate the files fully without editing by commenting out functions with unrecognised types.

I also added a script bin/all_rst_to_pxd.sh like:

#!/usr/bin/env bash

FLINT_DOC_DIR=$1

set -e

modules="\
    fmpz\
    fmpz_factor\
    fmpz_poly\
    fmpz_poly_factor\
    fmpz_mat\
    fmpz_lll\
    "

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
done

The idea would be for that modules list to end up having all of the FLINT modules and generating all of the .pxd files.

The script only extracts functions from the docs but not structs or macros. I moved one macro to flint.pxd but otherwise I factored out the structs from these files into a flint_types.pxd. The structs still need to be edited manually but we should organise them according to the way they are in the flint headers:

$ ls ../flint/src/*type*
../flint/src/acb_types.h   ../flint/src/fmpz_mod_types.h  ../flint/src/limb_types.h
../flint/src/acf_types.h   ../flint/src/fmpz_types.h      ../flint/src/mpoly_types.h
../flint/src/arb_types.h   ../flint/src/fq_nmod_types.h   ../flint/src/nmod_types.h
../flint/src/arf_types.h   ../flint/src/fq_types.h        ../flint/src/n_poly_types.h
../flint/src/ca_types.h    ../flint/src/fq_zech_types.h   ../flint/src/padic_types.h
../flint/src/fmpq_types.h  ../flint/src/gr_types.h

I checked the structs against the FLINT code and updating some things like long -> slong or mp_limb -> ulong.

There was one function missing from the docs fmpz_factor_expand which I manually added to flint_types.pxd.

Running the script like this has also update the types and names in a bunch of function definitions.

We should do this for all of the auto-generated files so that they can be kept up to date in a single command and then we can just add the entire lot in one go.

See also #54 which discusses auto-generating cython bindings for every Flint function.

@oscarbenjamin oscarbenjamin merged commit 137e7a6 into flintlib:main Sep 4, 2024
40 checks passed
@oscarbenjamin oscarbenjamin deleted the pr_auto_pxd branch September 4, 2024 00:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant