Skip to content

Commit 688994c

Browse files
cleanup blockbanded constructors
1 parent c90bfd3 commit 688994c

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

src/BivariateGramMatrix.jl

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,20 @@ function bivariatemoments(μ1::AbstractVector{T}, μ2::AbstractVector{T}) where
1717
return μ
1818
end
1919

20+
function bivariatemoments(μ1::PaddedVector{T}, μ2::PaddedVector{T}) where T
21+
@assert length(μ1) == length(μ2)
22+
N = length(μ1)
23+
b = length(μ1.args[2])+length(μ2.args[2])-1
24+
v = Vector{T}(undef, b*(b+1)÷2)
25+
for n in 0:b-1
26+
for k in 0:n
27+
v[n*(n+1)÷2+k+1] = μ1[n-k+1]*μ2[k+1]
28+
end
29+
end
30+
μ = BlockedVector(PaddedVector(v, N*(N+1)÷2), 1:N)
31+
return μ
32+
end
33+
2034
# These should live in BlockBandedMatrices.jl after PR #223
2135

2236
@inline function inbands_viewblock(A::BandedBlockBandedMatrix, KJ::Block{2})
@@ -130,7 +144,8 @@ end
130144

131145
function BivariateGramMatrix::BlockedVector{T, <: PaddedVector{T}}, X::XT, Y::YT, p0::T) where {T, XT <: AbstractMatrix{T}, YT <: AbstractMatrix{T}}
132146
N = blocklength(μ)
133-
b = blocklength.args[2])-1
147+
bb = length.blocks.args[2])
148+
b = ceil(Int, (-1+sqrt(1+8bb))/2) - 1
134149
n = (N+1)÷2
135150
@assert N == blocksize(X, 1) == blocksize(X, 2) == blocksize(Y, 1) == blocksize(Y, 2)
136151
@assert blockbandwidths(X) == blockbandwidths(Y) == (1, 1)

test/bivariategrammatrixtests.jl

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using BlockArrays, FastTransforms, LazyArrays, LinearAlgebra, Test
1+
using BlockArrays, BlockBandedMatrices, FastTransforms, LazyArrays, LinearAlgebra, Test
22

33
import FastTransforms: chebyshevmoments1, chebyshevabsmoments1, bivariatemoments
44

@@ -18,11 +18,6 @@ import FastTransforms: chebyshevmoments1, chebyshevabsmoments1, bivariatemoments
1818
WC = BivariateChebyshevGramMatrix(μ)
1919
@test W WC
2020

21-
R = cholesky(W).U
22-
RC = cholesky(WC).U
23-
24-
@test R RC
25-
2621
Gx = FastTransforms.compute_skew_generators(Val(1), W)
2722
GxC = FastTransforms.compute_skew_generators(Val(1), WC)
2823
@test Gx GxC
@@ -34,4 +29,20 @@ import FastTransforms: chebyshevmoments1, chebyshevabsmoments1, bivariatemoments
3429
J = [zeros(n, n) Matrix{Float64}(I, n, n); Matrix{Float64}(-I, n, n) zeros(n, n)]
3530
@test W.X'W-W*W.X Gx*J*Gx'
3631
@test W.Y'W-W*W.Y Gy*J*Gy'
32+
33+
R = cholesky(W).U
34+
RC = cholesky(WC).U
35+
36+
@test R RC
37+
38+
μ1 = PaddedVector(1 ./ [1,2,3], 2n-1)
39+
μ2 = PaddedVector(1 ./ [1,2,3,4,5,6], 2n-1)
40+
μ = bivariatemoments(μ1, μ2)
41+
μ̂ = bivariatemoments(Vector(μ1), Vector(μ2))
42+
@test μ μ̂
43+
44+
W = BivariateGramMatrix(μ, X, Y)
45+
WC = BivariateChebyshevGramMatrix(μ)
46+
@test blockbandwidths(W) == blockbandwidths(WC) == subblockbandwidths(W) == subblockbandwidths(WC) == (7, 7)
47+
@test W WC
3748
end

0 commit comments

Comments
 (0)