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
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/sage/matrix/matrix2.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -3586,6 +3586,38 @@ cdef class Matrix(Matrix1):
s += self.get_unsafe(i, j) * other.get_unsafe(j, i)
return s

def get_bandwidth(self):
"""
Return the bandwidth of ``self``.

EXAMPLES::
sage: A = matrix([[1,0,0],[0,1,0],[0,0,1]]); A
[1 0 0]
[0 1 0]
[0 0 1]
sage: A.get_bandwidth()
0

sage: B = matrix([[1,2,3],[0,4,5],[0,0,6]]); B
[1 2 3]
[0 4 5]
[0 0 6]
sage: B.get_bandwidth()
2
"""
cdef Py_ssize_t i, j, rows, cols, max_bandwidth
max_bandwidth = 0
rows, cols = self.nrows(), self.ncols()
zero = self._base_ring(0)

for i in range(rows):
for j in range(cols):
if self.get_unsafe(i, j) != zero:
dist = abs(j - i)
max_bandwidth = max(max_bandwidth, dist)

return max_bandwidth

#####################################################################################
# Generic Hessenberg Form and charpoly algorithm
#####################################################################################
Expand Down
Loading