Skip to content

Commit 2c095fb

Browse files
committed
start Jacobi
1 parent d63f02c commit 2c095fb

File tree

7 files changed

+94
-17
lines changed

7 files changed

+94
-17
lines changed

REQUIRE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
julia 0.7
22
IntervalSets 0.3.1
33
DomainSets 0.0.1
4+
FillArrays 0.3
45
LazyArrays 0.4
56
BandedMatrices 0.7.2
67
InfiniteArrays 0.0.2

src/ContinuumArrays.jl

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
module ContinuumArrays
22
using IntervalSets, LinearAlgebra, LazyArrays, BandedMatrices, InfiniteArrays, DomainSets
33
import Base: @_inline_meta, axes, getindex, convert, prod, *, /, \, +, -,
4-
IndexStyle, IndexLinear, ==
4+
IndexStyle, IndexLinear, ==, OneTo
55
import Base.Broadcast: materialize
66
import LazyArrays: Mul2
7-
import BandedMatrices: AbstractBandedLayout
7+
import BandedMatrices: AbstractBandedLayout, _BandedMatrix
88

99
include("QuasiArrays/QuasiArrays.jl")
1010
using .QuasiArrays
11-
import .QuasiArrays: cardinality, checkindex, QuasiAdjoint, QuasiTranspose, slice, QSlice, SubQuasiArray
11+
import .QuasiArrays: cardinality, checkindex, QuasiAdjoint, QuasiTranspose, slice, QSlice, SubQuasiArray,
12+
QuasiDiagonal
1213

13-
export Spline, LinearSpline, HeavisideSpline, DiracDelta, Derivative
14+
export Spline, LinearSpline, HeavisideSpline, DiracDelta, Derivative, JacobiWeight, Jacobi, Legendre
1415

1516
####
1617
# Interval indexing support
@@ -35,6 +36,17 @@ function checkindex(::Type{Bool}, inds::AbstractInterval, I::AbstractArray)
3536
b
3637
end
3738

39+
40+
# we represent as a Mul with a banded matrix
41+
function materialize(V::SubQuasiArray{<:Any,2,<:Any,<:Tuple{<:QSlice,<:AbstractUnitRange}})
42+
A = parent(V)
43+
_,jr = parentindices(V)
44+
first(jr) 1 || throw(BoundsError())
45+
P = BandedMatrix((1-first(jr) => Ones{Int}(length(jr)),), (size(A,2), length(jr)))
46+
A*P
47+
end
48+
49+
3850
include("operators.jl")
3951
include("bases/bases.jl")
4052

src/QuasiArrays/matmul.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ end
3232
QuasiMatMulMat{styleA, styleB, T, V} = QuasiArrayMulArray{styleA, styleB, 2, 2, T, V}
3333
QuasiMatMulQuasiMat{styleA, styleB, T, V} = QuasiArrayMulQuasiArray{styleA, styleB, 2, 2, T, V}
3434

35-
35+
*(A::AbstractQuasiArray, B::AbstractQuasiArray, C::AbstractQuasiArray) = materialize(Mul(A,B,C))
3636
*(A::AbstractQuasiArray, B::AbstractQuasiArray) = materialize(Mul(A,B))
3737
*(A::AbstractQuasiArray, B::AbstractArray) = materialize(Mul(A,B))
3838
*(A::AbstractArray, B::AbstractQuasiArray) = materialize(Mul(A,B))

src/QuasiArrays/quasidiagonal.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ struct QuasiDiagonal{T,V<:AbstractQuasiVector{T}} <: AbstractQuasiMatrix{T}
66
diag::V
77

88
function QuasiDiagonal{T,V}(diag) where {T,V<:AbstractQuasiVector{T}}
9-
@assert !has_offset_axes(diag)
109
new{T,V}(diag)
1110
end
1211
end

src/bases/jacobi.jl

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,35 @@ function getindex(w::JacobiWeight, x::Real)
99
(1-x)^w.a * (1+x)^w.b
1010
end
1111

12+
abstract type AbstractJacobi{T} <: AbstractQuasiMatrix{T} end
1213

13-
struct Jacobi{T} <: AbstractQuasiMatrix{T}
14+
struct Legendre{T} <: AbstractJacobi{T} end
15+
Legendre() = Legendre{Float64}()
16+
17+
struct Jacobi{T} <: AbstractJacobi{T}
1418
b::T
1519
a::T
1620
end
1721

18-
axes(::Jacobi) = (ChebyshevInterval(), OneTo(∞))
22+
axes(::AbstractJacobi) = (ChebyshevInterval(), OneTo(∞))
1923
==(P::Jacobi, Q::Jacobi) = P.a == Q.a && P.b == Q.b
24+
25+
26+
materialize(M::Mul2{<:Any,<:Any,<:QuasiAdjoint{<:Any,<:Legendre},<:Legendre}) =
27+
Diagonal(2 ./ (2(0:∞) .+ 1))
28+
29+
30+
function materialize(M::Mul2{<:Any,<:Any,<:Derivative{<:Any,<:ChebyshevInterval},<:Jacobi})
31+
_, S = M.factors
32+
D = _BandedMatrix(((1:.+ 1 .+ S.a .+ S.b)/2)', ∞, -1,1)
33+
Mul(Jacobi(S.a+1,S.b+1), D)
34+
end
35+
36+
function materialize(M::Mul{<:Tuple,<:Tuple{<:Derivative{<:Any,<:ChebyshevInterval},
37+
QuasiDiagonal{Bool,JacobiWeight{Bool}},Jacobi{Bool}}})
38+
_, W, S = M.factors
39+
w = parent(W)
40+
(w.a && S.a && w.b && S.b) || throw(ArgumentError())
41+
D = _BandedMatrix((-2*(1:∞))', ∞, 1,-1)
42+
Mul(Legendre(), D)
43+
end

src/bases/splines.jl

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,6 @@ function copyto!(dest::SymTridiagonal, AB::Mul2{<:Any,<:Any,<:QuasiAdjoint{<:Any
5858
end
5959

6060
## Sub-bases
61-
# we represent as a Mul with a banded matrix
62-
function materialize(V::SubQuasiArray{<:Any,2,<:Spline,<:Tuple{<:QSlice,<:AbstractUnitRange}})
63-
A = parent(V)
64-
_,jr = parentindices(V)
65-
first(jr) 1 || throw(BoundsError())
66-
P = BandedMatrix((1-first(jr) => Ones{Int}(length(jr)),), (size(A,2), length(jr)))
67-
A*P
68-
end
6961

7062

7163
## Mass matrix

test/runtests.jl

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using ContinuumArrays, LazyArrays, IntervalSets, FillArrays, LinearAlgebra, BandedMatrices, Test
1+
using ContinuumArrays, LazyArrays, IntervalSets, FillArrays, LinearAlgebra, BandedMatrices, Test,
2+
InfiniteArrays
23
import ContinuumArrays: ℵ₁, materialize
34
import ContinuumArrays.QuasiArrays: SubQuasiArray
45

@@ -151,3 +152,51 @@ end
151152

152153
@test u[0.1] 0.00012678835289369413
153154
end
155+
156+
157+
S = Jacobi(true,true)
158+
W = Diagonal(JacobiWeight(true,true))
159+
D = Derivative(axes(W,1))
160+
D*S
161+
162+
D*S[:,1:10]
163+
164+
materialize(D*W*S)
165+
166+
J = Jacobi(false,false)
167+
J'J
168+
169+
170+
S'W'W*S
171+
172+
N = 10
173+
L = D*W*S[:,1:N]
174+
# temporary work around to force 3-term materialize
175+
L = *(L.factors[1:3]...) * L.factors[4]
176+
177+
Δ = L'L # weak second derivative
178+
179+
f = Legendre() * Vcat(1:10, Zeros(∞))
180+
181+
182+
L'f
183+
184+
axes(L')
185+
186+
Legendre()'f
187+
188+
A = Diagonal(1:∞)
189+
x = Vcat(1:10, Zeros(∞))
190+
191+
@which A*x
192+
193+
B = BandedMatrices._BandedMatrix((1:∞)', ∞, -1,1)
194+
195+
B*x
196+
197+
N = 100000; @time B[1:N,1:N]
198+
199+
200+
201+
import LazyArrays: MemoryLayout
202+
MemoryLayout.(x.arrays)

0 commit comments

Comments
 (0)