From ea5639724fa4d861ef9d7f170d6ec88f9025044f Mon Sep 17 00:00:00 2001 From: Sheehan Olver Date: Tue, 3 Oct 2023 16:11:10 +0100 Subject: [PATCH] Make BandedMatrix immutable (#403) * Make BandedMatrix immutable * Don't export isbanded * Add brandn * Update BandedMatrices.jl * Update index.md --- Project.toml | 2 +- docs/src/index.md | 10 +++++++++- src/BandedMatrices.jl | 2 +- src/banded/BandedMatrix.jl | 11 +++++++++-- test/test_subarray.jl | 2 +- test/test_symbanded.jl | 2 +- test/test_tribanded.jl | 2 +- 7 files changed, 23 insertions(+), 8 deletions(-) diff --git a/Project.toml b/Project.toml index 7787cc6b..b21737d6 100644 --- a/Project.toml +++ b/Project.toml @@ -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" diff --git a/docs/src/index.md b/docs/src/index.md index 2c778e3d..5ba7b5aa 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -11,6 +11,10 @@ BandedMatrix brand ``` +```@docs +brandn +``` + ```@meta DocTestSetup = quote using BandedMatrices @@ -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)`. @@ -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 | | :--------------- | :--------------- | diff --git a/src/BandedMatrices.jl b/src/BandedMatrices.jl index 7e6268ee..914b97de 100644 --- a/src/BandedMatrices.jl +++ b/src/BandedMatrices.jl @@ -48,6 +48,7 @@ const TransposeFact = isdefined(LinearAlgebra, :TransposeFactorization) ? export BandedMatrix, bandrange, brand, + brandn, bandwidth, BandError, band, @@ -56,7 +57,6 @@ export BandedMatrix, bandwidths, colrange, rowrange, - isbanded, Zeros, Fill, Ones, diff --git a/src/banded/BandedMatrix.jl b/src/banded/BandedMatrix.jl index 3b1fcb9a..aed5eca3 100644 --- a/src/banded/BandedMatrix.jl +++ b/src/banded/BandedMatrix.jl @@ -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 @@ -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) @@ -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) diff --git a/test/test_subarray.jl b/test/test_subarray.jl index 99fc8dab..854b28c9 100644 --- a/test/test_subarray.jl +++ b/test/test_subarray.jl @@ -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 diff --git a/test/test_symbanded.jl b/test/test_symbanded.jl index 6c13b2bd..8174f884 100644 --- a/test/test_symbanded.jl +++ b/test/test_symbanded.jl @@ -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 diff --git a/test/test_tribanded.jl b/test/test_tribanded.jl index 357e04c4..13802ad6 100644 --- a/test/test_tribanded.jl +++ b/test/test_tribanded.jl @@ -1,5 +1,5 @@ using BandedMatrices, LinearAlgebra, ArrayLayouts, Test -import BandedMatrices: BandedColumns, BandedRows +import BandedMatrices: BandedColumns, BandedRows, isbanded @testset "Triangular" begin