Skip to content

Added a bandwidth feature #39978

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

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

Conversation

HenryWu2101
Copy link
Contributor

#13565
Added a bandwidth feature that gives the bandwidth of a matrix. The bandwidth of a matrix measures how far from the main diagonal the nonzero entries extend. Mostly used for storage efficiency / reordering to speed up solvers etc. For now it is just a new feature to add.

📝 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

cc @tscrim

Copy link

github-actions bot commented Apr 20, 2025

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

@dcoudert
Copy link
Contributor

dcoudert commented Apr 20, 2025

The order of operations could be improved by visiting the matrix by diagonals and stop as soon as a non zero value is found. it is best to visit simultaneously the upper and the lower diagonals.
You can use #39963 here.

I'm not sure that the method should be called bandwidth. May be get_bandwidth ? When you ask for the bandwidth, you usually expect to get an ordering of the rows/columns that minimizes the bandwidth.
See for instance method bandwidth in graphs https://doc.sagemath.org/html/en/reference/graphs/sage/graphs/graph_decompositions/bandwidth.html

@HenryWu2101
Copy link
Contributor Author

HenryWu2101 commented Apr 21, 2025

@dcoudert For the namesake, I wasn't careful to see that there is a method with the same name but different behavior implemented elsewhere. In that case, naming it the same would not be appropriate, will change to get_bandwidth. And additionally, I'm not sure if it would be necessary to propose implement bandwidth in matrix2.pyx as a follow-up issue.

As for using diagonal to improve efficiency, it was exactly what I thought when I created the diagonal PR and then got to this issue when looking for something similar in the issue pool. But as I understand it, the bandwidth of a matrix is the smallest distance for all non-zero entries to lie from the main diagonal. At that time, I felt iterating from main diagonal outward would not be an improvement (since it still needs to iterate to the end, in case a non-zero entry lies at the top corner).

So to clarify what you proposed, you're saying if I go through every diagonal starting from the corner to the main diagonal via diagonal, and I stop as soon as I reach a non-zero entry (and visit from both directions simultaneously), I would have an improvement with only $O(n^2)$ as the worst case scenario.

@dcoudert
Copy link
Contributor

@dcoudert For the namesake, I wasn't careful to see that there is a method with the same name but different behavior implemented elsewhere. In that case, naming it the same would not be appropriate, will change to get_bandwidth. And additionally, I'm not sure if it would be necessary to propose implement bandwidth in matrix2.pyx as a follow-up issue.

I don't think it's necessary.

So to clarify what you proposed, you're saying if I go through every diagonal starting from the corner to the main diagonal via diagonal, and I stop as soon as I reach a non-zero entry (and visit from both directions simultaneously), I would have an improvement with only $O(n^2)$ as the worst case scenario.

Precisely and this is what was proposed in the original patch #13565. The idea is to stop computation as soon as possible. This should be an improvement for large matrix.

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.

2 participants