New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reimplement matrix_integer_dense using FLINT #16803
Comments
Commit: |
comment:2
By the way, after rebasing it does not compile. I will fix it tomorrow hopefully. |
comment:3
A word of caution about algorithm defaults: FLINT should generally be faster for small input but IML/Linbox etc. probably have much better code for things like nullspace, charpoly... as soon as the matrices start to get large. Replacing _rational_kernel_iml with _rational_kernel_flint, for example, is strange. Surely both algorithms should be available. |
comment:5
I rewrote the code to have all the previous functionality available. The code compiles and passes all the doctests in the matrix/ folder. I will have it run all the doctests during the weekend. |
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:9
Hi, A first remark playing around with timings is that in sage-6.3 somebody or something has definitely completely massively screwed up Linbox, or how Linbox is built, or how we use linbox, which was the default representation and library for arithmetic. Consider this:
Linbox should easily beat the multiply_multi_modular approach -- that's just basically a naive version of the same thing linbox would be doing if it were properly built and linked. Instead, Linbox is massively slower. In fact, almost exactly as much slower as I would expect if the wrong BLAS were being linked. Note that I tested against the new flint backend and now a._multiply_multi_modular(b) is asymptotically similar to flint, though asymptotically (for n=2000 already), they are pretty close to the same in speed (8.55s versus 11.4s). In any case, somebody should really look into why linbox is so screwed up -- we switched to it initially since it was much better than doing a._multiply_multi_modular(b) and also our own strassen implementation. |
comment:10
OK, I've been skeptically looking at and testing this patch much of today. I made a few tiny changes, but frankly I think this is overall AWESOME. FLINT's linear algebra seems quite good. The following three methods are now still gone. Add them back so I can run some randomized consistency tests more easily...
When these are added back, and I run tests of correctness by comparing with them, then I'll give this an enthusiastic positive review. |
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:15
I have added the three functions back, and run the long tests in sage/matrix/. |
comment:16
MAJOR PROBLEM! Now that multiply_multi_modular is back, I wrote code to do some random testing of correctness. I did not find situations where things are wrong... however, I quickly ran into major trouble because this ticket introduces a huge memory leak. I just defined two matrices and multiplied them a few hundred times, and had major ram problems. In particular, in sage-6.3 (without this branch):
With this ticket:
Conclusion: making nontrivial use of the code on this ticket will very quickly use up all RAM on your computer. So... needs work until that is fixed. |
comment:77
Done. |
comment:79
Linear algebra should really give the right answer to a few ulp, and not just 1e-10. But the test is about testing that the division operator works, so ok. |
Changed branch from u/mmasdeu/16803-matflint-4 to |
Changed commit from |
comment:82
Did any of the reviewers (Volker?) actually read the code on this ticket? I've started doing this and there are many things to be improved... perhaps this ticket was merged too fast. |
comment:83
Is it perfect? No. But better than before? IMHO yes. Faster? For sure. |
comment:84
Replying to @jdemeyer:
I certainly read the version of the code 5 weeks ago, and had many, many, many suggestions for improvement, found numerous major bugs, etc.
One has to balance that with the fact that for whatever reason, without this ticket a vast range of linear algebra in Sage is so utterly orders of magnitude too slow, as to make it painful and useless for research work. This new code is dramatically faster than before. |
comment:85
Replying to @williamstein:
I only hope we're not trading correctness for speed. |
comment:86
Replying to @jdemeyer:
Well when I looked over the code 5 weeks ago there are numerous memory leaks and other causes for concern (e.g., unitialized memory assumed to be 0). But those were I think all addressed. Did you find anything that is actually incorrect? Or does the overall code just make you unhappy and nervous? Or are you not happy building on FLINT? |
comment:87
I just have to add jdemeyer that I'm really glad you're looking at this too, since you have an amazing eye for quality (similar to your recent remarks about the pexpect interfaces). |
comment:88
Replying to @williamstein:
The segmentation fault in
When looking at this code, there are some sloppy things (like why is the
That's not the problem. In general, I think it's good to rely on external packages if they do a good job (which seems to be the case here). |
comment:90
What's with the changes in padics in this ticket? Surely, yet another mistake... |
comment:91
Yet another follow-up: #17094 |
comment:92
I must say that IMO some of the comments (82 and 90) made above are not very constructive. jdemeyer questions the thoroughness of the reviewing process, while clearly he himself didn't read the comments at the beginning of the ticket (at least those that refer to the convenience of leaving in the legacy functions). After the experience with this ticket I feel less inclined to take on the analogous job for matrix_rational_dense. Sorry! |
comment:93
Replying to @mmasdeu:
[comment:82] was made out of frustration by seeing so many things here which are dubious. So okay, that's not constructive. However in [comment:90], I noticed a mistake, mentioned it in the comment and fixed it in #17090. How is that not constructive?
That's true, but after William Stein's comment, I have fixed that back in #17090.
Please don't. I think it's absolutely good to improve matrices like you did here. The fact that I am making so many comments and creating follow-up tickets means that I care. I make mistakes, you make mistakes, that's normal and that's why have this review process. My only complaint (and I still stand behind this) is that this ticket was given positive_review too soon. Ideally, those 3 follow-up tickets should have been reviewer patches on this ticket. |
comment:94
Replying to @jdemeyer:
I can understand your frustration. But the bar is high enough (python + cython + sage oddities + legacy code + git + trac, and I am probably missing something here) that makes it very hard for people to contribute, and these comments do not help. But I take your last comment in good faith :-). Also, if there are other things that are dubious please share them because I (and possibly others!) would like to learn from it.
Surely I did not go and touch p-adics for no reason. These changes weren't there in the first version of the my patch, and I had to add them because during the time it took to from the first version until this ticket got closed other changes were being merged, and these made the patch to stop compiling. Changing those lines in p-adics is how I managed to fix it, but the hackish idea was not mine, I saw it used elsewhere. I appreciate you having fixed it back. |
comment:95
Replying to @mmasdeu:
I think you simply did something compiling Sage, because those changes to p-adics are totally unrelated to matrices. I cannot imagine how the change to matrices could break building p-adics or vice versa. And indeed, I simply undid the changes in #17090 without any bad consequences. |
comment:96
Replying to @mmasdeu:
Marc -- don't you want to be a bad ass computer programmer, in addition to mathematician? Just redo matrix_rational_dense, and you'll be way closer :-) |
comment:97
Replying to @mmasdeu:
Well, you can look at the follow-up tickets #17090 and #17094 and see what I changed (and preferably review those tickets). Some general things which haven't been mentioned yet:
|
comment:98
Replying to @jdemeyer: Thanks! These comments are helpful indeed. William -- I rather try to be a better mathematician...it has the advantage that although you get constantly evaluated, the evaluations are mostly anonymous :-). But that was in my to-do list. And it still is, despite my previous comments in this ticket! |
In this ticket we reimplement all of matrix_integer_dense using FLINT fmpz_mat_t.
The speed-up is substantial. With the new code:
This takes more than 1 minute in the same computer using Sage 6.3.
CC: @pjbruin
Component: linear algebra
Keywords: flint, matrix
Author: Marc Masdeu
Branch:
812a509
Reviewer: William Stein, Jeroen Demeyer
Issue created by migration from https://trac.sagemath.org/ticket/16803
The text was updated successfully, but these errors were encountered: