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

Fix quadratic memory of berlekamp_massey #36173

Merged
merged 4 commits into from
Sep 10, 2023

Conversation

grhkm21
Copy link
Contributor

@grhkm21 grhkm21 commented Sep 1, 2023

Fix #36172.

Reduced berlekamp_massey memory consumption by replacing a dictionary with temporary variables. The memory consumption of the line highlighted below reduced from 42MB to 4MB (probably inaccurate, but significant enough).

from memory_profiler import profile
from sage.matrix.berlekamp_massey import berlekamp_massey
@profile
def gen_data():
    p = random_prime(2**64)
    ls = [GF(p).random_element() for _ in range(20000)]
    berlekamp_massey(ls); # <--- this line
gen_data()

I am not sure if I have to include extra doctests or not, or how to test memory consumptions, since the time complexity is also O(n^2).

📝 Checklist

  • The title is concise, informative, and self-explanatory.
  • 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 accordingly.

@kwankyu
Copy link
Collaborator

kwankyu commented Sep 1, 2023

@dima, would you approve the workflows? (or could you give me the privilege to grant the approval?)

The test has been reflected in the PR on GitHub.
@github-actions
Copy link

github-actions bot commented Sep 3, 2023

Documentation preview for this PR (built with commit 0293a38; changes) is ready! 🎉

vbraun pushed a commit to vbraun/sage that referenced this pull request Sep 4, 2023
    
Fix sagemath#36172.

Reduced berlekamp_massey memory consumption by replacing a dictionary
with temporary variables. The memory consumption of the line highlighted
below reduced from 42MB to 4MB (probably inaccurate, but significant
enough).

```python
from memory_profiler import profile
from sage.matrix.berlekamp_massey import berlekamp_massey
@Profile
def gen_data():
    p = random_prime(2**64)
    ls = [GF(p).random_element() for _ in range(20000)]
    berlekamp_massey(ls); # <--- this line
gen_data()
```

I am not sure if I have to include extra doctests or not, or how to test
memory consumptions, since the time complexity is also O(n^2).

### 📝 Checklist

- [x] The title is concise, informative, and self-explanatory.
- [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.
- [x] I have updated the documentation accordingly.
    
URL: sagemath#36173
Reported by: grhkm21
Reviewer(s): grhkm21, Kwankyu Lee
vbraun pushed a commit to vbraun/sage that referenced this pull request Sep 5, 2023
    
Fix sagemath#36172.

Reduced berlekamp_massey memory consumption by replacing a dictionary
with temporary variables. The memory consumption of the line highlighted
below reduced from 42MB to 4MB (probably inaccurate, but significant
enough).

```python
from memory_profiler import profile
from sage.matrix.berlekamp_massey import berlekamp_massey
@Profile
def gen_data():
    p = random_prime(2**64)
    ls = [GF(p).random_element() for _ in range(20000)]
    berlekamp_massey(ls); # <--- this line
gen_data()
```

I am not sure if I have to include extra doctests or not, or how to test
memory consumptions, since the time complexity is also O(n^2).

### 📝 Checklist

- [x] The title is concise, informative, and self-explanatory.
- [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.
- [x] I have updated the documentation accordingly.
    
URL: sagemath#36173
Reported by: grhkm21
Reviewer(s): grhkm21, Kwankyu Lee
@vbraun vbraun merged commit f63a4d5 into sagemath:develop Sep 10, 2023
11 checks passed
@mkoeppe mkoeppe added this to the sage-10.2 milestone Sep 10, 2023
@grhkm21 grhkm21 deleted the grhkm/issue-36172 branch September 11, 2023 04:51
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.

Unoptimal memory complexity of sage.matrix.berlekamp
4 participants