Skip to content

Commit 4cacec3

Browse files
Overload _BandedMatrix(::BandedRows, A::AbstactMatrix) (#486)
* BandedRows * EOL * Add new interface function * Use permutedims; cleanup implementation a bit * Combine iterator * don't test on pre anymore * Test transpose as well --------- Co-authored-by: Sheehan Olver <solver@mac.com>
1 parent f0a432f commit 4cacec3

File tree

6 files changed

+25
-2
lines changed

6 files changed

+25
-2
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ jobs:
4545
version:
4646
- 'lts'
4747
- '1'
48-
- 'pre'
4948
os:
5049
- ubuntu-latest
5150
- macOS-latest

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "BandedMatrices"
22
uuid = "aae01518-5342-5314-be14-df237901396f"
3-
version = "1.9.5"
3+
version = "1.10.0"
44

55
[deps]
66
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"

docs/src/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ interface consists of the following:
218218
| `inbands_setindex!(A, v, k, j)` | Unsafe: set `A[k,j] = v`, without the need to check if we are inside the bands |
219219
| `BandedMatrices.MemoryLayout(A)` | Override to get banded lazy linear algebra, e.g. `y .= Mul(A,x)` |
220220
| `BandedMatrices.bandeddata(A)` | Override to return a matrix of the entries in BLAS format. Required if `MemoryLayout(A)` returns `BandedColumnMajor` |
221+
| `BandedMatrices.bandedrowsdata(A)` | Override to return a matrix of the entries reshaped to a row-major format. Required if `MemoryLayout(A)` returns `BandedRowsMajor` |
221222

222223
Note that certain `SubArray`s of `BandedMatrix` are also banded matrices.
223224
The banded matrix interface is implemented for such `SubArray`s to take advantage of this.

src/banded/BandedMatrix.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,16 @@ BandedMatrix(A::AbstractMatrix) = _BandedMatrix(MemoryLayout(A), A)
264264
## specialised
265265
# use bandeddata if possible
266266
_BandedMatrix(::BandedColumns, A::AbstractMatrix) = _BandedMatrix(copy(bandeddata(A)), axes(A,1), bandwidths(A)...)
267+
function _BandedMatrix(::BandedRows, A::AbstractMatrix)
268+
bdata = bandedrowsdata(A)
269+
data = similar(bdata, eltype(bdata), reverse(size(bdata)))
270+
u, ℓ = bandwidths(A)
271+
n = size(A, 2)
272+
for j in axes(A, 1), i in max(1, j - u):min(n, j + ℓ)
273+
data[ℓ + 1 + j - i, i] = bdata[j, u+1+i-j]
274+
end
275+
return _BandedMatrix(data, axes(A, 1), bandwidths(A)...)
276+
end
267277
function _BandedMatrix(::DiagonalLayout, A::AbstractMatrix{T}) where T
268278
m,n = size(A)
269279
dat = Matrix{T}(undef, 1, n)

src/interfaceimpl.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ function bandeddata(D::Union{Diagonal, Transpose{<:Any, <:Diagonal}, Adjoint{<:A
3030
permutedims(diagonaldata(D))
3131
end
3232

33+
bandedrowsdata(Ac::Transpose) = permutedims(bandeddata(parent(Ac)))
34+
bandedrowsdata(Ac::Adjoint{<:Real}) = permutedims(bandeddata(parent(Ac)))
35+
3336
# treat subinds as banded
3437
sublayout(::DiagonalLayout{L}, inds::Type) where L = sublayout(bandedcolumns(L()), inds)
3538
sublayout(::DiagonalLayout{L}, inds::Type{<:NTuple{2,AbstractUnitRange{Int}}}) where L = sublayout(bandedcolumns(L()), inds)

test/test_banded.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,16 @@ include("mymatrix.jl")
600600
@test B2 == B
601601
@test typeof(B2) == typeof(B)
602602
end
603+
604+
@testset "_BandedMatrix(::BandedRows)" begin
605+
A = brand(5, 5, 2, 1)
606+
for B in (A', transpose(A))
607+
@test BandedMatrices._BandedMatrix(MemoryLayout(B), B) == B
608+
@test BandedMatrix(B) == B
609+
@test BandedMatrix(B) !== B
610+
@test BandedMatrices.bandeddata(BandedMatrix(B)) !== BandedMatrices.bandeddata(A)
611+
end
612+
end
603613
end
604614

605615
end # module

0 commit comments

Comments
 (0)