Skip to content

Commit

Permalink
Merge pull request #106 from oscarbenjamin/pr_fmpz_mod_mat
Browse files Browse the repository at this point in the history
Add fmpz_mod_mat
  • Loading branch information
oscarbenjamin committed Nov 29, 2023
2 parents 3e31bc6 + 67b29cf commit e5da576
Show file tree
Hide file tree
Showing 17 changed files with 1,672 additions and 127 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -17,3 +17,4 @@ MANIFEST
*.swp
.python-version
*.DS_Store
.venv
8 changes: 8 additions & 0 deletions doc/source/fmpz_mod_mat.rst
@@ -0,0 +1,8 @@
**fmpz_mod_mat** -- matrices over integers mod n for arbitrary n
===============================================================================

.. autoclass :: flint.fmpz_mod_mat
:members:
:inherited-members:
:undoc-members:
1 change: 1 addition & 0 deletions doc/source/index.rst
Expand Up @@ -58,6 +58,7 @@ Matrix types
fmpz_mat.rst
fmpq_mat.rst
nmod_mat.rst
fmpz_mod_mat.rst
arb_mat.rst
acb_mat.rst

Expand Down
21 changes: 14 additions & 7 deletions setup.py
Expand Up @@ -76,18 +76,30 @@

ext_files = [
("flint.pyflint", ["src/flint/pyflint.pyx"]),

("flint.flint_base.flint_base", ["src/flint/flint_base/flint_base.pyx"]),
("flint.flint_base.flint_context", ["src/flint/flint_base/flint_context.pyx"]),

("flint.types.fmpz", ["src/flint/types/fmpz.pyx"]),
("flint.types.fmpz_poly", ["src/flint/types/fmpz_poly.pyx"]),
("flint.types.fmpz_mpoly", ["src/flint/types/fmpz_mpoly.pyx"]),
("flint.types.fmpz_mat", ["src/flint/types/fmpz_mat.pyx"]),
("flint.types.fmpz_series", ["src/flint/types/fmpz_series.pyx"]),

("flint.types.fmpq", ["src/flint/types/fmpq.pyx"]),
("flint.types.fmpq_poly", ["src/flint/types/fmpq_poly.pyx"]),
("flint.types.fmpq_mat", ["src/flint/types/fmpq_mat.pyx"]),
("flint.types.fmpq_series", ["src/flint/types/fmpq_series.pyx"]),

("flint.types.nmod", ["src/flint/types/nmod.pyx"]),
("flint.types.nmod_poly", ["src/flint/types/nmod_poly.pyx"]),
("flint.types.nmod_mat", ["src/flint/types/nmod_mat.pyx"]),
("flint.types.nmod_series", ["src/flint/types/nmod_series.pyx"]),

("flint.types.fmpz_mod", ["src/flint/types/fmpz_mod.pyx"]),
("flint.types.fmpz_mod_poly", ["src/flint/types/fmpz_mod_poly.pyx"]),
("flint.types.fmpz_mod_mat", ["src/flint/types/fmpz_mod_mat.pyx"]),

("flint.types.arf", ["src/flint/types/arf.pyx"]),
("flint.types.arb", ["src/flint/types/arb.pyx"]),
("flint.types.arb_poly", ["src/flint/types/arb_poly.pyx"]),
Expand All @@ -97,15 +109,10 @@
("flint.types.acb_poly", ["src/flint/types/acb_poly.pyx"]),
("flint.types.acb_mat", ["src/flint/types/acb_mat.pyx"]),
("flint.types.acb_series", ["src/flint/types/acb_series.pyx"]),
("flint.types.fmpz_mpoly", ["src/flint/types/fmpz_mpoly.pyx"]),
("flint.types.fmpz_mod", ["src/flint/types/fmpz_mod.pyx"]),
("flint.types.fmpz_mod_poly", ["src/flint/types/fmpz_mod_poly.pyx"]),

("flint.types.dirichlet", ["src/flint/types/dirichlet.pyx"]),
("flint.flint_base.flint_base", ["src/flint/flint_base/flint_base.pyx"]),
("flint.flint_base.flint_context", ["src/flint/flint_base/flint_context.pyx"]),
# Helper for unittests
("flint.functions.showgood", ["src/flint/functions/showgood.pyx"]),

("flint.functions.showgood", ["src/flint/functions/showgood.pyx"]),
]

ext_options = {
Expand Down
13 changes: 10 additions & 3 deletions src/flint/__init__.py
@@ -1,16 +1,25 @@
from .pyflint import *

from .types.fmpz import *
from .types.fmpz_poly import *
from .types.fmpz_mat import *
from .types.fmpz_series import *

from .types.fmpq import *
from .types.fmpq_poly import *
from .types.fmpq_mat import *
from .types.fmpq_series import *

from .types.nmod import *
from .types.nmod_poly import *
from .types.nmod_mat import *
from .types.nmod_series import *

from .types.fmpz_mpoly import *
from .types.fmpz_mod import *
from .types.fmpz_mod_poly import *
from .types.fmpz_mod_mat import fmpz_mod_mat

from .types.arf import *
from .types.arb import *
from .types.arb_poly import *
Expand All @@ -20,9 +29,7 @@
from .types.acb_poly import *
from .types.acb_mat import *
from .types.acb_series import *
from .types.fmpz_mpoly import *
from .types.fmpz_mod import *
from .types.fmpz_mod_poly import *

from .types.dirichlet import *
from .functions.showgood import good, showgood

Expand Down
4 changes: 2 additions & 2 deletions src/flint/flint_base/flint_base.pyx
@@ -1,5 +1,7 @@
from flint.flintlib.flint cimport FLINT_BITS as _FLINT_BITS
from flint.flint_base.flint_context cimport thectx


cdef class flint_elem:
def __repr__(self):
if thectx.pretty:
Expand Down Expand Up @@ -134,8 +136,6 @@ cdef class flint_mat(flint_elem):
"""

def repr(self):
if thectx.pretty:
return str(self)
# XXX
return "%s(%i, %i, [%s])" % (type(self).__name__,
self.nrows(), self.ncols(), (", ".join(map(str, self.entries()))))
Expand Down
75 changes: 75 additions & 0 deletions src/flint/flintlib/fmpz_mod_mat.pxd
@@ -0,0 +1,75 @@
from flint.flintlib.flint cimport 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
from flint.flintlib.fmpz_mod_poly cimport fmpz_mod_poly_t


cdef extern from "flint/fmpz_mod_mat.h":
ctypedef struct fmpz_mod_mat_struct:
fmpz_mat_t mat
fmpz_t mod
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 "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)
1 change: 1 addition & 0 deletions src/flint/test/__main__.py
Expand Up @@ -60,6 +60,7 @@ def run_doctests(verbose=None):
flint.types.fmpz_series,
flint.types.fmpz_mod,
flint.types.fmpz_mod_poly,
flint.types.fmpz_mod_mat,
flint.types.fmpq,
flint.types.fmpq_poly,
flint.types.fmpq_mat,
Expand Down

0 comments on commit e5da576

Please sign in to comment.