Open roed314 opened 3 years ago
Branch: u/roed/nmod_mat
Branch pushed to git repo; I updated commit sha1. New commits:
763533d | Fix bug in cinit |
Commit: 763533d
Branch pushed to git repo; I updated commit sha1. New commits:
8cdf9b1 | Add some functions to Matrix_nmod_dense |
Branch pushed to git repo; I updated commit sha1. New commits:
936668a | Add todos |
Branch pushed to git repo; I updated commit sha1. New commits:
aaf0680 | Update todo |
Branch pushed to git repo; I updated commit sha1. New commits:
fb02349 | Reorder todos |
Branch pushed to git repo; I updated commit sha1. New commits:
31d05e4 | inverses, swap rows and columns |
d69baff | richmp |
ba439fc | Merge branch 'u/roed/nmod_mat' of git://trac.sagemath.org/sage into nmod_mat |
9285ed3 | Merge branch 'u/roed/nmod_mat' of git://trac.sagemath.org/sage into nmod_mat |
6a3d32a | justifying flags |
a90423a | Merge branch 'u/roed/nmod_mat' of git://trac.sagemath.org/sage into nmod_mat |
c7c68cd | some progress |
61821e8 | fixing various things |
cecbe30 | Merge branch 'u/edgarcosta/nmod_mat' of git://trac.sagemath.org/sage into t/31548/nmod_mat |
Sage development has entered the release candidate phase for 9.3. Setting a new milestone for this ticket based on a cursory review of ticket status, priority, and last modification date.
Branch pushed to git repo; I updated commit sha1. Last 10 new commits:
33dd395 | comment |
b922d8e | Merge branch 'u/roed/nmod_mat' of git://trac.sagemath.org/sage into nmod_mat |
c1961a2 | right kernel matrix |
b1d5396 | Merge branch 'u/roed/nmod_mat' of git://trac.sagemath.org/sage into nmod_mat |
b9965be | remove comment |
1045207 | touch up right kernel |
fb619b0 | work around echenolize |
45de1c8 | remove stack |
bf8aaab | Merge branch 'u/edgarcosta/nmod_mat' of git://trac.sagemath.org/sage into t/31548/nmod_mat |
3eb1cd4 | Fix import |
Dependencies: #31069
Branch pushed to git repo; I updated commit sha1. New commits:
fc48eca | Working on documentation |
Branch pushed to git repo; I updated commit sha1. New commits:
64e44fc | Fixing bugs and adding documentation to matrices mod n |
Branch pushed to git repo; I updated commit sha1. New commits:
e5c4c1e | Working on documentation |
Branch pushed to git repo; I updated commit sha1. New commits:
6f41da9 | Fixing doctest problems from switching default implementation to flint for small matrices |
Marking for patchbot to test....
Author: David Roe, Edgar Costa
If you aren't yet ready for comments, I apologize. However, I made a quick skim over things before I realized you set this as needs review for the patchbot.
For def _change_implementation
, wouldn't it make more sense to be cdef
or cpdef
since it should be called entirely from internal stuff? Also, in that implementation, I don't think we should use self.list()
for spare matrices. I also generally find using sage.matrix.matrix_space.MatrixSpace
unstable and think it is better to have a direct import.
I know you said this is for the patchbot, but it would be good to have doctests for _solve_right_modn
. I would also add
cdef list X
cdef Py_ssize_t n
change
- X = self.matrix_space(B.ncols(), self.ncols())(X)
- return X.T
+ return self.matrix_space(B.ncols(), self.ncols())(X).T
(perhaps casting the result as a matrix too), and mark B
as a Matrix
.
I am not sure about the name of the files being matrix_nmod_dense
and the subsequently the name of the class. It conflicts with the matrix_modn_*
files and I feel it is too generic given that it is for a specific implementation.
Why is poly_crt
in the matrix file?
can't
-> cannot
as we want to make the writing formal.
It would be good to implement a get_is_zero_unsafe
method.
No problem! I'm still working on stuff, so comments are easily incorporated. I also realized that the patchbot won't test this since it relies on spkgs until #31069 is merged.
Do you think matrix_modn_flint
and Matrix_modn_flint
would be better?
The poly_crt
function is left over from an earlier implementation of charpoly
or minpoly
(I forget which). I will take care of it.
Thanks!
Replying to @roed314:
No problem! I'm still working on stuff, so comments are easily incorporated. I also realized that the patchbot won't test this since it relies on spkgs until #31069 is merged.
Yea, I didn't quite realize that either. ^^;;
Do you think
matrix_modn_flint
andMatrix_modn_flint
would be better?
The former for the name of the file, the latter for the name of the class considering the other matrix classes in Sage.
Let me know if there is anything I can do to help too.
Branch pushed to git repo; I updated commit sha1. New commits:
cd1b853 | Merge branch 'u/roed/nmod_mat' of trac.sagemath.org:sage into t/31548/nmod_mat |
6e2b75a | Merge branch 'u/roed/nmod_mat' of trac.sagemath.org:sage into t/31548/nmod_mat |
ee10b06 | Working on documentation and fixing tests |
465f51d | Working on documentation |
Replying to @tscrim:
For
def _change_implementation
, wouldn't it make more sense to becdef
orcpdef
since it should be called entirely from internal stuff? Also, in that implementation, I don't think we should useself.list()
for spare matrices. I also generally find usingsage.matrix.matrix_space.MatrixSpace
unstable and think it is better to have a direct import.
Even for a 2 by 2 matrix where the calling overhead is most substantial, changing to cpdef
makes a negligible difference:
sage: A = random_matrix(Zmod(120), 2)
sage: A
[ 32 108]
[ 2 112]
sage: %time B = A._change_implementation("linbox") # using def
CPU times: user 339 µs, sys: 8 µs, total: 347 µs
Wall time: 350 µs
sage: A = random_matrix(Zmod(120), 2) # using cpdef
sage: %time B = A._change_implementation("linbox")
CPU times: user 334 µs, sys: 5 µs, total: 339 µs
Wall time: 343 µs
I don't think it's worth the cost of recompiling everything depending on matrix0.pxd
, and the risk of developers accidentally using def
instead of cpdef
on a matrix class in the future.
I agree about sparse matrices, but currently in sage.matrix.matrix_space.get_matrix_class
we don't allow the implementation
keyword for sparse matrices, so the issue is moot. I'd be happy to have more sparse matrices in Sage eventually, but for now there's no way to even test a version of _change_implementation
in Matrix_sparse
.
I'm not sure what you mean by using sage.matrix.matrix_space.MatrixSpace
unstable. Do you mean switching to from sage.matrix.matrix_space import MatrixSpace
? I was just copying what's done a couple dozen lines above in matrix2.pyx
, but I'm happy to make this change if desired.
I know you said this is for the patchbot, but it would be good to have doctests for
_solve_right_modn
.
Agreed. I've added them.
I would also add
cdef list X cdef Py_ssize_t n
change
- X = self.matrix_space(B.ncols(), self.ncols())(X) - return X.T + return self.matrix_space(B.ncols(), self.ncols())(X).T
(perhaps casting the result as a matrix too), and mark
B
as aMatrix
.
I've added the cdef Py_ssize_t n
since that can speed up the loop, and made the change you suggested in the diff. I don't think it's necessary to mark X
as a list or B
as a matrix, since I'm not calling any functions that will benefit from knowing the types (and the runtime is surely dominated by the call to Pari's matsolvemod
)
I am not sure about the name of the files being
matrix_nmod_dense
and the subsequently the name of the class. It conflicts with thematrix_modn_*
files and I feel it is too generic given that it is for a specific implementation.
Agreed. I've changed it to matrix_modn_dense_flint
.
Why is
poly_crt
in the matrix file?
I've created #31731 and removed it from this ticket.
can't
->cannot
as we want to make the writing formal.It would be good to implement a
get_is_zero_unsafe
method.
Both done.
All tests pass in matrix modules rings modular crypto
. I'm happy to run tests on all of Sage if people are happy with the changes in principle.
Branch pushed to git repo; I updated commit sha1. New commits:
760e0c9 | Small fixes |
(I accidentally made a comment instead of editing the ticket description)
New commits:
760e0c9 | Small fixes |
This ticket is now actually ready for review, though the patchbot won't run currently (since it depends on #31069 which changes spkgs).
This tickets adds a new class for dense matrices over
Zmod(N)
implemented using FLINT'snmod_mat_t
type, along with some supporting ancillary changes:Zmod(N)
for compositeN
to return the Howell form (see the introduction and Chapter 4 of Storjohann's thesis). Since this echelon form can have more rows than the input matrix, made some supporting changes including a new method_echelon_copy
.Zmod(N)
to return the number of leading 1s in Howell form (it raised aNotImplementedError
before), andpivots
to be the locations of these leading 1s. There is also a method_pivots
for accessing the columns where the leading entry is not 1.N
have improved speed and functionality for inversion,charpoly
,det
,minpoly
,echelon_form
,solve_right
andright_kernel_matrix
. There is also a new methodminpoly_ideal
for the ideal vanishing on a matrix (the natural generalization of the minimal polynomial, which generates this ideal when it is principal).stack
andaugment
to return a matrix over a common base ring of the two inputs, rather than just using the top/left matrix to determine the base ring._change_implementation
on matrices, together with rough heuristics for matrices on matrices modN
in determining when it's worth switching between FLINT and linbox (linbox is faster for large matrices, FLINT for smaller, and FLINT offers extra functionality for matrices modulo composite integers).ulong_extras
for number theoretic functions on longsmatrix_cyclo_dense
(which uses a multimodular approach), and moved the_reduction_matrix
method to the base field which will yield better caching behavior.solve_right
and getting different random matrices with a different implementation.Depends on #31069
CC: @edgarcosta
Component: linear algebra
Author: David Roe, Edgar Costa
Branch/Commit: u/roed/nmod_mat @
a3c8e38
Reviewer: Travis Scrimshaw
Issue created by migration from https://trac.sagemath.org/ticket/31548