### colstart example Source: https://julialinearalgebra.github.io/BandedMatrices.jl Creates a 4x4 banded matrix with bandwidths (0,1) and shows colstart for columns 3 and 4. ```julia julia> A = BandedMatrix(0=>1:4, 1=>5:7) 4×4 BandedMatrix{Int64} with bandwidths (0, 1): 1 5 ⋅ ⋅ ⋅ 2 6 ⋅ ⋅ ⋅ 3 7 ⋅ ⋅ ⋅ 4 julia> BandedMatrices.colstart(A, 3) 2 julia> BandedMatrices.colstart(A, 4) 3 ``` -------------------------------- ### colstop example Source: https://julialinearalgebra.github.io/BandedMatrices.jl Creates a 4x4 banded matrix with bandwidths (0,1) and shows colstop for columns 3 and 4. ```julia julia> A = BandedMatrix(0=>1:4, 1=>5:7) 4×4 BandedMatrix{Int64} with bandwidths (0, 1): 1 5 ⋅ ⋅ ⋅ 2 6 ⋅ ⋅ ⋅ 3 7 ⋅ ⋅ ⋅ 4 julia> BandedMatrices.colstop(A, 3) 3 julia> BandedMatrices.colstop(A, 4) 4 ``` -------------------------------- ### Create banded matrix with constant bands Source: https://julialinearalgebra.github.io/BandedMatrices.jl Example showing how to set constant bands for a finite difference approximation. ```julia n = 128 h = 1/n A = BandedMatrix{Float64}(undef, (n,n), (1,1)) A[band(0)] .= -2/h^2 A[band(1)] .= A[band(-1)] .= 1/h^2 ``` -------------------------------- ### collength example Source: https://julialinearalgebra.github.io/BandedMatrices.jl Creates a 4x4 banded matrix with bandwidths (0,1) and shows collength for columns 1 and 2. ```julia julia> A = BandedMatrix(0=>1:4, 1=>5:7) 4×4 BandedMatrix{Int64} with bandwidths (0, 1): 1 5 ⋅ ⋅ ⋅ 2 6 ⋅ ⋅ ⋅ 3 7 ⋅ ⋅ ⋅ 4 julia> BandedMatrices.collength(A, 1) 1 julia> BandedMatrices.collength(A, 2) 2 ``` -------------------------------- ### colrange example Source: https://julialinearalgebra.github.io/BandedMatrices.jl Creates a 4x4 banded matrix with bandwidths (0,1) and shows colrange for columns 1 and 3. ```julia julia> A = BandedMatrix(0=>1:4, 1=>5:7) 4×4 BandedMatrix{Int64} with bandwidths (0, 1): 1 5 ⋅ ⋅ ⋅ 2 6 ⋅ ⋅ ⋅ 3 7 ⋅ ⋅ ⋅ 4 julia> colrange(A, 1) 1:1 julia> colrange(A, 3) 2:3 ``` -------------------------------- ### BandError example Source: https://julialinearalgebra.github.io/BandedMatrices.jl Creates a banded matrix and checks that BandError(A, 1) is an instance of BandError. ```julia julia> A = BandedMatrix(0 => 1:3); julia> BandError(A, 1) isa BandError true ``` -------------------------------- ### rowstart function signature Source: https://julialinearalgebra.github.io/BandedMatrices.jl Return the starting row index of the filled bands in the i-th row. ```julia rowstart(A, i::Integer) ``` -------------------------------- ### rowstart(A, i::Integer) Source: https://julialinearalgebra.github.io/BandedMatrices.jl Return the starting column index of the filled bands in the i-th row, bounded by the actual matrix size. ```APIDOC ## rowstart(A, i::Integer) ### Description Return the starting column index of the filled bands in the `i`-th row, bounded by the actual matrix size. ### Function Signature `rowstart(A, i::Integer)` ### Parameters - **A** (AbstractMatrix) - Required - The banded matrix. - **i** (Integer) - Required - Row index. ### Returns - **Int** - Starting column index. ``` -------------------------------- ### Create banded matrices with Zeros, Eye, and Ones Source: https://julialinearalgebra.github.io/BandedMatrices.jl Examples of creating banded matrices initialized with Zeros, Eye, or Ones. ```julia julia> BandedMatrix(Zeros(5,5), (1,2)) 5×5 BandedMatrix{Float64} with bandwidths (1, 2): 0.0 0.0 0.0 ⋅ ⋅ 0.0 0.0 0.0 0.0 ⋅ ⋅ 0.0 0.0 0.0 0.0 ⋅ ⋅ 0.0 0.0 0.0 ⋅ ⋅ ⋅ 0.0 0.0 julia> BandedMatrix(Eye(5), (1,2)) 5×5 BandedMatrix{Float64} with bandwidths (1, 2): 1.0 0.0 0.0 ⋅ ⋅ 0.0 1.0 0.0 0.0 ⋅ ⋅ 0.0 1.0 0.0 0.0 ⋅ ⋅ 0.0 1.0 0.0 ⋅ ⋅ ⋅ 0.0 1.0 julia> BandedMatrix(Ones(5,5), (1,2)) 5×5 BandedMatrix{Float64} with bandwidths (1, 2): 1.0 1.0 1.0 ⋅ ⋅ 1.0 1.0 1.0 1.0 ⋅ ⋅ 1.0 1.0 1.0 1.0 ⋅ ⋅ 1.0 1.0 1.0 ⋅ ⋅ ⋅ 1.0 1.0 ``` -------------------------------- ### colstart(A, i::Integer) Source: https://julialinearalgebra.github.io/BandedMatrices.jl Return the starting row index of the filled bands in the i-th column, bounded by the actual matrix size. ```APIDOC ## colstart(A, i::Integer) ### Description Return the starting row index of the filled bands in the `i`-th column, bounded by the actual matrix size. ### Function Signature `colstart(A, i::Integer)` ### Parameters - **A** (AbstractMatrix) - Required - The banded matrix. - **i** (Integer) - Required - Column index. ### Returns - **Int** - Starting row index. ### Examples ```julia julia> A = BandedMatrix(0=>1:4, 1=>5:7) 4×4 BandedMatrix{Int64} with bandwidths (0, 1): 1 5 ⋅ ⋅ ⋅ 2 6 ⋅ ⋅ ⋅ 3 7 ⋅ ⋅ ⋅ 4 julia> BandedMatrices.colstart(A, 3) 2 julia> BandedMatrices.colstart(A, 4) 3 ``` ``` -------------------------------- ### BandSlice example Source: https://julialinearalgebra.github.io/BandedMatrices.jl Creates a banded matrix, converts Band(1) to a BandSlice via to_indices, and checks that it equals diagind(B, 1). ```julia julia> B = BandedMatrix(0 => 1:4, 1=>1:3); julia> bs = to_indices(B, (Band(1),))[1]; julia> bs isa BandedMatrices.BandSlice true julia> using LinearAlgebra julia> bs == diagind(B, 1) true ``` -------------------------------- ### BandedMatrices.rowstart(A, i::Integer) Source: https://julialinearalgebra.github.io/BandedMatrices.jl Returns the starting column index of the filled bands in the i-th row, bounded by the actual matrix size. ```APIDOC ## BandedMatrices.rowstart(A, i::Integer) ### Description Returns the starting column index of the filled bands in the i-th row, bounded by the actual matrix size. ### Function Signature `rowstart(A, i::Integer)` ### Parameters - **A** (BandedMatrix) - The banded matrix. - **i** (Integer) - The row index. ### Returns - **Integer** - The starting column index of the filled bands in row i. ### Examples ```julia julia> A = BandedMatrix(0=>1:4, 1=>5:7) 4×4 BandedMatrix{Int64} with bandwidths (0, 1): 1 5 ⋅ ⋅ ⋅ 2 6 ⋅ ⋅ ⋅ 3 7 ⋅ ⋅ ⋅ 4 julia> BandedMatrices.rowstart(A, 2) 2 julia> BandedMatrices.rowstart(A, 3) 3 ``` ``` -------------------------------- ### Access rowstart of a BandedMatrix Source: https://julialinearalgebra.github.io/BandedMatrices.jl Returns the starting column index of the filled bands in the i-th row, bounded by the matrix size. ```julia julia> A = BandedMatrix(0=>1:4, 1=>5:7) 4×4 BandedMatrix{Int64} with bandwidths (0, 1): 1 5 ⋅ ⋅ ⋅ 2 6 ⋅ ⋅ ⋅ 3 7 ⋅ ⋅ ⋅ 4 julia> BandedMatrices.rowstart(A, 2) 2 julia> BandedMatrices.rowstart(A, 3) 3 ``` -------------------------------- ### colstart function signature Source: https://julialinearalgebra.github.io/BandedMatrices.jl Return the starting row index of the filled bands in the i-th column, bounded by the actual matrix size. ```julia colstart(A, i::Integer) ``` -------------------------------- ### Performance comparison: Dense vs Structured Source: https://julialinearalgebra.github.io/BandedMatrices.jl Demonstrates the performance difference when creating a BandedMatrix from a dense matrix versus a structured matrix. ```julia julia> @time BandedMatrix(ones(10000,10000),(0,0)); 0.775120 seconds (10 allocations: 763.016 MiB, 28.04% gc time) julia> @time BandedMatrix(Ones(10000,10000),(0,0)); 0.000074 seconds (9 allocations: 78.469 KiB) ``` -------------------------------- ### Using Band to select diagonals Source: https://julialinearalgebra.github.io/BandedMatrices.jl Creates a banded matrix and checks that Band(0) and Band(1) select the main diagonal and superdiagonal, respectively. ```julia julia> A = BandedMatrix(0 => 1:3, 1 => 4:5); julia> A[Band(0)] == [1, 2, 3] true julia> A[Band(1)] == [4, 5] true ``` -------------------------------- ### Using band to access diagonals Source: https://julialinearalgebra.github.io/BandedMatrices.jl Creates a 4x4 banded matrix with bandwidths (1,1) and uses band(1), band(0), and band(-1) to extract the superdiagonal, main diagonal, and subdiagonal as vectors. ```julia julia> using BandedMatrices julia> A = BandedMatrix(0=>1:4, 1=>5:7, -1=>8:10) 4×4 BandedMatrix{Int64} with bandwidths (1, 1): 1 5 ⋅ ⋅ 8 2 6 ⋅ ⋅ 9 3 7 ⋅ ⋅ 10 4 julia> A[band(1)] 3-element Vector{Int64}: 5 6 7 julia> A[band(0)] 4-element Vector{Int64}: 1 2 3 4 julia> A[band(-1)] 3-element Vector{Int64}: 8 9 10 ``` -------------------------------- ### Initialize uninitialized BandedMatrix Source: https://julialinearalgebra.github.io/BandedMatrices.jl Creates an uninitialized n×m banded matrix of type T with specified bandwidths (l,u). ```julia BandedMatrix{T}(undef, (n, m), (l, u)) ``` -------------------------------- ### BandedMatrix(Zeros(n,m), (l,u)) Source: https://julialinearalgebra.github.io/BandedMatrices.jl Creates a banded matrix of all zeros with the given bandwidths. ```APIDOC ## BandedMatrix(Zeros(n,m), (l,u)) ### Description Creates a banded matrix of all zeros with the given bandwidths. ### Signature BandedMatrix(Zeros(n,m), (l,u)) ### Parameters - **Zeros(n,m)** (AbstractMatrix) - Required - A structured matrix of zeros with dimensions n x m. - **l** (Integer) - Required - Lower bandwidth. - **u** (Integer) - Required - Upper bandwidth. ### Returns A BandedMatrix of zeros with the specified bandwidths. ``` -------------------------------- ### BandedMatrix(Ones(n,m), (l,u)) Source: https://julialinearalgebra.github.io/BandedMatrices.jl Creates a banded matrix with constant value 1 in the bandwidth with the given bandwidths. ```APIDOC ## BandedMatrix(Ones(n,m), (l,u)) ### Description Creates a banded matrix with constant value 1 in the bandwidth with the given bandwidths. ### Signature BandedMatrix(Ones(n,m), (l,u)) ### Parameters - **Ones(n,m)** (AbstractMatrix) - Required - A structured matrix of ones with dimensions n x m. - **l** (Integer) - Required - Lower bandwidth. - **u** (Integer) - Required - Upper bandwidth. ### Returns A BandedMatrix with ones in the bandwidth and zeros elsewhere. ``` -------------------------------- ### Construct BandedMatrix from diagonals Source: https://julialinearalgebra.github.io/BandedMatrices.jl Constructs a m × n BandedMatrix with bandwidths (l,u) using Pairs of diagonals and vectors. ```julia BandedMatrix{T}(kv::Pair, (m,n), (l,u)) ``` -------------------------------- ### Using BandRange to access a row Source: https://julialinearalgebra.github.io/BandedMatrices.jl Creates a 4x4 banded matrix and uses A[2, BandRange] to extract the entries in row 2 that lie inside the bands. ```julia julia> using BandedMatrices julia> A = BandedMatrix(0=>1:4, 1=>5:7, -1=>8:10) 4×4 BandedMatrix{Int64} with bandwidths (1, 1): 1 5 ⋅ ⋅ 8 2 6 ⋅ ⋅ 9 3 7 ⋅ ⋅ 10 4 julia> A[2, BandRange] 3-element Vector{Int64}: 8 2 6 ``` -------------------------------- ### Create random banded matrix with brandn Source: https://julialinearalgebra.github.io/BandedMatrices.jl Creates an n×m banded matrix with random normals in the bandwidth of type T. ```julia brandn(T,n,m,l,u) ``` -------------------------------- ### bandwidth(A, i) Source: https://julialinearalgebra.github.io/BandedMatrices.jl Returns the lower bandwidth (i==1) or the upper bandwidth (i==2) of a banded matrix. ```APIDOC ## bandwidth(A, i) ### Description Returns the lower bandwidth (`i==1`) or the upper bandwidth (`i==2`) of a banded matrix. ### Function Signature `bandwidth(A, i)` ### Parameters - **A** (AbstractMatrix) - Required - The banded matrix. - **i** (Int) - Required - Specifies which bandwidth to return: 1 for lower, 2 for upper. ### Returns - **Int** - The requested bandwidth. ``` -------------------------------- ### Minimize bandwidth with symrcm Source: https://julialinearalgebra.github.io/BandedMatrices.jl Uses the reverse Cuthill-McKee algorithm to permute a symmetric matrix into a band matrix with smaller bandwidth. ```julia julia> using BandedMatrices, CliqueTrees julia> matrix = [ 1 0 1 0 0 0 0 1 1 0 1 1 0 0 1 1 1 0 1 1 1 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 1 0 1 1 0 0 1 0 0 0 1 1 0 0 0 1 0 0 1 1 1 0 0 1 1 0 1 1 0 0 1 0 1 0 0 1 0 0 0 0 1 ]; julia> bandedmatrix, perm, invp = symrcm(matrix); julia> bandedmatrix 9×9 LinearAlgebra.Symmetric{Int64, BandedMatrix{Int64, Matrix{Int64}, Base.OneTo{Int64}}}: 1 1 1 0 ⋅ ⋅ ⋅ ⋅ ⋅ 1 1 1 1 0 ⋅ ⋅ ⋅ ⋅ 1 1 1 0 1 1 ⋅ ⋅ ⋅ 0 1 0 1 0 1 0 ⋅ ⋅ ⋅ 0 1 0 1 0 1 0 ⋅ ⋅ ⋅ 1 1 0 1 1 1 0 ⋅ ⋅ ⋅ 0 1 1 1 0 1 ⋅ ⋅ ⋅ ⋅ 0 1 0 1 1 ⋅ ⋅ ⋅ ⋅ ⋅ 0 1 1 1 julia> bandedmatrix == matrix[perm, perm] true ``` -------------------------------- ### bandrange(A) Source: https://julialinearalgebra.github.io/BandedMatrices.jl Returns the range -bandwidth(A,1):bandwidth(A,2). ```APIDOC ## bandrange(A) ### Description Returns the range `-bandwidth(A,1):bandwidth(A,2)`. ### Function Signature `bandrange(A)` ### Parameters - **A** (AbstractMatrix) - Required - The banded matrix. ### Returns - **UnitRange{Int}** - The range of diagonal offsets covered by the bands. ``` -------------------------------- ### bandwidths(A) Source: https://julialinearalgebra.github.io/BandedMatrices.jl Returns a tuple containing the lower and upper bandwidth of A, in order. ```APIDOC ## bandwidths(A) ### Description Returns a tuple containing the lower and upper bandwidth of `A`, in order. ### Function Signature `bandwidths(A)` ### Parameters - **A** (AbstractMatrix) - Required - The banded matrix whose bandwidths are queried. ### Returns - **Tuple{Int, Int}** - A tuple `(lower_bandwidth, upper_bandwidth)`. ``` -------------------------------- ### Create random banded matrix with brand Source: https://julialinearalgebra.github.io/BandedMatrices.jl Creates an n×m banded matrix with random numbers in the bandwidth of type T. ```julia brand(T,n,m,l,u) ``` -------------------------------- ### Banded matrix interface Source: https://julialinearalgebra.github.io/BandedMatrices.jl The banded matrix interface allows custom matrix types to be treated as banded matrices. It consists of required methods (`bandwidths`, `BandedMatrices.isbanded`) and optional methods (`inbands_getindex`, `inbands_setindex!`, `BandedMatrices.MemoryLayout`, `BandedMatrices.bandeddata`, `BandedMatrices.bandedrowsdata`). ```APIDOC ## Banded matrix interface ### Description The banded matrix interface allows custom matrix types to be treated as banded matrices. Implementing the required methods enables utility functions from the package to work with these types. Optional methods provide additional functionality such as lazy linear algebra and efficient data access. ### Required Methods - **bandwidths(A)** - Returns a tuple containing the sub-diagonal and super-diagonal bandwidth. - **BandedMatrices.isbanded(A)** - Override to return `true`. ### Optional Methods - **inbands_getindex(A, k, j)** - Unsafe: return `A[k,j]`, without the need to check if we are inside the bands. - **inbands_setindex!(A, v, k, j)** - Unsafe: set `A[k,j] = v`, without the need to check if we are inside the bands. - **BandedMatrices.MemoryLayout(A)** - Override to get banded lazy linear algebra, e.g. `y .= Mul(A,x)`. - **BandedMatrices.bandeddata(A)** - Override to return a matrix of the entries in BLAS format. Required if `MemoryLayout(A)` returns `BandedColumnMajor`. - **BandedMatrices.bandedrowsdata(A)** - Override to return a matrix of the entries reshaped to a row-major format. Required if `MemoryLayout(A)` returns `BandedRowsMajor`. ### Notes Certain `SubArray`s of `BandedMatrix` are also banded matrices. The banded matrix interface is implemented for such `SubArray`s to take advantage of this. ``` -------------------------------- ### Construct square BandedMatrix from diagonals Source: https://julialinearalgebra.github.io/BandedMatrices.jl Constructs a square matrix from Pairs of diagonals and vectors. ```julia BandedMatrix(kv::Pair{<:Integer,<:AbstractVector}...) ``` -------------------------------- ### Performance comparison: Hcat vs LazyArrays Source: https://julialinearalgebra.github.io/BandedMatrices.jl Demonstrates the performance improvement using LazyArrays when concatenating matrices. ```julia julia> @time BandedMatrix([Ones(10000,5000) Zeros(10000,5000)],(1,1)); 0.346918 seconds (22 allocations: 763.169 MiB, 8.38% gc time) julia> using LazyArrays julia> @time BandedMatrix(Hcat(Ones(10000,5000),Zeros(10000,5000)),(1,1)); 0.012627 seconds (30.01 k allocations: 1.374 MiB, 92.24% gc time) ``` -------------------------------- ### bandrange function signature Source: https://julialinearalgebra.github.io/BandedMatrices.jl Returns the range -bandwidth(A,1):bandwidth(A,2). ```julia bandrange(A) ``` -------------------------------- ### bandwidth function signature Source: https://julialinearalgebra.github.io/BandedMatrices.jl Returns the lower bandwidth (i==1) or the upper bandwidth (i==2). ```julia bandwidth(A,i) ``` -------------------------------- ### BandedMatrix{T}(kv::Pair, (m,n), (l,u)) Source: https://julialinearalgebra.github.io/BandedMatrices.jl Constructs an m x n banded matrix with bandwidths (l, u) from a Pair of diagonal index and vector. ```APIDOC ## BandedMatrix{T}(kv::Pair, (m,n), (l,u)) ### Description Constructs an m x n BandedMatrix with bandwidths (l, u) from a Pair of diagonal index and vector. The vector kv.second is placed on the kv.first diagonal. ### Signature BandedMatrix{T}(kv::Pair, (m,n), (l,u)) ### Parameters - **T** (Type) - Required - Element type of the matrix. - **kv** (Pair{<:Integer,<:AbstractVector}) - Required - Pair where the first element is the diagonal index and the second is the vector to place on that diagonal. - **m** (Integer) - Required - Number of rows. - **n** (Integer) - Required - Number of columns. - **l** (Integer) - Required - Lower bandwidth. - **u** (Integer) - Required - Upper bandwidth. ### Returns A BandedMatrix of type T with the specified dimensions and bandwidths, with the given vector placed on the specified diagonal. ``` -------------------------------- ### bandwidths function signature Source: https://julialinearalgebra.github.io/BandedMatrices.jl Returns a tuple containing the lower and upper bandwidth of A, in order. ```julia bandwidths(A) ``` -------------------------------- ### collength(A, i::Integer) Source: https://julialinearalgebra.github.io/BandedMatrices.jl Return the number of filled bands in the i-th column. ```APIDOC ## collength(A, i::Integer) ### Description Return the number of filled bands in the `i`-th column. ### Function Signature `collength(A, i::Integer)` ### Parameters - **A** (AbstractMatrix) - Required - The banded matrix. - **i** (Integer) - Required - Column index. ### Returns - **Int** - Number of filled bands. ### Examples ```julia julia> A = BandedMatrix(0=>1:4, 1=>5:7) 4×4 BandedMatrix{Int64} with bandwidths (0, 1): 1 5 ⋅ ⋅ ⋅ 2 6 ⋅ ⋅ ⋅ 3 7 ⋅ ⋅ ⋅ 4 julia> BandedMatrices.collength(A, 1) 1 julia> BandedMatrices.collength(A, 2) 2 ``` ``` -------------------------------- ### Compute eigenvalues with KrylovKit Source: https://julialinearalgebra.github.io/BandedMatrices.jl Use KrylovKit to compute eigenvalues for a BandedMatrix by leveraging matrix-vector operations. ```julia using KrylovKit A = BandedMatrix(Eye(5), (1, 1)) KrylovKit.eigsolve(A, 1, :LR) ``` -------------------------------- ### BandedMatrix(kv::Pair{<:Integer,<:AbstractVector}...) Source: https://julialinearalgebra.github.io/BandedMatrices.jl Constructs a square banded matrix from multiple Pairs of diagonal indices and vectors. ```APIDOC ## BandedMatrix(kv::Pair{<:Integer,<:AbstractVector}...) ### Description Constructs a square matrix from Pairs of diagonals and vectors. Each vector kv.second is placed on the kv.first diagonal. ### Signature BandedMatrix(kv::Pair{<:Integer,<:AbstractVector}...) ### Parameters - **kv** (Pair{<:Integer,<:AbstractVector}...) - Required - One or more Pairs where the first element is the diagonal index and the second is the vector to place on that diagonal. ### Returns A square BandedMatrix with the specified diagonals filled with the given vectors. ``` -------------------------------- ### BandedMatrices.dataview(V::BandedMatrices.BandedMatrixBand) Source: https://julialinearalgebra.github.io/BandedMatrices.jl Forward a view of a band of a BandedMatrix to the parent's data matrix. This will error if the indexing is out-of-bounds for the data matrix, even if it is inbounds for the parent BandedMatrix. ```APIDOC ## BandedMatrices.dataview(V::BandedMatrices.BandedMatrixBand) ### Description Forward a view of a band of a `BandedMatrix` to the parent's data matrix. **Warning:** This will error if the indexing is out-of-bounds for the data matrix, even if it is inbounds for the parent `BandedMatrix`. ### Function Signature `dataview(V::BandedMatrices.BandedMatrixBand)` ### Parameters - **V** (BandedMatrixBand) - The band view. ### Returns - **SubArray** - A view of the parent's data matrix. ### Examples ```julia julia> A = BandedMatrix(0=>1:4, 1=>5:7, -1=>8:10) 4×4 BandedMatrix{Int64} with bandwidths (1, 1): 1 5 ⋅ ⋅ 8 2 6 ⋅ ⋅ 9 3 7 ⋅ ⋅ 10 4 julia> v = view(A, band(1)); julia> BandedMatrices.dataview(v) 3-element view(::Matrix{Int64}, 1, 2:4) with eltype Int64: 5 6 7 ``` ``` -------------------------------- ### BandedMatrix{T}(undef, (n, m), (l, u)) Source: https://julialinearalgebra.github.io/BandedMatrices.jl Constructs an uninitialized n x m banded matrix of type T with bandwidths (l, u). ```APIDOC ## BandedMatrix{T}(undef, (n, m), (l, u)) ### Description Returns an uninitialized n x m banded matrix of type T with bandwidths (l, u). ### Signature BandedMatrix{T}(undef, (n, m), (l, u)) ### Parameters - **T** (Type) - Required - Element type of the matrix. - **undef** (UndefInitializer) - Required - Indicates uninitialized storage. - **n** (Integer) - Required - Number of rows. - **m** (Integer) - Required - Number of columns. - **l** (Integer) - Required - Lower bandwidth. - **u** (Integer) - Required - Upper bandwidth. ### Returns An uninitialized BandedMatrix of type T with the specified dimensions and bandwidths. ``` -------------------------------- ### brand(T,n,m,l,u) Source: https://julialinearalgebra.github.io/BandedMatrices.jl Creates an n x m banded matrix with random numbers in the bandwidth of type T with bandwidths (l, u). ```APIDOC ## brand(T,n,m,l,u) ### Description Creates an n x m banded matrix with random numbers in the bandwidth of type T with bandwidths (l, u). ### Signature brand(T,n,m,l,u) ### Parameters - **T** (Type) - Required - Element type of the matrix. - **n** (Integer) - Required - Number of rows. - **m** (Integer) - Required - Number of columns. - **l** (Integer) - Required - Lower bandwidth. - **u** (Integer) - Required - Upper bandwidth. ### Returns A BandedMatrix of type T with random entries in the bandwidth. ``` -------------------------------- ### brandn(T,n,m,l,u) Source: https://julialinearalgebra.github.io/BandedMatrices.jl Creates an n x m banded matrix with random normal numbers in the bandwidth of type T with bandwidths (l, u). ```APIDOC ## brandn(T,n,m,l,u) ### Description Creates an n x m banded matrix with random normal numbers in the bandwidth of type T with bandwidths (l, u). ### Signature brandn(T,n,m,l,u) ### Parameters - **T** (Type) - Required - Element type of the matrix. - **n** (Integer) - Required - Number of rows. - **m** (Integer) - Required - Number of columns. - **l** (Integer) - Required - Lower bandwidth. - **u** (Integer) - Required - Upper bandwidth. ### Returns A BandedMatrix of type T with random normal entries in the bandwidth. ``` -------------------------------- ### Band(i) Source: https://julialinearalgebra.github.io/BandedMatrices.jl Index selector for the diagonal at offset i of a banded matrix. Band(0) selects the main diagonal, positive offsets select superdiagonals, and negative offsets select subdiagonals. ```APIDOC ## Band(i) ### Description Index selector for the diagonal at offset `i` of a banded matrix. `Band(0)` selects the main diagonal, positive offsets select superdiagonals, and negative offsets select subdiagonals. ### Type `Band(i)` ### Fields - **i::Int** - Diagonal offset from the main diagonal. ### Arguments - **i::Int** - Diagonal offset to select. ### Examples ```julia julia> A = BandedMatrix(0 => 1:3, 1 => 4:5); julia> A[Band(0)] == [1, 2, 3] true julia> A[Band(1)] == [4, 5] true ``` ``` -------------------------------- ### BandedMatrix(Eye(n), (l,u)) Source: https://julialinearalgebra.github.io/BandedMatrices.jl Creates a banded identity matrix with the given bandwidths. ```APIDOC ## BandedMatrix(Eye(n), (l,u)) ### Description Creates a banded identity matrix with the given bandwidths. ### Signature BandedMatrix(Eye(n), (l,u)) ### Parameters - **Eye(n)** (AbstractMatrix) - Required - A structured identity matrix of size n x n. - **l** (Integer) - Required - Lower bandwidth. - **u** (Integer) - Required - Upper bandwidth. ### Returns A BandedMatrix representing the identity matrix with the specified bandwidths. ``` -------------------------------- ### BandedMatrix{Float64}(undef, (n,n), (1,1)) with band assignment Source: https://julialinearalgebra.github.io/BandedMatrices.jl Creates a banded matrix with constant bands by assigning values to specific diagonals using the band function. ```APIDOC ## BandedMatrix{Float64}(undef, (n,n), (1,1)) with band assignment ### Description Creates a banded matrix of a given size with constant bands, such as the classical finite difference approximation of the one-dimensional Laplacian. The band function is used to assign values to specific diagonals. ### Example n = 128 h = 1/n A = BandedMatrix{Float64}(undef, (n,n), (1,1)) A[band(0)] .= -2/h^2 A[band(1)] .= A[band(-1)] .= 1/h^2 ``` -------------------------------- ### symrcm(matrix) Source: https://julialinearalgebra.github.io/BandedMatrices.jl The reverse Cuthill-McKee algorithm permutes a symmetric matrix into a band matrix with small bandwidth. It returns a tuple containing the banded matrix, the permutation vector, and the inverse permutation vector. ```APIDOC ## symrcm(matrix) ### Description The reverse Cuthill-McKee algorithm permutes a symmetric matrix into a band matrix with small bandwidth. It returns a tuple containing the banded matrix, the permutation vector, and the inverse permutation vector. ### Method `symrcm(matrix)` ### Parameters - **matrix** (Matrix) - Required - A symmetric matrix to be permuted. ### Returns - **bandedmatrix** (Symmetric{BandedMatrix}) - The permuted matrix in banded form. - **perm** (Vector) - The permutation vector. - **invp** (Vector) - The inverse permutation vector. ### Example ```julia using BandedMatrices, CliqueTrees matrix = [ 1 0 1 0 0 0 0 1 1 0 1 1 0 0 1 1 1 0 1 1 1 0 0 0 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 1 0 1 1 0 0 1 0 0 0 1 1 0 0 0 1 0 0 1 1 1 0 0 1 1 0 1 1 0 0 1 0 1 0 0 1 0 0 0 0 1 ]; bandedmatrix, perm, invp = symrcm(matrix); ``` ``` -------------------------------- ### Access dataview of a band Source: https://julialinearalgebra.github.io/BandedMatrices.jl Forwards a view of a band of a BandedMatrix to the parent's data matrix. This will error if the indexing is out-of-bounds for the data matrix. ```julia dataview(V::BandedMatrices.BandedMatrixBand) ``` ```julia julia> A = BandedMatrix(0=>1:4, 1=>5:7, -1=>8:10) 4×4 BandedMatrix{Int64} with bandwidths (1, 1): 1 5 ⋅ ⋅ 8 2 6 ⋅ ⋅ 9 3 7 ⋅ ⋅ 10 4 julia> v = view(A, band(1)); julia> BandedMatrices.dataview(v) 3-element view(::Matrix{Int64}, 1, 2:4) with eltype Int64: 5 6 7 ``` -------------------------------- ### BandedMatrices.bandeddata(A) Source: https://julialinearalgebra.github.io/BandedMatrices.jl Returns a matrix containing the data of a banded matrix, in the BLAS format. This is required for gbmv! support. ```APIDOC ## BandedMatrices.bandeddata(A) ### Description Returns a matrix containing the data of a banded matrix, in the BLAS format. This is required for gbmv! support. ### Function Signature `bandeddata(A)` ### Parameters - **A** (BandedMatrix) - The banded matrix. ### Returns - **Matrix** - The data matrix in BLAS format. ``` -------------------------------- ### BandError type signatures Source: https://julialinearalgebra.github.io/BandedMatrices.jl Exception thrown when an operation accesses diagonal offset i outside the stored lower and upper bandwidths of A. Three constructors are shown. ```julia BandError(A, i) BandError(A, (k, j)) BandError(A) ``` -------------------------------- ### BandError(A, i), BandError(A, (k, j)), BandError(A) Source: https://julialinearalgebra.github.io/BandedMatrices.jl Exception thrown when an operation accesses diagonal offset i outside the stored lower and upper bandwidths of A. ```APIDOC ## BandError(A, i), BandError(A, (k, j)), BandError(A) ### Description Exception thrown when an operation accesses diagonal offset `i` outside the stored lower and upper bandwidths of `A`. ### Type `BandError(A, i)` `BandError(A, (k, j))` `BandError(A)` ### Fields - **A::AbstractMatrix** - Matrix whose band structure rejects the access. - **i::Int** - Requested diagonal offset, with positive offsets above and negative offsets below the main diagonal. ### Arguments - **A::AbstractMatrix** - Matrix whose band structure is being accessed. - **i::Int** - Requested diagonal offset. - **(k, j)::Tuple{Int, Int}** - Matrix coordinates from which the diagonal offset `j - k` is computed. ### Examples ```julia julia> A = BandedMatrix(0 => 1:3); julia> BandError(A, 1) isa BandError true ``` ``` -------------------------------- ### colstop(A, i::Integer) Source: https://julialinearalgebra.github.io/BandedMatrices.jl Return the stopping row index of the filled bands in the i-th column, bounded by the actual matrix size. ```APIDOC ## colstop(A, i::Integer) ### Description Return the stopping row index of the filled bands in the `i`-th column, bounded by the actual matrix size. ### Function Signature `colstop(A, i::Integer)` ### Parameters - **A** (AbstractMatrix) - Required - The banded matrix. - **i** (Integer) - Required - Column index. ### Returns - **Int** - Stopping row index. ### Examples ```julia julia> A = BandedMatrix(0=>1:4, 1=>5:7) 4×4 BandedMatrix{Int64} with bandwidths (0, 1): 1 5 ⋅ ⋅ ⋅ 2 6 ⋅ ⋅ ⋅ 3 7 ⋅ ⋅ ⋅ 4 julia> BandedMatrices.colstop(A, 3) 3 julia> BandedMatrices.colstop(A, 4) 4 ``` ``` -------------------------------- ### band(i) Source: https://julialinearalgebra.github.io/BandedMatrices.jl Represents the i-th band of a banded matrix. Used as an index selector. ```APIDOC ## band(i) ### Description Represents the `i`-th band of a banded matrix. Used as an index selector. ### Function Signature `band(i)` ### Parameters - **i** (Int) - Required - Diagonal offset: 0 for main diagonal, positive for superdiagonals, negative for subdiagonals. ### Returns - **Band** - A band selector object. ### Example ```julia julia> using BandedMatrices julia> A = BandedMatrix(0=>1:4, 1=>5:7, -1=>8:10) 4×4 BandedMatrix{Int64} with bandwidths (1, 1): 1 5 ⋅ ⋅ 8 2 6 ⋅ ⋅ 9 3 7 ⋅ ⋅ 10 4 julia> A[band(1)] 3-element Vector{Int64}: 5 6 7 julia> A[band(0)] 4-element Vector{Int64}: 1 2 3 4 julia> A[band(-1)] 3-element Vector{Int64}: 8 9 10 ``` ``` -------------------------------- ### Banded matrix representation Source: https://julialinearalgebra.github.io/BandedMatrices.jl Visual representation of a banded matrix and its corresponding internal data storage structure. ```text [ a_11 a_12 ⋅ ⋅ a_21 a_22 a_23 ⋅ a_31 a_32 a_33 a_34 ⋅ a_42 a_43 a_44 ] ``` ```text [ ⋅ a_12 a_23 a_34 a_11 a_22 a_33 a_44 a_21 a_32 a_43 ⋅ a_31 a_42 ⋅ ⋅ ] ``` -------------------------------- ### BandRange constant signature Source: https://julialinearalgebra.github.io/BandedMatrices.jl Represents the entries in a row/column inside the bands. ```julia BandRange ``` -------------------------------- ### Band type signature Source: https://julialinearalgebra.github.io/BandedMatrices.jl Index selector for the diagonal at offset i of a banded matrix. Band(0) selects the main diagonal, positive offsets select superdiagonals, and negative offsets select subdiagonals. ```julia Band(i) ``` -------------------------------- ### collength function signature Source: https://julialinearalgebra.github.io/BandedMatrices.jl Return the number of filled bands in the i-th column. ```julia collength(A, i::Integer) ``` -------------------------------- ### BandedMatrices.rowstop(A, i::Integer) Source: https://julialinearalgebra.github.io/BandedMatrices.jl Returns the stopping column index of the filled bands in the i-th row, bounded by the actual matrix size. ```APIDOC ## BandedMatrices.rowstop(A, i::Integer) ### Description Returns the stopping column index of the filled bands in the i-th row, bounded by the actual matrix size. ### Function Signature `rowstop(A, i::Integer)` ### Parameters - **A** (BandedMatrix) - The banded matrix. - **i** (Integer) - The row index. ### Returns - **Integer** - The stopping column index of the filled bands in row i. ### Examples ```julia julia> A = BandedMatrix(0=>1:4, 1=>5:7) 4×4 BandedMatrix{Int64} with bandwidths (0, 1): 1 5 ⋅ ⋅ ⋅ 2 6 ⋅ ⋅ ⋅ 3 7 ⋅ ⋅ ⋅ 4 julia> BandedMatrices.rowstop(A, 2) 3 julia> BandedMatrices.rowstop(A, 4) 4 ``` ```