From 4d1cee821efe8406d53cfaea5ae2a40ce6046e6b Mon Sep 17 00:00:00 2001 From: Oscar Benjamin Date: Fri, 2 Feb 2024 16:59:58 +0000 Subject: [PATCH 01/10] Remove --no-build-isolation in test build script --- bin/pip_install_ubuntu.sh | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/bin/pip_install_ubuntu.sh b/bin/pip_install_ubuntu.sh index ac9d9491..16817354 100755 --- a/bin/pip_install_ubuntu.sh +++ b/bin/pip_install_ubuntu.sh @@ -19,7 +19,7 @@ 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 +FLINTVER=3.0.1 # This will default to installing in /usr/local. If you want to install in a # non-standard location then configure flint with @@ -41,16 +41,12 @@ cd .. ls -l /usr/local/lib sudo ldconfig /usr/local/lib -# Python build requirements. Ideally these would be in pyproject.toml, but -# first need to migrate from setup.py to pyproject.toml. -pip install numpy cython setuptools wheel - # Install from checkout (or sdist). echo ----------------------------------------------------------- echo echo Running: -echo $ pip install --no-binary :all: --no-build-isolation $1 +echo $ pip install --no-binary :all: $1 echo echo ----------------------------------------------------------- -pip install --no-binary :all: --no-build-isolation $1 +pip install --no-binary :all: $1 From eead34541f2a42daf49e2e446982bdb76c0893eb Mon Sep 17 00:00:00 2001 From: Oscar Benjamin Date: Fri, 2 Feb 2024 17:00:56 +0000 Subject: [PATCH 02/10] Add CPython 3.13 to test matrix --- .github/workflows/buildwheel.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/buildwheel.yml b/.github/workflows/buildwheel.yml index 4d7ce6c8..eaacd33d 100644 --- a/.github/workflows/buildwheel.yml +++ b/.github/workflows/buildwheel.yml @@ -124,7 +124,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ['3.11', '3.12'] + python-version: ['3.11', '3.12', '3.13-dev'] # '.' means install from git checkout # 'python-flint' means install from PyPI sdist target: ['.', 'python-flint'] From 267e31a995993f181c79e7c89317b47ee36a55d7 Mon Sep 17 00:00:00 2001 From: Oscar Benjamin Date: Fri, 2 Feb 2024 17:37:29 +0000 Subject: [PATCH 03/10] Test with flint 3.0.0 and also git main --- .github/workflows/buildwheel.yml | 18 +++++++++- bin/pip_install_ubuntu.sh | 56 +++++++++++++++++++++++--------- 2 files changed, 58 insertions(+), 16 deletions(-) diff --git a/.github/workflows/buildwheel.yml b/.github/workflows/buildwheel.yml index eaacd33d..f02dff7d 100644 --- a/.github/workflows/buildwheel.yml +++ b/.github/workflows/buildwheel.yml @@ -125,7 +125,7 @@ jobs: fail-fast: false matrix: python-version: ['3.11', '3.12', '3.13-dev'] - # '.' means install from git checkout + # '.' means install from python-flint git checkout # 'python-flint' means install from PyPI sdist target: ['.', 'python-flint'] steps: @@ -135,3 +135,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: pip install ${{ matrix.target }} on ${{ matrix.python-version }} + runs-on: ubuntu-22.04 + strategy: + fail-fast: false + matrix: + # minimum supported version and latest git + flint: ['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.flint }} + - run: python -m flint.test --verbose diff --git a/bin/pip_install_ubuntu.sh b/bin/pip_install_ubuntu.sh index 16817354..6229795c 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,9 +37,6 @@ 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.1 - # This will default to installing in /usr/local. If you want to install in a # non-standard location then configure flint with # ./configure --disable-static --prefix=$PREFIX @@ -29,24 +45,34 @@ FLINTVER=3.0.1 # 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 -cd .. +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 + +./bootstrap.sh +./configure --disable-static +make -j +sudo make install 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 :all: $1 +echo $ pip install --no-binary :all: $PYTHON_FLINT echo echo ----------------------------------------------------------- -pip install --no-binary :all: $1 +pip install --no-binary :all: $PYTHON_FLINT From 7078dc938a36a1bfb54697441ed7e0776a4e4022 Mon Sep 17 00:00:00 2001 From: Oscar Benjamin Date: Fri, 2 Feb 2024 17:40:17 +0000 Subject: [PATCH 04/10] Rename CI job --- .github/workflows/buildwheel.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/buildwheel.yml b/.github/workflows/buildwheel.yml index f02dff7d..65a4b345 100644 --- a/.github/workflows/buildwheel.yml +++ b/.github/workflows/buildwheel.yml @@ -137,17 +137,17 @@ jobs: - run: python -m flint.test --verbose test_flint_versions: - name: pip install ${{ matrix.target }} on ${{ matrix.python-version }} + name: Test flint ${{ matrix.flinttag }} runs-on: ubuntu-22.04 strategy: fail-fast: false matrix: # minimum supported version and latest git - flint: ['v3.0.0', 'main'] + 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.flint }} + - run: bin/pip_install_ubuntu.sh . ${{ matrix.flinttag }} - run: python -m flint.test --verbose From 74a0ebcec19fa2f802387c6103d9c4142ea923c6 Mon Sep 17 00:00:00 2001 From: Oscar Benjamin Date: Fri, 2 Feb 2024 17:43:42 +0000 Subject: [PATCH 05/10] Fix build script --- bin/pip_install_ubuntu.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/bin/pip_install_ubuntu.sh b/bin/pip_install_ubuntu.sh index 6229795c..0246d086 100755 --- a/bin/pip_install_ubuntu.sh +++ b/bin/pip_install_ubuntu.sh @@ -37,14 +37,6 @@ PYTHON_FLINT=$1 sudo apt-get update sudo apt-get install libgmp-dev libmpfr-dev xz-utils -# This will default to installing in /usr/local. If you want to install in a -# non-standard location then configure flint with -# ./configure --disable-static --prefix=$PREFIX -# If $PREFIX is not in default search paths, then at build time set -# export C_INCLUDE_PATH=$PREFIX/include -# and at runtime set -# export LD_LIBRARY_PATH=$PREFIX/lib - if [ -z "$FLINT_GIT" ]; then # Install from release tarball echo "Installing Flint $FLINTVER from release tarball" @@ -59,10 +51,18 @@ else 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 +# ./configure --disable-static --prefix=$PREFIX +# If $PREFIX is not in default search paths, then at build time set +# export C_INCLUDE_PATH=$PREFIX/include +# and at runtime set +# export LD_LIBRARY_PATH=$PREFIX/lib ./bootstrap.sh ./configure --disable-static make -j sudo make install +cd .. ls -l /usr/local/lib sudo ldconfig /usr/local/lib From eae1720a87c7e9552b14c9d7c117a0e00316f1a5 Mon Sep 17 00:00:00 2001 From: Oscar Benjamin Date: Sat, 3 Feb 2024 12:42:01 +0000 Subject: [PATCH 06/10] Add __FLINT_VERSION__ and __FLINT_RELEASE__ --- src/flint/__init__.py | 5 +++++ src/flint/flint_base/flint_base.pyx | 11 ++++++++++- src/flint/flintlib/flint.pxd | 2 ++ 3 files changed, 17 insertions(+), 1 deletion(-) 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) From 3263d9da6ee18f6ab6e8956646866e9a8a506a00 Mon Sep 17 00:00:00 2001 From: Oscar Benjamin Date: Sat, 3 Feb 2024 13:41:06 +0000 Subject: [PATCH 07/10] Add compat_ layer for fmpz_mod_mat This is needed to support both Flint 3.1.0 at the same time as earlier versions since the signatures of most fmpz_mod_mat functions are changed in Flint 3.1.0. --- src/flint/flintlib/fmpz_mod_mat.pxd | 184 +++++++++++++++++++--------- src/flint/types/fmpz_mod_mat.pyx | 96 +++++++-------- 2 files changed, 173 insertions(+), 107 deletions(-) diff --git a/src/flint/flintlib/fmpz_mod_mat.pxd b/src/flint/flintlib/fmpz_mod_mat.pxd index c1b08f48..37ef2707 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(perm, mat, ctx) fmpz_mod_mat_rref(perm, 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(perm, mat, ctx) fmpz_mod_mat_rref(perm, 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(slong * perm, 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..6832cf12 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,16 +229,16 @@ 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.""" @@ -251,7 +251,7 @@ cdef class fmpz_mod_mat(flint_mat): """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,7 @@ cdef class fmpz_mod_mat(flint_mat): if other is NotImplemented: return other - res = fmpz_mod_mat_equal((self).val, (other).val) + res = compat_fmpz_mod_mat_equal((self).val, (other).val, self.ctx.val) if op == 2: return res @@ -334,7 +334,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 +353,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 +367,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 +387,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 +497,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 +537,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 +560,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 +578,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 +609,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 +652,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(NULL, res.val, res.ctx.val) return (res, r) From 2f6c9417bbb02ebdebcbe6bdd805fd73e0d89474 Mon Sep 17 00:00:00 2001 From: Oscar Benjamin Date: Sat, 3 Feb 2024 13:59:57 +0000 Subject: [PATCH 08/10] Don't use members of fmpz_mod_mat_t --- src/flint/types/fmpz_mod_mat.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/flint/types/fmpz_mod_mat.pyx b/src/flint/types/fmpz_mod_mat.pyx index 6832cf12..9ccff4e1 100644 --- a/src/flint/types/fmpz_mod_mat.pyx +++ b/src/flint/types/fmpz_mod_mat.pyx @@ -244,7 +244,7 @@ cdef class fmpz_mod_mat(flint_mat): """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): From de731214fad7b270640424cbcf4d37ce04b30314 Mon Sep 17 00:00:00 2001 From: Oscar Benjamin Date: Sat, 3 Feb 2024 14:44:22 +0000 Subject: [PATCH 09/10] Fix fmpz_mod_mat equal and rref --- src/flint/flintlib/fmpz_mod_mat.pxd | 6 +++--- src/flint/types/fmpz_mod_mat.pyx | 7 +++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/flint/flintlib/fmpz_mod_mat.pxd b/src/flint/flintlib/fmpz_mod_mat.pxd index 37ef2707..ad053f6d 100644 --- a/src/flint/flintlib/fmpz_mod_mat.pxd +++ b/src/flint/flintlib/fmpz_mod_mat.pxd @@ -44,7 +44,7 @@ cdef extern from *: #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(perm, mat, ctx) fmpz_mod_mat_rref(perm, mat, 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) @@ -69,7 +69,7 @@ cdef extern from *: #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(perm, mat, ctx) fmpz_mod_mat_rref(perm, mat) + #define compat_fmpz_mod_mat_rref(mat, ctx) fmpz_mod_mat_rref(NULL, perm, 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) @@ -97,7 +97,7 @@ cdef extern from "flint/fmpz_mod_mat.h": 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(slong * perm, fmpz_mod_mat_t mat, 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) # diff --git a/src/flint/types/fmpz_mod_mat.pyx b/src/flint/types/fmpz_mod_mat.pyx index 9ccff4e1..0049ad39 100644 --- a/src/flint/types/fmpz_mod_mat.pyx +++ b/src/flint/types/fmpz_mod_mat.pyx @@ -320,7 +320,10 @@ cdef class fmpz_mod_mat(flint_mat): if other is NotImplemented: return other - res = compat_fmpz_mod_mat_equal((self).val, (other).val, self.ctx.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 @@ -652,5 +655,5 @@ cdef class fmpz_mod_mat(flint_mat): res = self else: res = self._copy() - r = compat_fmpz_mod_mat_rref(NULL, res.val, res.ctx.val) + r = compat_fmpz_mod_mat_rref(res.val, res.ctx.val) return (res, r) From 128a035cbfb0956b92c39aaff69ab8105b36b5ec Mon Sep 17 00:00:00 2001 From: Oscar Benjamin Date: Sat, 3 Feb 2024 14:46:41 +0000 Subject: [PATCH 10/10] Fix fmpz_mod_mat rref --- src/flint/flintlib/fmpz_mod_mat.pxd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/flint/flintlib/fmpz_mod_mat.pxd b/src/flint/flintlib/fmpz_mod_mat.pxd index ad053f6d..22f1b181 100644 --- a/src/flint/flintlib/fmpz_mod_mat.pxd +++ b/src/flint/flintlib/fmpz_mod_mat.pxd @@ -69,7 +69,7 @@ cdef extern from *: #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, perm, mat) + #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)