-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
53 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module BandedMatricesSparseArraysExt | ||
|
||
using BandedMatrices | ||
using BandedMatrices: _banded_rowval, _banded_colval, _banded_nzval | ||
using SparseArrays | ||
import SparseArrays: sparse | ||
|
||
function sparse(B::BandedMatrix) | ||
sparse(_banded_rowval(B), _banded_colval(B), _banded_nzval(B), size(B)...) | ||
end | ||
|
||
function BandedMatrices.bandwidths(A::SparseMatrixCSC) | ||
l,u = -size(A,1),-size(A,2) | ||
|
||
m,n = size(A) | ||
rows = rowvals(A) | ||
vals = nonzeros(A) | ||
for j = 1:n | ||
for ind in nzrange(A, j) | ||
i = rows[ind] | ||
# We skip non-structural zeros when computing the | ||
# bandwidths. | ||
iszero(vals[ind]) && continue | ||
ij = abs(i-j) | ||
if i ≥ j | ||
l = max(l, ij) | ||
u = max(u, -ij) | ||
elseif i < j | ||
l = max(l, -ij) | ||
u = max(u, ij) | ||
end | ||
end | ||
end | ||
|
||
l,u | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters