Skip to content
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

Speed up multimodular algorithm in bad case #39204

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from

Conversation

user202729
Copy link
Contributor

@user202729 user202729 commented Dec 25, 2024

Edit: Now flint has fixed flintlib/flint#2129 , it should be better to just switch to flint entirely — according to flintlib/flint#2129 (comment) , one of the possible algorithms by flint is multimodular, which should be faster than or equal to what we're having now. If it is slower in any case, bug can be reported upstream.


Related to #39197.

Technically the algorithm doesn't deviate from @williamstein 's original book; however the original book doesn't say how many additional primes to add each time.

The original implementation roughly consider 3 more primes each time. This can be highly inefficient when there are more columns than rows, which makes the result's height much higher than the guess.

This increases the length of M by roughly a factor of 1.2 each time. Worst case it makes the algorithm slower by a (hopefully small) constant factor.

For the added test case, it appears to improve the performance. (Originally takes 40s, now takes <10s on my machine)

📝 Checklist

  • The title is concise and informative.
  • The description explains in detail what this PR is about.
  • I have linked a relevant issue or discussion.
  • I have created tests covering the changes.
  • I have updated the documentation and checked the documentation preview.

⌛ Dependencies

Copy link

github-actions bot commented Dec 25, 2024

Documentation preview for this PR (built with commit ce55b7c; changes) is ready! 🎉
This preview will update shortly after each push to this PR.

@user202729 user202729 marked this pull request as draft January 22, 2025 05:57
@user202729
Copy link
Contributor Author

Superseded by #39733

@user202729 user202729 closed this Mar 18, 2025
@tscrim
Copy link
Collaborator

tscrim commented Apr 2, 2025

Even with #39733, I think there is a benefit for speeding up this implementation within Sage (some people might need it for some reason). Should we reopen this?

@user202729
Copy link
Contributor Author

Up to you, if there's some interest…?

At least the change in this pull request is not overly complicated.

@user202729 user202729 reopened this Apr 2, 2025
@user202729 user202729 marked this pull request as ready for review April 2, 2025 11:14
@tscrim
Copy link
Collaborator

tscrim commented Apr 2, 2025

I will do the review. I should be able to get to it tomorrow.

Copy link
Collaborator

@tscrim tscrim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. LGTM.

vbraun pushed a commit to vbraun/sage that referenced this pull request Apr 4, 2025
sagemathgh-39204: Speed up multimodular algorithm in bad case
    
**Edit**: Now flint has fixed
flintlib/flint#2129 , it should be better to
just switch to flint entirely — according to
flintlib/flint#2129 (comment) ,
one of the possible algorithms by flint is multimodular, which should be
faster than or equal to what we're having now. If it is slower in any
case, bug can be reported upstream.

------

Related to sagemath#39197.

Technically the algorithm doesn't deviate from @williamstein  's
original book; however the original book doesn't say *how many*
additional primes to add each time.

The original implementation roughly consider 3 more primes each time.
This can be highly inefficient when there are more columns than rows,
which makes the result's height much higher than the guess.

This increases the length of `M` by roughly a factor of `1.2` each time.
Worst case it makes the algorithm slower by a (hopefully small) constant
factor.

For the added test case, it appears to improve the performance.
(Originally takes 40s, now takes <10s on my machine)

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->

- [x] The title is concise and informative.
- [x] The description explains in detail what this PR is about.
- [x] I have linked a relevant issue or discussion.
- [x] I have created tests covering the changes.
- [ ] I have updated the documentation and checked the documentation
preview.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on. For example,
-->
<!-- - sagemath#12345: short description why this is a dependency -->
<!-- - sagemath#34567: ... -->
    
URL: sagemath#39204
Reported by: user202729
Reviewer(s): Travis Scrimshaw
vbraun pushed a commit to vbraun/sage that referenced this pull request Apr 5, 2025
sagemathgh-39204: Speed up multimodular algorithm in bad case
    
**Edit**: Now flint has fixed
flintlib/flint#2129 , it should be better to
just switch to flint entirely — according to
flintlib/flint#2129 (comment) ,
one of the possible algorithms by flint is multimodular, which should be
faster than or equal to what we're having now. If it is slower in any
case, bug can be reported upstream.

------

Related to sagemath#39197.

Technically the algorithm doesn't deviate from @williamstein  's
original book; however the original book doesn't say *how many*
additional primes to add each time.

The original implementation roughly consider 3 more primes each time.
This can be highly inefficient when there are more columns than rows,
which makes the result's height much higher than the guess.

This increases the length of `M` by roughly a factor of `1.2` each time.
Worst case it makes the algorithm slower by a (hopefully small) constant
factor.

For the added test case, it appears to improve the performance.
(Originally takes 40s, now takes <10s on my machine)

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->

- [x] The title is concise and informative.
- [x] The description explains in detail what this PR is about.
- [x] I have linked a relevant issue or discussion.
- [x] I have created tests covering the changes.
- [ ] I have updated the documentation and checked the documentation
preview.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on. For example,
-->
<!-- - sagemath#12345: short description why this is a dependency -->
<!-- - sagemath#34567: ... -->
    
URL: sagemath#39204
Reported by: user202729
Reviewer(s): Travis Scrimshaw
vbraun pushed a commit to vbraun/sage that referenced this pull request Apr 7, 2025
sagemathgh-39204: Speed up multimodular algorithm in bad case
    
**Edit**: Now flint has fixed
flintlib/flint#2129 , it should be better to
just switch to flint entirely — according to
flintlib/flint#2129 (comment) ,
one of the possible algorithms by flint is multimodular, which should be
faster than or equal to what we're having now. If it is slower in any
case, bug can be reported upstream.

------

Related to sagemath#39197.

Technically the algorithm doesn't deviate from @williamstein  's
original book; however the original book doesn't say *how many*
additional primes to add each time.

The original implementation roughly consider 3 more primes each time.
This can be highly inefficient when there are more columns than rows,
which makes the result's height much higher than the guess.

This increases the length of `M` by roughly a factor of `1.2` each time.
Worst case it makes the algorithm slower by a (hopefully small) constant
factor.

For the added test case, it appears to improve the performance.
(Originally takes 40s, now takes <10s on my machine)

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->

- [x] The title is concise and informative.
- [x] The description explains in detail what this PR is about.
- [x] I have linked a relevant issue or discussion.
- [x] I have created tests covering the changes.
- [ ] I have updated the documentation and checked the documentation
preview.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on. For example,
-->
<!-- - sagemath#12345: short description why this is a dependency -->
<!-- - sagemath#34567: ... -->
    
URL: sagemath#39204
Reported by: user202729
Reviewer(s): Travis Scrimshaw
vbraun pushed a commit to vbraun/sage that referenced this pull request Apr 10, 2025
sagemathgh-39204: Speed up multimodular algorithm in bad case
    
**Edit**: Now flint has fixed
flintlib/flint#2129 , it should be better to
just switch to flint entirely — according to
flintlib/flint#2129 (comment) ,
one of the possible algorithms by flint is multimodular, which should be
faster than or equal to what we're having now. If it is slower in any
case, bug can be reported upstream.

------

Related to sagemath#39197.

Technically the algorithm doesn't deviate from @williamstein  's
original book; however the original book doesn't say *how many*
additional primes to add each time.

The original implementation roughly consider 3 more primes each time.
This can be highly inefficient when there are more columns than rows,
which makes the result's height much higher than the guess.

This increases the length of `M` by roughly a factor of `1.2` each time.
Worst case it makes the algorithm slower by a (hopefully small) constant
factor.

For the added test case, it appears to improve the performance.
(Originally takes 40s, now takes <10s on my machine)

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->

- [x] The title is concise and informative.
- [x] The description explains in detail what this PR is about.
- [x] I have linked a relevant issue or discussion.
- [x] I have created tests covering the changes.
- [ ] I have updated the documentation and checked the documentation
preview.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on. For example,
-->
<!-- - sagemath#12345: short description why this is a dependency -->
<!-- - sagemath#34567: ... -->
    
URL: sagemath#39204
Reported by: user202729
Reviewer(s): Travis Scrimshaw
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Computing echelon form of smaller matrix takes longer than larger matrix?
2 participants