Skip to content

Commit

Permalink
Support RectDiagonal (#411)
Browse files Browse the repository at this point in the history
  • Loading branch information
dlfivefifty authored Dec 3, 2023
1 parent 211877d commit 00ad0aa
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "BandedMatrices"
uuid = "aae01518-5342-5314-be14-df237901396f"
version = "1.2.1"
version = "1.3"

[deps]
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
Expand Down
2 changes: 1 addition & 1 deletion src/BandedMatrices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import ArrayLayouts: MemoryLayout, transposelayout, triangulardata,
_qr!, _qr, _lu!, _lu, _factorize, AbstractTridiagonalLayout, TridiagonalLayout,
BidiagonalLayout, bidiagonaluplo, diagonaldata, supdiagonaldata, subdiagonaldata, copymutable_oftype_layout, dualadjoint

import FillArrays: AbstractFill, getindex_value, _broadcasted_zeros, unique_value, OneElement
import FillArrays: AbstractFill, getindex_value, _broadcasted_zeros, unique_value, OneElement, RectDiagonal

const libblas = LinearAlgebra.BLAS.libblas
const liblapack = LinearAlgebra.BLAS.liblapack
Expand Down
8 changes: 4 additions & 4 deletions src/banded/BandedMatrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,10 @@ BandedMatrix{V,C,Base.OneTo{Int}}(Z::Zeros{T,2}, bnds::NTuple{2,Integer}) where
BandedMatrix{V}(Z::Zeros{T,2}, bnds::NTuple{2,Integer}) where {T,V} =
_BandedMatrix(zeros(V,max(0,sum(bnds)+1),size(Z,2)),size(Z,1),bnds...)

BandedMatrix(E::Eye{T}, bnds::NTuple{2,Integer}) where T = BandedMatrix{T}(E, bnds)
function BandedMatrix{T}(E::Eye, bnds::NTuple{2,Integer}) where T
ret=BandedMatrix(Zeros{T}(E), bnds)
ret[band(0)] .= one(T)
BandedMatrix(E::RectDiagonal{T}, bnds::NTuple{2,Integer}) where T = BandedMatrix{T}(E, bnds)
function BandedMatrix{T}(E::RectDiagonal, bnds::NTuple{2,Integer}) where T
ret = BandedMatrix(Zeros{T}(E), bnds)
ret[band(0)] .= E.diag
ret
end

Expand Down
6 changes: 3 additions & 3 deletions src/interfaceimpl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ isbanded(::Zeros) = true
bandwidths(::Zeros) = (-40320,-40320) # 40320 == prod(1:8), used for special cases involving gcd
inbands_getindex(::Zeros{T}, k::Integer, j::Integer) where T = zero(T)

isbanded(::Eye) = true
bandwidths(::Eye) = (0,0)
inbands_getindex(::Eye{T}, k::Integer, j::Integer) where T = one(T)
isbanded(::RectDiagonal) = true
bandwidths(::RectDiagonal) = (0,0)
inbands_getindex(E::RectDiagonal, k::Integer, j::Integer) = E.diag[k]

isbanded(::Diagonal) = true
bandwidths(::Diagonal) = (0,0)
Expand Down
4 changes: 4 additions & 0 deletions test/test_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ LinearAlgebra.fill!(A::PseudoBandedMatrix, v) = fill!(A.data,v)
@test B * Eye(5) == B
@test muladd!(2.0, Eye(5), B, 0.0, zeros(5,5)) == 2B
@test muladd!(2.0, B, Eye(5), 0.0, zeros(5,5)) == 2B

@test isbanded(2Eye(5,6))
@test bandwidths(2Eye(5,6)) == (0,0)
@test BandedMatrices.inbands_getindex(2Eye(5,6), 1,1) == 2
end

@testset "Diagonal" begin
Expand Down

2 comments on commit 00ad0aa

@dlfivefifty
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/96387

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.3.0 -m "<description of version>" 00ad0aa290c716cfb6b312180becae93641dcb5d
git push origin v1.3.0

Please sign in to comment.