diff --git a/.github/workflows/buildwheel.yml b/.github/workflows/buildwheel.yml index 3a4573ba..c4ab36ee 100644 --- a/.github/workflows/buildwheel.yml +++ b/.github/workflows/buildwheel.yml @@ -111,8 +111,8 @@ jobs: strategy: fail-fast: false matrix: - python-version: ['3.11', '3.12'] - # '.' means install from git checkout + python-version: ['3.11', '3.12', '3.13-dev'] + # '.' means install from python-flint git checkout # 'python-flint' means install from PyPI sdist target: ['.', 'python-flint'] steps: @@ -122,3 +122,19 @@ jobs: python-version: ${{ matrix.python-version }} - run: bin/pip_install_ubuntu.sh ${{ matrix.target }} - run: python -m flint.test --verbose + + test_flint_versions: + name: Test flint ${{ matrix.flinttag }} + runs-on: ubuntu-22.04 + strategy: + fail-fast: false + matrix: + # minimum supported version and latest git + flinttag: ['v3.0.0', 'main'] + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: 3.12 + - run: bin/pip_install_ubuntu.sh . ${{ matrix.flinttag }} + - run: python -m flint.test --verbose diff --git a/bin/pip_install_ubuntu.sh b/bin/pip_install_ubuntu.sh index b1c25444..41f9bf96 100755 --- a/bin/pip_install_ubuntu.sh +++ b/bin/pip_install_ubuntu.sh @@ -4,13 +4,32 @@ set -o errexit # This script should work to install python-flint on Ubuntu from a VCS checkout # -# $ git checkout https://github.com/flintlib/python-flint.git +# $ git clone https://github.com/flintlib/python-flint.git +# $ cd python-flint # $ bin/pip_install_ubuntu.sh . # # To install an sdist from PyPI, use # # $ bin/pip_install_ubuntu.sh python-flint # +# The Flint version to build can be provided as an argument, e.g. +# +# $ bin/pip_install_ubuntu.sh python-flint v3.0.1 +# +# The version is a tag or branch in the Flint repository. If not provided, the +# script will default to downloading the release tarball hard-coded below. Only +# Flint 3 or newer will work. + +if [ -z "$2" ]; then + echo "Building from release tarball" + FLINT_GIT="" + FLINTVER=3.0.1 +else + echo "Building from git: $2" + FLINT_GIT=$2 +fi +# Either . or python-flint. Passed to pip install +PYTHON_FLINT=$1 # Install runtime and build dependencies @@ -18,8 +37,19 @@ set -o errexit sudo apt-get update sudo apt-get install libgmp-dev libmpfr-dev xz-utils -# Only Flint 3 or newer will work. -FLINTVER=3.0.0 +if [ -z "$FLINT_GIT" ]; then + # Install from release tarball + echo "Installing Flint $FLINTVER from release tarball" + curl -O -L https://www.flintlib.org/flint-$FLINTVER.tar.gz + tar xf flint-$FLINTVER.tar.gz + cd flint-$FLINTVER +else + # Install from git + echo "Installing Flint from git: $FLINT_GIT" + git clone https://github.com/flintlib/flint.git + cd flint + git checkout $FLINT_GIT +fi # This will default to installing in /usr/local. If you want to install in a # non-standard location then configure flint with @@ -28,25 +58,21 @@ FLINTVER=3.0.0 # export C_INCLUDE_PATH=$PREFIX/include # and at runtime set # export LD_LIBRARY_PATH=$PREFIX/lib - -curl -O -L https://www.flintlib.org/flint-$FLINTVER.tar.gz -tar xf flint-$FLINTVER.tar.gz -cd flint-$FLINTVER - ./bootstrap.sh - ./configure --disable-static - make -j - sudo make install +./bootstrap.sh +./configure --disable-static +make -j +sudo make install cd .. ls -l /usr/local/lib sudo ldconfig /usr/local/lib -# Install from checkout (or sdist). +# Build python-flint from sdist echo ----------------------------------------------------------- echo echo Running: -echo $ pip install --no-binary python-flint $1 +echo $ pip install --no-binary python-flint $PYTHON_FLINT echo echo ----------------------------------------------------------- -pip install --no-binary python-flint $1 +pip install --no-binary python-flint $PYTHON_FLINT \ No newline at end of file diff --git a/src/flint/__init__.py b/src/flint/__init__.py index fcb62cf3..9a8fb4c5 100644 --- a/src/flint/__init__.py +++ b/src/flint/__init__.py @@ -33,4 +33,9 @@ from .types.dirichlet import * from .functions.showgood import good, showgood +from .flint_base.flint_base import ( + FLINT_VERSION as __FLINT_VERSION__, + FLINT_RELEASE as __FLINT_RELEASE__, +) + __version__ = '0.6.0' diff --git a/src/flint/flint_base/flint_base.pyx b/src/flint/flint_base/flint_base.pyx index 7d42d397..89c58b68 100644 --- a/src/flint/flint_base/flint_base.pyx +++ b/src/flint/flint_base/flint_base.pyx @@ -1,7 +1,16 @@ -from flint.flintlib.flint cimport FLINT_BITS as _FLINT_BITS +from flint.flintlib.flint cimport ( + FLINT_BITS as _FLINT_BITS, + FLINT_VERSION as _FLINT_VERSION, + __FLINT_RELEASE as _FLINT_RELEASE, +) from flint.flint_base.flint_context cimport thectx +FLINT_BITS = _FLINT_BITS +FLINT_VERSION = _FLINT_VERSION.decode("ascii") +FLINT_RELEASE = _FLINT_RELEASE + + cdef class flint_elem: def __repr__(self): if thectx.pretty: diff --git a/src/flint/flintlib/flint.pxd b/src/flint/flintlib/flint.pxd index 51950f47..739cc9d2 100644 --- a/src/flint/flintlib/flint.pxd +++ b/src/flint/flintlib/flint.pxd @@ -37,6 +37,8 @@ cdef extern from "flint/fmpz.h": ctypedef slong fmpz_struct cdef extern from "flint/flint.h": + const char * FLINT_VERSION + const int __FLINT_RELEASE const int FLINT_BITS ctypedef void * flint_rand_t void flint_randinit(flint_rand_t state) diff --git a/src/flint/flintlib/fmpz_mod_mat.pxd b/src/flint/flintlib/fmpz_mod_mat.pxd index c1b08f48..22f1b181 100644 --- a/src/flint/flintlib/fmpz_mod_mat.pxd +++ b/src/flint/flintlib/fmpz_mod_mat.pxd @@ -1,4 +1,10 @@ -from flint.flintlib.flint cimport ulong, slong, fmpz_struct, flint_rand_t +from flint.flintlib.flint cimport ( + __FLINT_RELEASE, + ulong, + slong, + fmpz_struct, + flint_rand_t +) from flint.flintlib.fmpz cimport fmpz_t from flint.flintlib.fmpz_mod cimport fmpz_mod_ctx_t from flint.flintlib.fmpz_mat cimport fmpz_mat_t @@ -12,64 +18,124 @@ cdef extern from "flint/fmpz_mod_mat.h": ctypedef fmpz_mod_mat_struct fmpz_mod_mat_t[1] -cdef extern from "flint/fmpz_mod_mat.h": - # This is not exposed in the docs: - int fmpz_mod_mat_equal(const fmpz_mod_mat_t mat1, const fmpz_mod_mat_t mat2); +cdef extern from *: + """ + /* + * fmpz_mod_mat function signatures were changed in FLINT 3.1.0 + */ + #if __FLINT_RELEASE >= 30100 /* Flint 3.1.0 or later */ + + #define compat_fmpz_mod_mat_init(mat, rows, cols, ctx) fmpz_mod_mat_init(mat, rows, cols, ctx) + #define compat_fmpz_mod_mat_init_set(mat, src, ctx) fmpz_mod_mat_init_set(mat, src, ctx) + #define compat_fmpz_mod_mat_clear(mat, ctx) fmpz_mod_mat_clear(mat, ctx) + #define compat_fmpz_mod_mat_set(A, B, ctx) fmpz_mod_mat_set(A, B, ctx) + #define compat_fmpz_mod_mat_nrows(mat, ctx) fmpz_mod_mat_nrows(mat, ctx) + #define compat_fmpz_mod_mat_ncols(mat, ctx) fmpz_mod_mat_ncols(mat, ctx) + #define compat_fmpz_mod_mat_entry(mat, i, j) fmpz_mod_mat_entry(mat, i, j) + #define compat_fmpz_mod_mat_set_entry(mat, i, j, val, ctx) fmpz_mod_mat_set_entry(mat, i, j, val, ctx) + #define compat_fmpz_mod_mat_one(mat, ctx) fmpz_mod_mat_one(mat, ctx) + #define compat_fmpz_mod_mat_equal(mat1, mat2, ctx) fmpz_mod_mat_equal(mat1, mat2, ctx) + #define compat_fmpz_mod_mat_is_zero(mat, ctx) fmpz_mod_mat_is_zero(mat, ctx) + #define compat_fmpz_mod_mat_neg(B, A, ctx) fmpz_mod_mat_neg(B, A, ctx) + #define compat_fmpz_mod_mat_add(C, A, B, ctx) fmpz_mod_mat_add(C, A, B, ctx) + #define compat_fmpz_mod_mat_sub(C, A, B, ctx) fmpz_mod_mat_sub(C, A, B, ctx) + #define compat_fmpz_mod_mat_scalar_mul_fmpz(B, A, c, ctx) fmpz_mod_mat_scalar_mul_fmpz(B, A, c, ctx) + #define compat_fmpz_mod_mat_mul(C, A, B, ctx) fmpz_mod_mat_mul(C, A, B, ctx) + #define compat_fmpz_mod_mat_inv(B, A, ctx) fmpz_mod_mat_inv(B, A, ctx) + #define compat_fmpz_mod_mat_transpose(B, A, ctx) fmpz_mod_mat_transpose(B, A, ctx) + #define compat_fmpz_mod_mat_solve(X, A, B, ctx) fmpz_mod_mat_solve(X, A, B, ctx) + #define compat_fmpz_mod_mat_rref(mat, ctx) fmpz_mod_mat_rref(mat, mat, ctx) + #define compat_fmpz_mod_mat_charpoly(p, M, ctx) fmpz_mod_mat_charpoly(p, M, ctx) + #define compat_fmpz_mod_mat_minpoly(p, M, ctx) fmpz_mod_mat_minpoly(p, M, ctx) + + #else /* Flint 3.0.0 or 3.0.1 */ + + #define compat_fmpz_mod_mat_init(mat, rows, cols, ctx) fmpz_mod_mat_init(mat, rows, cols, ctx->n) + #define compat_fmpz_mod_mat_init_set(mat, src, ctx) fmpz_mod_mat_init_set(mat, src) + #define compat_fmpz_mod_mat_clear(mat, ctx) fmpz_mod_mat_clear(mat) + #define compat_fmpz_mod_mat_set(A, B, ctx) fmpz_mod_mat_set(A, B) + #define compat_fmpz_mod_mat_nrows(mat, ctx) fmpz_mod_mat_nrows(mat) + #define compat_fmpz_mod_mat_ncols(mat, ctx) fmpz_mod_mat_ncols(mat) + #define compat_fmpz_mod_mat_entry(mat, i, j) fmpz_mod_mat_entry(mat, i, j) + #define compat_fmpz_mod_mat_set_entry(mat, i, j, val, ctx) fmpz_mod_mat_set_entry(mat, i, j, val) + #define compat_fmpz_mod_mat_one(mat, ctx) fmpz_mod_mat_one(mat) + #define compat_fmpz_mod_mat_equal(mat1, mat2, ctx) fmpz_mod_mat_equal(mat1, mat2) + #define compat_fmpz_mod_mat_is_zero(mat, ctx) fmpz_mod_mat_is_zero(mat) + #define compat_fmpz_mod_mat_neg(B, A, ctx) fmpz_mod_mat_neg(B, A) + #define compat_fmpz_mod_mat_add(C, A, B, ctx) fmpz_mod_mat_add(C, A, B) + #define compat_fmpz_mod_mat_sub(C, A, B, ctx) fmpz_mod_mat_sub(C, A, B) + #define compat_fmpz_mod_mat_scalar_mul_fmpz(B, A, c, ctx) fmpz_mod_mat_scalar_mul_fmpz(B, A, c) + #define compat_fmpz_mod_mat_mul(C, A, B, ctx) fmpz_mod_mat_mul(C, A, B) + #define compat_fmpz_mod_mat_inv(B, A, ctx) fmpz_mod_mat_inv(B, A) + #define compat_fmpz_mod_mat_transpose(B, A, ctx) fmpz_mod_mat_transpose(B, A) + #define compat_fmpz_mod_mat_solve(X, A, B, ctx) fmpz_mod_mat_solve(X, A, B) + #define compat_fmpz_mod_mat_rref(mat, ctx) fmpz_mod_mat_rref(NULL, mat) + #define compat_fmpz_mod_mat_charpoly(p, M, ctx) fmpz_mod_mat_charpoly(p, M, ctx) + #define compat_fmpz_mod_mat_minpoly(p, M, ctx) fmpz_mod_mat_minpoly(p, M, ctx) + + #endif + """ cdef extern from "flint/fmpz_mod_mat.h": - fmpz_struct * fmpz_mod_mat_entry(const fmpz_mod_mat_t mat, slong i, slong j) - void fmpz_mod_mat_set_entry(fmpz_mod_mat_t mat, slong i, slong j, const fmpz_t val) - void fmpz_mod_mat_init(fmpz_mod_mat_t mat, slong rows, slong cols, const fmpz_t n) - void fmpz_mod_mat_init_set(fmpz_mod_mat_t mat, const fmpz_mod_mat_t src) - void fmpz_mod_mat_clear(fmpz_mod_mat_t mat) - slong fmpz_mod_mat_nrows(const fmpz_mod_mat_t mat) - slong fmpz_mod_mat_ncols(const fmpz_mod_mat_t mat) - void _fmpz_mod_mat_set_mod(fmpz_mod_mat_t mat, const fmpz_t n) - void fmpz_mod_mat_one(fmpz_mod_mat_t mat) - void fmpz_mod_mat_zero(fmpz_mod_mat_t mat) - void fmpz_mod_mat_swap(fmpz_mod_mat_t mat1, fmpz_mod_mat_t mat2) - void fmpz_mod_mat_swap_entrywise(fmpz_mod_mat_t mat1, fmpz_mod_mat_t mat2) - int fmpz_mod_mat_is_empty(const fmpz_mod_mat_t mat) - int fmpz_mod_mat_is_square(const fmpz_mod_mat_t mat) - void _fmpz_mod_mat_reduce(fmpz_mod_mat_t mat) - void fmpz_mod_mat_randtest(fmpz_mod_mat_t mat, flint_rand_t state) - void fmpz_mod_mat_window_init(fmpz_mod_mat_t window, const fmpz_mod_mat_t mat, slong r1, slong c1, slong r2, slong c2) - void fmpz_mod_mat_window_clear(fmpz_mod_mat_t window) - void fmpz_mod_mat_concat_horizontal(fmpz_mod_mat_t res, const fmpz_mod_mat_t mat1, const fmpz_mod_mat_t mat2) - void fmpz_mod_mat_concat_vertical(fmpz_mod_mat_t res, const fmpz_mod_mat_t mat1, const fmpz_mod_mat_t mat2) - void fmpz_mod_mat_print_pretty(const fmpz_mod_mat_t mat) - int fmpz_mod_mat_is_zero(const fmpz_mod_mat_t mat) - void fmpz_mod_mat_set(fmpz_mod_mat_t B, const fmpz_mod_mat_t A) - void fmpz_mod_mat_transpose(fmpz_mod_mat_t B, const fmpz_mod_mat_t A) - void fmpz_mod_mat_set_fmpz_mat(fmpz_mod_mat_t A, const fmpz_mat_t B) - void fmpz_mod_mat_get_fmpz_mat(fmpz_mat_t A, const fmpz_mod_mat_t B) - void fmpz_mod_mat_add(fmpz_mod_mat_t C, const fmpz_mod_mat_t A, const fmpz_mod_mat_t B) - void fmpz_mod_mat_sub(fmpz_mod_mat_t C, const fmpz_mod_mat_t A, const fmpz_mod_mat_t B) - void fmpz_mod_mat_neg(fmpz_mod_mat_t B, const fmpz_mod_mat_t A) - void fmpz_mod_mat_scalar_mul_si(fmpz_mod_mat_t B, const fmpz_mod_mat_t A, slong c) - void fmpz_mod_mat_scalar_mul_ui(fmpz_mod_mat_t B, const fmpz_mod_mat_t A, ulong c) - void fmpz_mod_mat_scalar_mul_fmpz(fmpz_mod_mat_t B, const fmpz_mod_mat_t A, fmpz_t c) - void fmpz_mod_mat_mul(fmpz_mod_mat_t C, const fmpz_mod_mat_t A, const fmpz_mod_mat_t B) - # unimported types {'thread_pool_handle'} - # void _fmpz_mod_mat_mul_classical_threaded_pool_op(fmpz_mod_mat_t D, const fmpz_mod_mat_t C, const fmpz_mod_mat_t A, const fmpz_mod_mat_t B, int op, thread_pool_handle * threads, slong num_threads) - void _fmpz_mod_mat_mul_classical_threaded_op(fmpz_mod_mat_t D, const fmpz_mod_mat_t C, const fmpz_mod_mat_t A, const fmpz_mod_mat_t B, int op) - void fmpz_mod_mat_mul_classical_threaded(fmpz_mod_mat_t C, const fmpz_mod_mat_t A, const fmpz_mod_mat_t B) - void fmpz_mod_mat_sqr(fmpz_mod_mat_t B, const fmpz_mod_mat_t A) - void fmpz_mod_mat_mul_fmpz_vec(fmpz_struct * c, const fmpz_mod_mat_t A, const fmpz_struct * b, slong blen) - void fmpz_mod_mat_mul_fmpz_vec_ptr(fmpz_struct * const * c, const fmpz_mod_mat_t A, const fmpz_struct * const * b, slong blen) - void fmpz_mod_mat_fmpz_vec_mul(fmpz_struct * c, const fmpz_struct * a, slong alen, const fmpz_mod_mat_t B) - void fmpz_mod_mat_fmpz_vec_mul_ptr(fmpz_struct * const * c, const fmpz_struct * const * a, slong alen, const fmpz_mod_mat_t B) - void fmpz_mod_mat_trace(fmpz_t trace, const fmpz_mod_mat_t mat) - slong fmpz_mod_mat_rref(slong * perm, fmpz_mod_mat_t mat) - void fmpz_mod_mat_strong_echelon_form(fmpz_mod_mat_t mat) - slong fmpz_mod_mat_howell_form(fmpz_mod_mat_t mat) - int fmpz_mod_mat_inv(fmpz_mod_mat_t B, fmpz_mod_mat_t A) - slong fmpz_mod_mat_lu(slong * P, fmpz_mod_mat_t A, int rank_check) - void fmpz_mod_mat_solve_tril(fmpz_mod_mat_t X, const fmpz_mod_mat_t L, const fmpz_mod_mat_t B, int unit) - void fmpz_mod_mat_solve_triu(fmpz_mod_mat_t X, const fmpz_mod_mat_t U, const fmpz_mod_mat_t B, int unit) - int fmpz_mod_mat_solve(fmpz_mod_mat_t X, const fmpz_mod_mat_t A, const fmpz_mod_mat_t B) - int fmpz_mod_mat_can_solve(fmpz_mod_mat_t X, const fmpz_mod_mat_t A, const fmpz_mod_mat_t B) - void fmpz_mod_mat_similarity(fmpz_mod_mat_t M, slong r, fmpz_t d) - void fmpz_mod_mat_charpoly(fmpz_mod_poly_t p, const fmpz_mod_mat_t M, const fmpz_mod_ctx_t ctx) - void fmpz_mod_mat_minpoly(fmpz_mod_poly_t p, const fmpz_mod_mat_t M, const fmpz_mod_ctx_t ctx) + void compat_fmpz_mod_mat_init(fmpz_mod_mat_t mat, slong rows, slong cols, const fmpz_mod_ctx_t ctx) + void compat_fmpz_mod_mat_init_set(fmpz_mod_mat_t mat, const fmpz_mod_mat_t src, const fmpz_mod_ctx_t ctx) + void compat_fmpz_mod_mat_clear(fmpz_mod_mat_t mat, fmpz_mod_ctx_t ctx) + void compat_fmpz_mod_mat_set(fmpz_mod_mat_t B, const fmpz_mod_mat_t A, const fmpz_mod_ctx_t ctx) + slong compat_fmpz_mod_mat_nrows(const fmpz_mod_mat_t mat, const fmpz_mod_ctx_t ctx) + slong compat_fmpz_mod_mat_ncols(const fmpz_mod_mat_t mat, const fmpz_mod_ctx_t ctx) + fmpz_struct * compat_fmpz_mod_mat_entry(const fmpz_mod_mat_t mat, slong i, slong j) + void compat_fmpz_mod_mat_set_entry(fmpz_mod_mat_t mat, slong i, slong j, const fmpz_t val, const fmpz_mod_ctx_t ctx) + void compat_fmpz_mod_mat_one(fmpz_mod_mat_t mat, const fmpz_mod_ctx_t ctx) + int compat_fmpz_mod_mat_equal(const fmpz_mod_mat_t mat1, const fmpz_mod_mat_t mat2, const fmpz_mod_ctx_t ctx) + int compat_fmpz_mod_mat_is_zero(const fmpz_mod_mat_t mat, const fmpz_mod_ctx_t ctx) + void compat_fmpz_mod_mat_neg(fmpz_mod_mat_t B, const fmpz_mod_mat_t A, const fmpz_mod_ctx_t ctx) + void compat_fmpz_mod_mat_add(fmpz_mod_mat_t C, const fmpz_mod_mat_t A, const fmpz_mod_mat_t B, const fmpz_mod_ctx_t ctx) + void compat_fmpz_mod_mat_sub(fmpz_mod_mat_t C, const fmpz_mod_mat_t A, const fmpz_mod_mat_t B, const fmpz_mod_ctx_t ctx) + void compat_fmpz_mod_mat_scalar_mul_fmpz(fmpz_mod_mat_t B, const fmpz_mod_mat_t A, fmpz_t c, const fmpz_mod_ctx_t ctx) + void compat_fmpz_mod_mat_mul(fmpz_mod_mat_t C, const fmpz_mod_mat_t A, const fmpz_mod_mat_t B, const fmpz_mod_ctx_t ctx) + int compat_fmpz_mod_mat_inv(fmpz_mod_mat_t B, fmpz_mod_mat_t A, const fmpz_mod_ctx_t ctx) + void compat_fmpz_mod_mat_transpose(fmpz_mod_mat_t B, const fmpz_mod_mat_t A, const fmpz_mod_ctx_t ctx) + int compat_fmpz_mod_mat_solve(fmpz_mod_mat_t X, const fmpz_mod_mat_t A, const fmpz_mod_mat_t B, const fmpz_mod_ctx_t ctx) + slong compat_fmpz_mod_mat_rref(fmpz_mod_mat_t mat, const fmpz_mod_ctx_t ctx) + void compat_fmpz_mod_mat_charpoly(fmpz_mod_poly_t p, const fmpz_mod_mat_t M, const fmpz_mod_ctx_t ctx) + void compat_fmpz_mod_mat_minpoly(fmpz_mod_poly_t p, const fmpz_mod_mat_t M, const fmpz_mod_ctx_t ctx) + # + # The functions below are unused. The signatures shown are for Flint < 3.1.0 + # Probably compat_ versions are needed but each signature should be checked + # against Flint 3.1.0 or later. For now we comment these out. + # + # void _fmpz_mod_mat_set_mod(fmpz_mod_mat_t mat, const fmpz_t n) + # void fmpz_mod_mat_zero(fmpz_mod_mat_t mat) + # void fmpz_mod_mat_swap(fmpz_mod_mat_t mat1, fmpz_mod_mat_t mat2) + # void fmpz_mod_mat_swap_entrywise(fmpz_mod_mat_t mat1, fmpz_mod_mat_t mat2) + # int fmpz_mod_mat_is_empty(const fmpz_mod_mat_t mat) + # int fmpz_mod_mat_is_square(const fmpz_mod_mat_t mat) + # void _fmpz_mod_mat_reduce(fmpz_mod_mat_t mat) + # void fmpz_mod_mat_randtest(fmpz_mod_mat_t mat, flint_rand_t state) + # void fmpz_mod_mat_window_init(fmpz_mod_mat_t window, const fmpz_mod_mat_t mat, slong r1, slong c1, slong r2, slong c2) + # void fmpz_mod_mat_window_clear(fmpz_mod_mat_t window) + # void fmpz_mod_mat_concat_horizontal(fmpz_mod_mat_t res, const fmpz_mod_mat_t mat1, const fmpz_mod_mat_t mat2) + # void fmpz_mod_mat_concat_vertical(fmpz_mod_mat_t res, const fmpz_mod_mat_t mat1, const fmpz_mod_mat_t mat2) + # void fmpz_mod_mat_print_pretty(const fmpz_mod_mat_t mat) + # void fmpz_mod_mat_set_fmpz_mat(fmpz_mod_mat_t A, const fmpz_mat_t B) + # void fmpz_mod_mat_get_fmpz_mat(fmpz_mat_t A, const fmpz_mod_mat_t B) + # void fmpz_mod_mat_scalar_mul_si(fmpz_mod_mat_t B, const fmpz_mod_mat_t A, slong c) + # void fmpz_mod_mat_scalar_mul_ui(fmpz_mod_mat_t B, const fmpz_mod_mat_t A, ulong c) + # # unimported types {'thread_pool_handle'} + # # void _fmpz_mod_mat_mul_classical_threaded_pool_op(fmpz_mod_mat_t D, const fmpz_mod_mat_t C, const fmpz_mod_mat_t A, const fmpz_mod_mat_t B, int op, thread_pool_handle * threads, slong num_threads) + # void _fmpz_mod_mat_mul_classical_threaded_op(fmpz_mod_mat_t D, const fmpz_mod_mat_t C, const fmpz_mod_mat_t A, const fmpz_mod_mat_t B, int op) + # void fmpz_mod_mat_mul_classical_threaded(fmpz_mod_mat_t C, const fmpz_mod_mat_t A, const fmpz_mod_mat_t B) + # void fmpz_mod_mat_sqr(fmpz_mod_mat_t B, const fmpz_mod_mat_t A) + # void fmpz_mod_mat_mul_fmpz_vec(fmpz_struct * c, const fmpz_mod_mat_t A, const fmpz_struct * b, slong blen) + # void fmpz_mod_mat_mul_fmpz_vec_ptr(fmpz_struct * const * c, const fmpz_mod_mat_t A, const fmpz_struct * const * b, slong blen) + # void fmpz_mod_mat_fmpz_vec_mul(fmpz_struct * c, const fmpz_struct * a, slong alen, const fmpz_mod_mat_t B) + # void fmpz_mod_mat_fmpz_vec_mul_ptr(fmpz_struct * const * c, const fmpz_struct * const * a, slong alen, const fmpz_mod_mat_t B) + # void fmpz_mod_mat_trace(fmpz_t trace, const fmpz_mod_mat_t mat) + # void fmpz_mod_mat_strong_echelon_form(fmpz_mod_mat_t mat) + # slong fmpz_mod_mat_howell_form(fmpz_mod_mat_t mat) + # slong fmpz_mod_mat_lu(slong * P, fmpz_mod_mat_t A, int rank_check) + # void fmpz_mod_mat_solve_tril(fmpz_mod_mat_t X, const fmpz_mod_mat_t L, const fmpz_mod_mat_t B, int unit) + # void fmpz_mod_mat_solve_triu(fmpz_mod_mat_t X, const fmpz_mod_mat_t U, const fmpz_mod_mat_t B, int unit) + # int fmpz_mod_mat_can_solve(fmpz_mod_mat_t X, const fmpz_mod_mat_t A, const fmpz_mod_mat_t B) + # void fmpz_mod_mat_similarity(fmpz_mod_mat_t M, slong r, fmpz_t d) diff --git a/src/flint/types/fmpz_mod_mat.pyx b/src/flint/types/fmpz_mod_mat.pyx index 2635f3ac..0049ad39 100644 --- a/src/flint/types/fmpz_mod_mat.pyx +++ b/src/flint/types/fmpz_mod_mat.pyx @@ -8,28 +8,28 @@ from flint.flintlib.fmpz cimport ( fmpz_set, ) from flint.flintlib.fmpz_mod_mat cimport ( - fmpz_mod_mat_init, - fmpz_mod_mat_init_set, - fmpz_mod_mat_clear, - fmpz_mod_mat_set, - fmpz_mod_mat_nrows, - fmpz_mod_mat_ncols, - fmpz_mod_mat_entry, - fmpz_mod_mat_set_entry, - fmpz_mod_mat_one, - fmpz_mod_mat_equal, - fmpz_mod_mat_is_zero, - fmpz_mod_mat_neg, - fmpz_mod_mat_add, - fmpz_mod_mat_sub, - fmpz_mod_mat_mul, - fmpz_mod_mat_scalar_mul_fmpz, - fmpz_mod_mat_inv, - fmpz_mod_mat_transpose, - fmpz_mod_mat_solve, - fmpz_mod_mat_rref, - fmpz_mod_mat_charpoly, - fmpz_mod_mat_minpoly, + compat_fmpz_mod_mat_init, + compat_fmpz_mod_mat_init_set, + compat_fmpz_mod_mat_clear, + compat_fmpz_mod_mat_set, + compat_fmpz_mod_mat_nrows, + compat_fmpz_mod_mat_ncols, + compat_fmpz_mod_mat_entry, + compat_fmpz_mod_mat_set_entry, + compat_fmpz_mod_mat_one, + compat_fmpz_mod_mat_equal, + compat_fmpz_mod_mat_is_zero, + compat_fmpz_mod_mat_neg, + compat_fmpz_mod_mat_add, + compat_fmpz_mod_mat_sub, + compat_fmpz_mod_mat_mul, + compat_fmpz_mod_mat_scalar_mul_fmpz, + compat_fmpz_mod_mat_inv, + compat_fmpz_mod_mat_transpose, + compat_fmpz_mod_mat_solve, + compat_fmpz_mod_mat_rref, + compat_fmpz_mod_mat_charpoly, + compat_fmpz_mod_mat_minpoly, ) from flint.flint_base.flint_base cimport ( @@ -83,7 +83,7 @@ cdef class fmpz_mod_mat(flint_mat): """ def __dealloc__(self): if self._initialized: - fmpz_mod_mat_clear(self.val) + compat_fmpz_mod_mat_clear(self.val, self.ctx.val) def __init__(self, *args): """Construct an ``fmpz_mod_mat`` matrix. @@ -152,7 +152,7 @@ cdef class fmpz_mod_mat(flint_mat): cdef void _init_empty_ctx(self, slong m, slong n, fmpz_mod_ctx ctx): """Initialize an empty matrix with a given modulus context.""" self.ctx = ctx - fmpz_mod_mat_init(self.val, m, n, ctx.val.n) + compat_fmpz_mod_mat_init(self.val, m, n, ctx.val) self._initialized = True cdef void _init_empty(self, slong m, slong n, list args): @@ -175,7 +175,7 @@ cdef class fmpz_mod_mat(flint_mat): if val is NotImplemented: raise TypeError("fmpz_mod_mat: incompatible entries") e = val - fmpz_mod_mat_set_entry(self.val, i, j, e.val) + compat_fmpz_mod_mat_set_entry(self.val, i, j, e.val, ctx.val) # XXX: Should be possible to type this as flint_mat but nmod_mat is not a subclass # cdef void _init_from_matrix(self, flint_mat M, list args): @@ -192,7 +192,7 @@ cdef class fmpz_mod_mat(flint_mat): ctx = N1.ctx if N1.ctx != ctx: raise TypeError("fmpz_mod_mat: incompatible moduli") - fmpz_mod_mat_init_set(self.val, N1.val) + compat_fmpz_mod_mat_init_set(self.val, N1.val, ctx.val) self.ctx = ctx self._initialized = True elif typecheck(M, fmpz_mat): @@ -216,7 +216,7 @@ cdef class fmpz_mod_mat(flint_mat): """Create an initialized matrix of given shape and context.""" cdef fmpz_mod_mat res res = fmpz_mod_mat.__new__(fmpz_mod_mat) - fmpz_mod_mat_init(res.val, m, n, ctx.val.n) + compat_fmpz_mod_mat_init(res.val, m, n, ctx.val) res.ctx = ctx res._initialized = True return res @@ -229,29 +229,29 @@ cdef class fmpz_mod_mat(flint_mat): """Create a copy of the matrix.""" cdef fmpz_mod_mat res res = self._newlike() - fmpz_mod_mat_set(res.val, self.val) + compat_fmpz_mod_mat_set(res.val, self.val, self.ctx.val) return res cpdef slong nrows(self): """Return the number of rows.""" - return fmpz_mod_mat_nrows(self.val) + return compat_fmpz_mod_mat_nrows(self.val, self.ctx.val) cpdef slong ncols(self): """Return the number of columns.""" - return fmpz_mod_mat_ncols(self.val) + return compat_fmpz_mod_mat_ncols(self.val, self.ctx.val) def modulus(self): """Return the modulus.""" cdef fmpz mod mod = fmpz.__new__(fmpz) - fmpz_init_set(mod.val, self.val.mod) + fmpz_init_set(mod.val, self.ctx.val.n) return mod cdef fmpz_mod _getitem(self, slong i, slong j): """Retrieve an element as an ``fmpz_mod``.""" cdef fmpz_struct * p_e cdef fmpz_mod e - p_e = fmpz_mod_mat_entry(self.val, i, j) + p_e = compat_fmpz_mod_mat_entry(self.val, i, j) e = fmpz_mod.__new__(fmpz_mod) fmpz_set(e.val, p_e) e.ctx = self.ctx @@ -259,7 +259,7 @@ cdef class fmpz_mod_mat(flint_mat): cdef void _setitem(self, slong i, slong j, fmpz_t e): """Set an element from a raw ``fmpz_t``.""" - fmpz_mod_mat_set_entry(self.val, i, j, e) + compat_fmpz_mod_mat_set_entry(self.val, i, j, e, self.ctx.val) def repr(self): """Return a representation string.""" @@ -306,7 +306,7 @@ cdef class fmpz_mod_mat(flint_mat): def __nonzero__(self): """Return ``True`` if the matrix has any nonzero entries.""" cdef bint zero - zero = fmpz_mod_mat_is_zero(self.val) + zero = compat_fmpz_mod_mat_is_zero(self.val, self.ctx.val) return not zero def __richcmp__(self, other, int op): @@ -320,7 +320,10 @@ cdef class fmpz_mod_mat(flint_mat): if other is NotImplemented: return other - res = fmpz_mod_mat_equal((self).val, (other).val) + if (self).ctx != (other).ctx: + res = 0 + else: + res = compat_fmpz_mod_mat_equal((self).val, (other).val, self.ctx.val) if op == 2: return res @@ -334,7 +337,7 @@ cdef class fmpz_mod_mat(flint_mat): def __neg__(self): """``-M``""" res = self._newlike() - fmpz_mod_mat_neg(( res).val, self.val) + compat_fmpz_mod_mat_neg(( res).val, self.val, self.ctx.val) return res def _as_fmpz_mod_mat(self, other, same_shape=True): @@ -353,13 +356,13 @@ cdef class fmpz_mod_mat(flint_mat): def _add(self, fmpz_mod_mat other): """Add two ``fmpz_mod_mat`` matrices.""" res = self._newlike() - fmpz_mod_mat_add(res.val, self.val, other.val) + compat_fmpz_mod_mat_add(res.val, self.val, other.val, self.ctx.val) return res def _sub(self, fmpz_mod_mat other): """Subtract two ``fmpz_mod_mat`` matrices.""" res = self._newlike() - fmpz_mod_mat_sub(res.val, self.val, other.val) + compat_fmpz_mod_mat_sub(res.val, self.val, other.val, self.ctx.val) return res def _matmul(self, fmpz_mod_mat other): @@ -367,13 +370,13 @@ cdef class fmpz_mod_mat(flint_mat): if self.ncols() != other.nrows(): raise ValueError("Shape mismatch: cannot multiply matrices") res = self._new(self.nrows(), other.ncols(), self.ctx) - fmpz_mod_mat_mul(res.val, self.val, other.val) + compat_fmpz_mod_mat_mul(res.val, self.val, other.val, self.ctx.val) return res def _scalarmul(self, fmpz_mod other): """Multiply an ``fmpz_mod_mat`` matrix by an ``fmpz_mod`` scalar.""" res = self._newlike() - fmpz_mod_mat_scalar_mul_fmpz(res.val, self.val, other.val) + compat_fmpz_mod_mat_scalar_mul_fmpz(res.val, self.val, other.val, self.ctx.val) return res def _pow(self, slong other): @@ -387,14 +390,14 @@ cdef class fmpz_mod_mat(flint_mat): other = -other res = self._newlike() - fmpz_mod_mat_one(res.val) + compat_fmpz_mod_mat_one(res.val, self.ctx.val) tmp = self._copy() while other > 0: if other % 2 == 1: - fmpz_mod_mat_mul(res.val, res.val, tmp.val) - fmpz_mod_mat_mul(tmp.val, tmp.val, tmp.val) + compat_fmpz_mod_mat_mul(res.val, res.val, tmp.val, self.ctx.val) + compat_fmpz_mod_mat_mul(tmp.val, tmp.val, tmp.val, self.ctx.val) other //= 2 return res @@ -497,7 +500,7 @@ cdef class fmpz_mod_mat(flint_mat): if self.nrows() != self.ncols(): raise ValueError("fmpz_mod_mat inv: matrix must be square") res = self._newlike() - r = fmpz_mod_mat_inv(res.val, self.val) + r = compat_fmpz_mod_mat_inv(res.val, self.val, self.ctx.val) if r == 0: raise ZeroDivisionError("fmpz_mod_mat inv: matrix is not invertible") return res @@ -537,7 +540,7 @@ cdef class fmpz_mod_mat(flint_mat): pctx = fmpz_mod_poly_ctx(self.ctx) res = fmpz_mod_poly(0, pctx) - fmpz_mod_mat_charpoly(res.val, self.val, self.ctx.val) + compat_fmpz_mod_mat_charpoly(res.val, self.val, self.ctx.val) return res def minpoly(self): @@ -560,7 +563,7 @@ cdef class fmpz_mod_mat(flint_mat): pctx = fmpz_mod_poly_ctx(self.ctx) res = fmpz_mod_poly(0, pctx) - fmpz_mod_mat_minpoly(res.val, self.val, self.ctx.val) + compat_fmpz_mod_mat_minpoly(res.val, self.val, self.ctx.val) return res def transpose(self): @@ -578,7 +581,7 @@ cdef class fmpz_mod_mat(flint_mat): """ cdef fmpz_mod_mat res res = self._new(self.ncols(), self.nrows(), self.ctx) - fmpz_mod_mat_transpose(res.val, self.val) + compat_fmpz_mod_mat_transpose(res.val, self.val, self.ctx.val) return res def solve(self, rhs): @@ -609,7 +612,7 @@ cdef class fmpz_mod_mat(flint_mat): raise ValueError("fmpz_mod_mat solve: shape mismatch") res = self._new(rhs.nrows(), rhs.ncols(), self.ctx) - success = fmpz_mod_mat_solve(res.val, self.val, ( rhs).val) + success = compat_fmpz_mod_mat_solve(res.val, self.val, ( rhs).val, self.ctx.val) if not success: raise ZeroDivisionError("Singular matrix in solve") @@ -652,5 +655,5 @@ cdef class fmpz_mod_mat(flint_mat): res = self else: res = self._copy() - r = fmpz_mod_mat_rref(NULL, res.val) + r = compat_fmpz_mod_mat_rref(res.val, res.ctx.val) return (res, r)