Skip to content

Commit e0de0d8

Browse files
authored
BBBArrowheadMatrices module (#63)
* BBBArrowheadMatrices module * tests pass * Update test_arrowhead.jl * banded interface * eigvals via banded matrices * Update test_arrowhead.jl * v0.4.1
1 parent fecc8ab commit e0de0d8

File tree

4 files changed

+71
-6
lines changed

4 files changed

+71
-6
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "PiecewiseOrthogonalPolynomials"
22
uuid = "4461d12d-4663-4550-8580-cb764c85e20f"
33
authors = ["Sheehan Olver <solver@mac.com>"]
4-
version = "0.4"
4+
version = "0.4.1"
55

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

src/PiecewiseOrthogonalPolynomials.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ import ContinuumArrays: @simplify, factorize, TransformFactorization, AbstractBa
1010
import LazyArrays: paddeddata, AbstractLazyLayout
1111
import LazyBandedMatrices: BlockBroadcastMatrix, BlockVec, BandedLazyLayouts, AbstractLazyBandedBlockBandedLayout, UpperOrLowerTriangular
1212
import Base: size, axes, getindex, +, -, *, /, ==, \, OneTo, oneto, replace_in_print_matrix, copy, diff, getproperty, adjoint, transpose, tail, _sum, inv, show, summary
13-
import LinearAlgebra: BlasInt
1413
import InfiniteArrays: OneToInf
1514
import FillArrays: AbstractFill
16-
import MatrixFactorizations: reversecholcopy
1715
import FillArrays: SquareEye
1816

19-
export PiecewisePolynomial, ContinuousPolynomial, DirichletPolynomial, Derivative, Block, weaklaplacian, grammatrix
17+
export PiecewisePolynomial, ContinuousPolynomial, DirichletPolynomial, Derivative, Block, weaklaplacian, grammatrix, BBBArrowheadMatrix
2018

2119
include("arrowhead.jl")
20+
using .BBBArrowheadMatrices
21+
2222
include("piecewisepolynomial.jl")
2323
include("continuouspolynomial.jl")
2424
include("dirichlet.jl")

src/arrowhead.jl

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
module BBBArrowheadMatrices
2+
using LinearAlgebra, BlockArrays, BlockBandedMatrices, BandedMatrices, MatrixFactorizations, LazyBandedMatrices, LazyArrays, ArrayLayouts, InfiniteArrays, FillArrays
3+
import ArrayLayouts: MemoryLayout, sublayout, sub_materialize, symmetriclayout, transposelayout, SymmetricLayout, HermitianLayout, TriangularLayout, layout_getindex, materialize!, MatLdivVec, AbstractStridedLayout, triangulardata, MatMulMatAdd, MatMulVecAdd, _fill_lmul!, layout_replace_in_print_matrix
4+
import BandedMatrices: isbanded, bandwidths
5+
import BlockArrays: BlockSlice, block, blockindex, blockvec
6+
import BlockBandedMatrices: subblockbandwidths, blockbandwidths, AbstractBandedBlockBandedLayout, AbstractBandedBlockBandedMatrix
7+
import Base: size, axes, getindex, +, -, *, /, ==, \, OneTo, oneto, replace_in_print_matrix, copy, diff, getproperty, adjoint, transpose, tail, _sum, inv, show, summary
8+
import LazyArrays: paddeddata, AbstractLazyLayout
9+
import LazyBandedMatrices: BlockBroadcastMatrix, BlockVec, BandedLazyLayouts, AbstractLazyBandedBlockBandedLayout, UpperOrLowerTriangular
10+
import LinearAlgebra: BlasInt, eigvals
11+
import MatrixFactorizations: reversecholcopy
12+
import FillArrays: AbstractFill
13+
import FillArrays: SquareEye
14+
import InfiniteArrays: OneToInf
15+
16+
17+
export BBBArrowheadMatrix
118

219
"""
320
BBBArrowheadMatrix
@@ -498,4 +515,22 @@ for Tri in (:LowerTriangular, :UnitLowerTriangular)
498515
getfield(F, d)
499516
end
500517
end
501-
end
518+
end
519+
520+
####
521+
# banded interface
522+
#####
523+
bbbbandwidth(k, A) = bandwidth(A, k)
524+
bbbbandwidth(k, A, C...) = +(size(A,k), size.(Base.front(C), k)...) + bandwidth(last(C),k)
525+
bandwidths(A::BBBArrowheadMatrix) = bbbbandwidth(1, A.A, A.C...), bbbbandwidth(2, A.A, A.B...)
526+
isbanded(A::BBBArrowheadMatrix) = true
527+
528+
529+
####
530+
# eigvals
531+
#####
532+
533+
eigvals(A::Symmetric{<:Real,<:BBBArrowheadMatrix}) = eigvals(Symmetric(BandedMatrix(parent(A))))
534+
eigvals(A::Symmetric{<:Real,<:BBBArrowheadMatrix}, B::Symmetric{<:Real,<:BBBArrowheadMatrix}) = eigvals(Symmetric(BandedMatrix(parent(A))), Symmetric(BandedMatrix(parent(B))))
535+
536+
end #module

test/test_arrowhead.jl

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using PiecewiseOrthogonalPolynomials, FillArrays, BandedMatrices, MatrixFactorizations, BlockBandedMatrices, Base64, ClassicalOrthogonalPolynomials, Test
1+
using PiecewiseOrthogonalPolynomials, FillArrays, BandedMatrices, MatrixFactorizations, BlockBandedMatrices, BandedMatrices, Base64, ClassicalOrthogonalPolynomials, LinearAlgebra, Test
22
using PiecewiseOrthogonalPolynomials: BBBArrowheadMatrix
33
using InfiniteArrays, BlockArrays
44
using BandedMatrices: _BandedMatrix
@@ -144,4 +144,34 @@ import Base: oneto, OneTo
144144
@test U reversecholesky(Matrix(Symmetric(A))).U
145145
@test U*U' Symmetric(A)
146146
end
147+
148+
@testset "banded" begin
149+
n = 5; p = 5;
150+
A = BBBArrowheadMatrix(BandedMatrix(0 => 1:n, 1 => 1:n-1, -1 => 1:n-1),
151+
ntuple(_ -> BandedMatrix((0 => randn(n-1), -1 => randn(n-1)), (n,n-1)), 2),
152+
ntuple(_ -> BandedMatrix((0 => randn(n), 1 => randn(n-1)), (n-1,n)), 3),
153+
fill(BandedMatrix((0 => randn(p) .+ 10, 2 => randn(p-2), -1=> randn(p-1)), (p, p)), n-1))
154+
155+
156+
@test blockbandwidths(A) == (3,2)
157+
@test subblockbandwidths(A) == (1,1)
158+
@test BandedMatrices.isbanded(A)
159+
@test bandwidths(A) == (13,9)
160+
@test BandedMatrix(A) == A
161+
end
162+
163+
@testset "eigvals" begin
164+
r = range(-1,1; length=4)
165+
C = ContinuousPolynomial{1}(r)
166+
KR = Block.(OneTo(5))
167+
Δ = weaklaplacian(C)[KR,KR]
168+
M = grammatrix(C)[KR,KR]
169+
ΔB = BandedMatrix(Δ)
170+
MB = BandedMatrix(M)
171+
@test bandwidths(Δ) == bandwidths(ΔB) == (1,1)
172+
@test bandwidths(M) == bandwidths(MB) == (7,7)
173+
@test eigvals(Symmetric(Δ)) == eigvals(Symmetric(ΔB))
174+
@test eigvals(Symmetric(M)) == eigvals(Symmetric(MB))
175+
@test eigvals(Symmetric(Δ), Symmetric(M)) == eigvals(Symmetric(ΔB), Symmetric(MB))
176+
end
147177
end

0 commit comments

Comments
 (0)