Skip to content

Commit e5da576

Browse files
Merge pull request #106 from oscarbenjamin/pr_fmpz_mod_mat
Add fmpz_mod_mat
2 parents 3e31bc6 + 67b29cf commit e5da576

17 files changed

+1672
-127
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ MANIFEST
1717
*.swp
1818
.python-version
1919
*.DS_Store
20+
.venv

doc/source/fmpz_mod_mat.rst

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
**fmpz_mod_mat** -- matrices over integers mod n for arbitrary n
2+
===============================================================================
3+
4+
.. autoclass :: flint.fmpz_mod_mat
5+
:members:
6+
:inherited-members:
7+
:undoc-members:
8+

doc/source/index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ Matrix types
5858
fmpz_mat.rst
5959
fmpq_mat.rst
6060
nmod_mat.rst
61+
fmpz_mod_mat.rst
6162
arb_mat.rst
6263
acb_mat.rst
6364

setup.py

+14-7
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,30 @@
7676

7777
ext_files = [
7878
("flint.pyflint", ["src/flint/pyflint.pyx"]),
79+
80+
("flint.flint_base.flint_base", ["src/flint/flint_base/flint_base.pyx"]),
81+
("flint.flint_base.flint_context", ["src/flint/flint_base/flint_context.pyx"]),
82+
7983
("flint.types.fmpz", ["src/flint/types/fmpz.pyx"]),
8084
("flint.types.fmpz_poly", ["src/flint/types/fmpz_poly.pyx"]),
85+
("flint.types.fmpz_mpoly", ["src/flint/types/fmpz_mpoly.pyx"]),
8186
("flint.types.fmpz_mat", ["src/flint/types/fmpz_mat.pyx"]),
8287
("flint.types.fmpz_series", ["src/flint/types/fmpz_series.pyx"]),
88+
8389
("flint.types.fmpq", ["src/flint/types/fmpq.pyx"]),
8490
("flint.types.fmpq_poly", ["src/flint/types/fmpq_poly.pyx"]),
8591
("flint.types.fmpq_mat", ["src/flint/types/fmpq_mat.pyx"]),
8692
("flint.types.fmpq_series", ["src/flint/types/fmpq_series.pyx"]),
93+
8794
("flint.types.nmod", ["src/flint/types/nmod.pyx"]),
8895
("flint.types.nmod_poly", ["src/flint/types/nmod_poly.pyx"]),
8996
("flint.types.nmod_mat", ["src/flint/types/nmod_mat.pyx"]),
9097
("flint.types.nmod_series", ["src/flint/types/nmod_series.pyx"]),
98+
99+
("flint.types.fmpz_mod", ["src/flint/types/fmpz_mod.pyx"]),
100+
("flint.types.fmpz_mod_poly", ["src/flint/types/fmpz_mod_poly.pyx"]),
101+
("flint.types.fmpz_mod_mat", ["src/flint/types/fmpz_mod_mat.pyx"]),
102+
91103
("flint.types.arf", ["src/flint/types/arf.pyx"]),
92104
("flint.types.arb", ["src/flint/types/arb.pyx"]),
93105
("flint.types.arb_poly", ["src/flint/types/arb_poly.pyx"]),
@@ -97,15 +109,10 @@
97109
("flint.types.acb_poly", ["src/flint/types/acb_poly.pyx"]),
98110
("flint.types.acb_mat", ["src/flint/types/acb_mat.pyx"]),
99111
("flint.types.acb_series", ["src/flint/types/acb_series.pyx"]),
100-
("flint.types.fmpz_mpoly", ["src/flint/types/fmpz_mpoly.pyx"]),
101-
("flint.types.fmpz_mod", ["src/flint/types/fmpz_mod.pyx"]),
102-
("flint.types.fmpz_mod_poly", ["src/flint/types/fmpz_mod_poly.pyx"]),
112+
103113
("flint.types.dirichlet", ["src/flint/types/dirichlet.pyx"]),
104-
("flint.flint_base.flint_base", ["src/flint/flint_base/flint_base.pyx"]),
105-
("flint.flint_base.flint_context", ["src/flint/flint_base/flint_context.pyx"]),
106-
# Helper for unittests
107-
("flint.functions.showgood", ["src/flint/functions/showgood.pyx"]),
108114

115+
("flint.functions.showgood", ["src/flint/functions/showgood.pyx"]),
109116
]
110117

111118
ext_options = {

src/flint/__init__.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
from .pyflint import *
2+
23
from .types.fmpz import *
34
from .types.fmpz_poly import *
45
from .types.fmpz_mat import *
56
from .types.fmpz_series import *
7+
68
from .types.fmpq import *
79
from .types.fmpq_poly import *
810
from .types.fmpq_mat import *
911
from .types.fmpq_series import *
12+
1013
from .types.nmod import *
1114
from .types.nmod_poly import *
1215
from .types.nmod_mat import *
1316
from .types.nmod_series import *
17+
18+
from .types.fmpz_mpoly import *
19+
from .types.fmpz_mod import *
20+
from .types.fmpz_mod_poly import *
21+
from .types.fmpz_mod_mat import fmpz_mod_mat
22+
1423
from .types.arf import *
1524
from .types.arb import *
1625
from .types.arb_poly import *
@@ -20,9 +29,7 @@
2029
from .types.acb_poly import *
2130
from .types.acb_mat import *
2231
from .types.acb_series import *
23-
from .types.fmpz_mpoly import *
24-
from .types.fmpz_mod import *
25-
from .types.fmpz_mod_poly import *
32+
2633
from .types.dirichlet import *
2734
from .functions.showgood import good, showgood
2835

src/flint/flint_base/flint_base.pyx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
from flint.flintlib.flint cimport FLINT_BITS as _FLINT_BITS
12
from flint.flint_base.flint_context cimport thectx
23

4+
35
cdef class flint_elem:
46
def __repr__(self):
57
if thectx.pretty:
@@ -134,8 +136,6 @@ cdef class flint_mat(flint_elem):
134136
"""
135137

136138
def repr(self):
137-
if thectx.pretty:
138-
return str(self)
139139
# XXX
140140
return "%s(%i, %i, [%s])" % (type(self).__name__,
141141
self.nrows(), self.ncols(), (", ".join(map(str, self.entries()))))

src/flint/flintlib/fmpz_mod_mat.pxd

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
from flint.flintlib.flint cimport ulong, slong, fmpz_struct, flint_rand_t
2+
from flint.flintlib.fmpz cimport fmpz_t
3+
from flint.flintlib.fmpz_mod cimport fmpz_mod_ctx_t
4+
from flint.flintlib.fmpz_mat cimport fmpz_mat_t
5+
from flint.flintlib.fmpz_mod_poly cimport fmpz_mod_poly_t
6+
7+
8+
cdef extern from "flint/fmpz_mod_mat.h":
9+
ctypedef struct fmpz_mod_mat_struct:
10+
fmpz_mat_t mat
11+
fmpz_t mod
12+
ctypedef fmpz_mod_mat_struct fmpz_mod_mat_t[1]
13+
14+
15+
cdef extern from "flint/fmpz_mod_mat.h":
16+
# This is not exposed in the docs:
17+
int fmpz_mod_mat_equal(const fmpz_mod_mat_t mat1, const fmpz_mod_mat_t mat2);
18+
19+
20+
cdef extern from "flint/fmpz_mod_mat.h":
21+
fmpz_struct * fmpz_mod_mat_entry(const fmpz_mod_mat_t mat, slong i, slong j)
22+
void fmpz_mod_mat_set_entry(fmpz_mod_mat_t mat, slong i, slong j, const fmpz_t val)
23+
void fmpz_mod_mat_init(fmpz_mod_mat_t mat, slong rows, slong cols, const fmpz_t n)
24+
void fmpz_mod_mat_init_set(fmpz_mod_mat_t mat, const fmpz_mod_mat_t src)
25+
void fmpz_mod_mat_clear(fmpz_mod_mat_t mat)
26+
slong fmpz_mod_mat_nrows(const fmpz_mod_mat_t mat)
27+
slong fmpz_mod_mat_ncols(const fmpz_mod_mat_t mat)
28+
void _fmpz_mod_mat_set_mod(fmpz_mod_mat_t mat, const fmpz_t n)
29+
void fmpz_mod_mat_one(fmpz_mod_mat_t mat)
30+
void fmpz_mod_mat_zero(fmpz_mod_mat_t mat)
31+
void fmpz_mod_mat_swap(fmpz_mod_mat_t mat1, fmpz_mod_mat_t mat2)
32+
void fmpz_mod_mat_swap_entrywise(fmpz_mod_mat_t mat1, fmpz_mod_mat_t mat2)
33+
int fmpz_mod_mat_is_empty(const fmpz_mod_mat_t mat)
34+
int fmpz_mod_mat_is_square(const fmpz_mod_mat_t mat)
35+
void _fmpz_mod_mat_reduce(fmpz_mod_mat_t mat)
36+
void fmpz_mod_mat_randtest(fmpz_mod_mat_t mat, flint_rand_t state)
37+
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)
38+
void fmpz_mod_mat_window_clear(fmpz_mod_mat_t window)
39+
void fmpz_mod_mat_concat_horizontal(fmpz_mod_mat_t res, const fmpz_mod_mat_t mat1, const fmpz_mod_mat_t mat2)
40+
void fmpz_mod_mat_concat_vertical(fmpz_mod_mat_t res, const fmpz_mod_mat_t mat1, const fmpz_mod_mat_t mat2)
41+
void fmpz_mod_mat_print_pretty(const fmpz_mod_mat_t mat)
42+
int fmpz_mod_mat_is_zero(const fmpz_mod_mat_t mat)
43+
void fmpz_mod_mat_set(fmpz_mod_mat_t B, const fmpz_mod_mat_t A)
44+
void fmpz_mod_mat_transpose(fmpz_mod_mat_t B, const fmpz_mod_mat_t A)
45+
void fmpz_mod_mat_set_fmpz_mat(fmpz_mod_mat_t A, const fmpz_mat_t B)
46+
void fmpz_mod_mat_get_fmpz_mat(fmpz_mat_t A, const fmpz_mod_mat_t B)
47+
void fmpz_mod_mat_add(fmpz_mod_mat_t C, const fmpz_mod_mat_t A, const fmpz_mod_mat_t B)
48+
void fmpz_mod_mat_sub(fmpz_mod_mat_t C, const fmpz_mod_mat_t A, const fmpz_mod_mat_t B)
49+
void fmpz_mod_mat_neg(fmpz_mod_mat_t B, const fmpz_mod_mat_t A)
50+
void fmpz_mod_mat_scalar_mul_si(fmpz_mod_mat_t B, const fmpz_mod_mat_t A, slong c)
51+
void fmpz_mod_mat_scalar_mul_ui(fmpz_mod_mat_t B, const fmpz_mod_mat_t A, ulong c)
52+
void fmpz_mod_mat_scalar_mul_fmpz(fmpz_mod_mat_t B, const fmpz_mod_mat_t A, fmpz_t c)
53+
void fmpz_mod_mat_mul(fmpz_mod_mat_t C, const fmpz_mod_mat_t A, const fmpz_mod_mat_t B)
54+
# unimported types {'thread_pool_handle'}
55+
# 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)
56+
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)
57+
void fmpz_mod_mat_mul_classical_threaded(fmpz_mod_mat_t C, const fmpz_mod_mat_t A, const fmpz_mod_mat_t B)
58+
void fmpz_mod_mat_sqr(fmpz_mod_mat_t B, const fmpz_mod_mat_t A)
59+
void fmpz_mod_mat_mul_fmpz_vec(fmpz_struct * c, const fmpz_mod_mat_t A, const fmpz_struct * b, slong blen)
60+
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)
61+
void fmpz_mod_mat_fmpz_vec_mul(fmpz_struct * c, const fmpz_struct * a, slong alen, const fmpz_mod_mat_t B)
62+
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)
63+
void fmpz_mod_mat_trace(fmpz_t trace, const fmpz_mod_mat_t mat)
64+
slong fmpz_mod_mat_rref(slong * perm, fmpz_mod_mat_t mat)
65+
void fmpz_mod_mat_strong_echelon_form(fmpz_mod_mat_t mat)
66+
slong fmpz_mod_mat_howell_form(fmpz_mod_mat_t mat)
67+
int fmpz_mod_mat_inv(fmpz_mod_mat_t B, fmpz_mod_mat_t A)
68+
slong fmpz_mod_mat_lu(slong * P, fmpz_mod_mat_t A, int rank_check)
69+
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)
70+
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)
71+
int fmpz_mod_mat_solve(fmpz_mod_mat_t X, const fmpz_mod_mat_t A, const fmpz_mod_mat_t B)
72+
int fmpz_mod_mat_can_solve(fmpz_mod_mat_t X, const fmpz_mod_mat_t A, const fmpz_mod_mat_t B)
73+
void fmpz_mod_mat_similarity(fmpz_mod_mat_t M, slong r, fmpz_t d)
74+
void fmpz_mod_mat_charpoly(fmpz_mod_poly_t p, const fmpz_mod_mat_t M, const fmpz_mod_ctx_t ctx)
75+
void fmpz_mod_mat_minpoly(fmpz_mod_poly_t p, const fmpz_mod_mat_t M, const fmpz_mod_ctx_t ctx)

src/flint/test/__main__.py

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def run_doctests(verbose=None):
6060
flint.types.fmpz_series,
6161
flint.types.fmpz_mod,
6262
flint.types.fmpz_mod_poly,
63+
flint.types.fmpz_mod_mat,
6364
flint.types.fmpq,
6465
flint.types.fmpq_poly,
6566
flint.types.fmpq_mat,

0 commit comments

Comments
 (0)