Skip to content

Commit ac247f2

Browse files
committed
pinv for Jacobi
1 parent 9cbbd61 commit ac247f2

File tree

3 files changed

+50
-69
lines changed

3 files changed

+50
-69
lines changed

src/ContinuumArrays.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Base: @_inline_meta, axes, getindex, convert, prod, *, /, \, +, -,
44
IndexStyle, IndexLinear, ==, OneTo
55
import Base.Broadcast: materialize
66
import LazyArrays: Mul2
7+
import LinearAlgebra: pinv
78
import BandedMatrices: AbstractBandedLayout, _BandedMatrix
89

910
include("QuasiArrays/QuasiArrays.jl")

src/bases/jacobi.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ end
1111

1212
abstract type AbstractJacobi{T} <: AbstractQuasiMatrix{T} end
1313

14+
pinv(J::AbstractJacobi) = PInv(J)
15+
1416
struct Legendre{T} <: AbstractJacobi{T} end
1517
Legendre() = Legendre{Float64}()
1618

test/runtests.jl

Lines changed: 47 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -153,100 +153,78 @@ end
153153
@test u[0.1] 0.00012678835289369413
154154
end
155155

156+
@testset "Jacobi" begin
157+
S = Jacobi(true,true)
158+
W = Diagonal(JacobiWeight(true,true))
159+
D = Derivative(axes(W,1))
160+
P = Legendre()
156161

157-
S = Jacobi(true,true)
158-
W = Diagonal(JacobiWeight(true,true))
159-
D = Derivative(axes(W,1))
160-
161-
A = @inferred(PInv(Jacobi(2,2))*D*S)
162-
@test A isa BandedMatrix
163-
@test size(A) == (∞,∞)
164-
@test A[1:10,1:10] == diagm(1 => 1:0.5:5)
165-
166-
M = @inferred(D*S)
167-
@test M isa Mul
168-
@test M.factors[1] == Jacobi(2,2)
169-
@test M.factors[2][1:10,1:10] == A[1:10,1:10]
170-
171-
172-
L = Diagonal(JacobiWeight(true,false))
173-
A = @inferred(PInv(Jacobi(false,true))*L*S)
174-
@test A isa BandedMatrix
175-
@test size(A) == (∞,∞)
176-
177-
L = Diagonal(JacobiWeight(false,true))
178-
A = @inferred(PInv(Jacobi(true,false))*L*S)
179-
@test A isa BandedMatrix
180-
@test size(A) == (∞,∞)
162+
A = @inferred(PInv(Jacobi(2,2))*D*S)
163+
@test A isa BandedMatrix
164+
@test size(A) == (∞,∞)
165+
@test A[1:10,1:10] == diagm(1 => 1:0.5:5)
181166

167+
M = @inferred(D*S)
168+
@test M isa Mul
169+
@test M.factors[1] == Jacobi(2,2)
170+
@test M.factors[2][1:10,1:10] == A[1:10,1:10]
182171

183-
L = Diagonal(JacobiWeight(true,true))
172+
L = Diagonal(JacobiWeight(true,false))
173+
A = @inferred(PInv(Jacobi(false,true))*L*S)
174+
@test A isa BandedMatrix
175+
@test size(A) == (∞,∞)
184176

177+
L = Diagonal(JacobiWeight(false,true))
178+
A = @inferred(PInv(Jacobi(true,false))*L*S)
179+
@test A isa BandedMatrix
180+
@test size(A) == (∞,∞)
185181

186-
L = Legendre()
182+
A,B = (P'P),(PInv(P)*W*S)
187183

188-
A, B = (L'L),(PInv(L)*W*S)
184+
M = Mul(A,B)
185+
@test M[1,1] == 4/3
189186

190-
M = A*B
191-
@which M.mul[1,1]
187+
M = MulMatrix{Float64}(A,B)
188+
= M[1:10,1:10]
189+
@testisa BandedMatrix
190+
@test bandwidths(M̃) == (2,0)
192191

193-
@which materialize(Mul(A,B))
192+
@test A*B isa MulArray
194193

195-
M = LazyArrays.MulArray(Mul(A,B))
196-
axes(M)
197194

198-
@time A[1:100000,1:100000]
199-
@profiler A.data[:,1:10_000]
200-
201-
V = view(A.data,:,1:100)
202-
203-
N = 10_000; M = randn(3,N)
204-
205-
A.data.arrays[2]
206-
207-
@time begin
208-
M[1,:] .= view(A.data.arrays[1]', 1:N)
209-
M[2,:] .= view(A.data.arrays[2], 1, 1:N)
210-
M[3,:] .= view(A.data.arrays[3]', 1:N)
195+
A,B,C = (PInv(P)*W*S)',(P'P),(PInv(P)*W*S)
196+
M = MulArray(A,B,C)
197+
@test typeof(A*B*C) == typeof(M)
198+
@test M[1,1] 1+1/15
211199
end
212-
M
213-
214-
@which copyto!(M, V)
215-
216-
@time
217-
218-
typeof(V)
219-
220-
using Profile
221-
Profile.clear()
222-
@time randn(3,10_000)
223-
224-
W*S
225-
226-
227200

201+
S = Jacobi(true,true)
202+
W = Diagonal(JacobiWeight(true,true))
203+
D = Derivative(axes(W,1))
204+
P = Legendre()
228205

229-
M = Mul(S',W',W,S)
230-
materialize(M)
231-
materialize(Mul(S',W',W))
206+
N = 10
207+
L = D*W*S[:,1:N]
208+
Δ = L'L # weak second derivative
232209

233-
@which materialize(M)
210+
M = Mul.factors[1:3])
211+
LazyArrays.fullmaterialize(M)
212+
P'*W*S
234213

235214
W*W
236215

237216
S'W'W*S
238217

239218
N = 10
240-
L = D*W*S[:,1:N]
219+
B = S[:,1:N]
220+
L = D*W*
241221
# temporary work around to force 3-term materialize
242222
L = *(L.factors[1:3]...) * L.factors[4]
243223

224+
M = (D*W*S)'*(D*W*S)
225+
M.factors[1].mul.factors
244226

245-
*(L.factors[1:3]...)
246-
247-
@test L.factors isa Tuple{<:Legendre,<:BandedMatrix,<:BandedMatrix}
248227

249-
Δ = L'L # weak second derivative
250228
@test size(Δ) == (10,10)
251229

252230

0 commit comments

Comments
 (0)