Skip to content

Commit

Permalink
Make BandedMatrix immutable (#403)
Browse files Browse the repository at this point in the history
* Make BandedMatrix immutable

* Don't export isbanded

* Add brandn

* Update BandedMatrices.jl

* Update index.md
  • Loading branch information
dlfivefifty authored Oct 3, 2023
1 parent 59f4758 commit ea56397
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 8 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 = "0.17.38"
version = "1.0.0"

[deps]
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
Expand Down
10 changes: 9 additions & 1 deletion docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ BandedMatrix
brand
```

```@docs
brandn
```

```@meta
DocTestSetup = quote
using BandedMatrices
Expand Down Expand Up @@ -98,6 +102,10 @@ band
BandRange
```

```@docs
BandedMatrices.isbanded
```

To loop over the nonzero elements of a BandedMatrix, you can use `colrange(A, c)` and `rowrange(A, r)`.


Expand All @@ -116,7 +124,7 @@ interface consists of the following:
| Required methods | Brief description |
| :--------------- | :--------------- |
| `bandwidths(A)` | Returns a tuple containing the sub-diagonal and super-diagonal bandwidth |
| `isbanded(A)` | Override to return `true` |
| `BandedMatrices.isbanded(A)` | Override to return `true` |

| Optional methods | Brief description |
| :--------------- | :--------------- |
Expand Down
2 changes: 1 addition & 1 deletion src/BandedMatrices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const TransposeFact = isdefined(LinearAlgebra, :TransposeFactorization) ?
export BandedMatrix,
bandrange,
brand,
brandn,
bandwidth,
BandError,
band,
Expand All @@ -56,7 +57,6 @@ export BandedMatrix,
bandwidths,
colrange,
rowrange,
isbanded,
Zeros,
Fill,
Ones,
Expand Down
11 changes: 9 additions & 2 deletions src/banded/BandedMatrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

function _BandedMatrix end

mutable struct BandedMatrix{T, CONTAINER, RAXIS} <: AbstractBandedMatrix{T}
struct BandedMatrix{T, CONTAINER, RAXIS} <: AbstractBandedMatrix{T}
data::CONTAINER # l+u+1 x n (# of columns)
raxis::RAXIS # axis for rows (col axis comes from data)
l::Int # lower bandwidth ≥0
Expand Down Expand Up @@ -163,7 +163,7 @@ promote_rule(::Type{BandedMatrix{T1, C1}}, ::Type{BandedMatrix{T2, C2}}) where {
BandedMatrix{promote_type(T1,T2), promote_type(C1, C2)}


for (op,bop) in ((:(rand),:brand),)
for (op,bop) in ((:rand,:brand), (:randn,:brandn))
@eval begin
$bop(::Type{T},n::Integer,m::Integer,a::Integer,b::Integer) where {T} =
_BandedMatrix($op(T,max(0,b+a+1),m),n,a,b)
Expand Down Expand Up @@ -193,6 +193,13 @@ Creates an `n×m` banded matrix with random numbers in the bandwidth of type `T
"""
brand

"""
brandn(T,n,m,l,u)
Creates an `n×m` banded matrix with random normals in the bandwidth of type `T` with bandwidths `(l,u)`
"""
brand

## Conversions from AbstractArrays, we include FillArrays in case `zeros` is ever faster
BandedMatrix{T}(A::AbstractMatrix, bnds::NTuple{2,Integer}) where T =
BandedMatrix{T, Matrix{T}}(A, bnds)
Expand Down
2 changes: 1 addition & 1 deletion test/test_subarray.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using BandedMatrices, FillArrays, ArrayLayouts, Test
import LinearAlgebra: axpy!
import BandedMatrices: BandedColumns, bandeddata, MemoryLayout, BandedSubBandedMatrix, _BandedMatrix, sub_materialize
import BandedMatrices: BandedColumns, bandeddata, MemoryLayout, BandedSubBandedMatrix, _BandedMatrix, sub_materialize, isbanded


@testset "BandedMatrix SubArray" begin
Expand Down
2 changes: 1 addition & 1 deletion test/test_symbanded.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using ArrayLayouts
using BandedMatrices
import BandedMatrices: MemoryLayout, SymmetricLayout, HermitianLayout, BandedColumns
import BandedMatrices: MemoryLayout, SymmetricLayout, HermitianLayout, BandedColumns, isbanded
using FillArrays
using GenericLinearAlgebra
using LinearAlgebra
Expand Down
2 changes: 1 addition & 1 deletion test/test_tribanded.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using BandedMatrices, LinearAlgebra, ArrayLayouts, Test
import BandedMatrices: BandedColumns, BandedRows
import BandedMatrices: BandedColumns, BandedRows, isbanded


@testset "Triangular" begin
Expand Down

2 comments on commit ea56397

@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/92677

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.0.0 -m "<description of version>" ea5639724fa4d861ef9d7f170d6ec88f9025044f
git push origin v1.0.0

Please sign in to comment.