Skip to content

Commit 37b0ad9

Browse files
committed
do not convert Q to dense Matrix
1 parent 092a319 commit 37b0ad9

File tree

1 file changed

+7
-19
lines changed

1 file changed

+7
-19
lines changed

src/b-splines/prefiltering.jl

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ end
5252
function prefilter!(
5353
::Type{TWeights}, ret::TCoefs, it::BSpline
5454
) where {TWeights,TCoefs<:AbstractArray}
55-
local buf, shape, retrs
5655
sz = size(ret)
5756
first = true
5857
for dim in 1:ndims(ret)
@@ -72,18 +71,7 @@ function diffop(::Type{TWeights}, n::Int, k::Int) where {TWeights}
7271
end
7372
diffop(n::Int, k::Int) = diffop(Float64, n, k)
7473
### TODO: add compiled constructor for most common operators of order k=1,2
75-
#
76-
#function diffop(::Type{TWeights}, n::Int, k::Int) where {TWeights}
77-
# D1 = spdiagm(0 => -ones(TWeights,n-1), 1 => ones(TWeights,n-1))[1:end-1, :]
78-
# D = D1
79-
# for i in 1:k-1
80-
# D = diff(D; dims=1)
81-
## D = D1[1+i:end, 1+i:end] * D
82-
## lmul!(D1[1+i:end, 1+i:end], D)
83-
# end
84-
#
85-
# D' * D
86-
#end
74+
8775

8876
function prefilter!(
8977
::Type{TWeights}, ret::TCoefs, it::BSpline, λ::Real, k::Int
@@ -109,11 +97,12 @@ function prefilter!(
10997
end
11098

11199
M, b = prefiltering_system(TWeights, eltype(TCoefs), sz[1], degree(it))
112-
### TEST REGULARIZATION
113-
n = sz[1]
114-
Q = Matrix(diffop(TWeights, n, k))
115-
K = cholesky(Matrix(M)' * Matrix(M) + λ * Q)
116-
B = Matrix(M)' * popwrapper(ret)
100+
## Solve with regularization
101+
# Convert to dense Matrix because `*(Woodbury{Adjoint}, Woodbury)` is not defined
102+
Mt = Matrix(M)'
103+
Q = diffop(TWeights, sz[1], k)
104+
K = cholesky(Mt * Matrix(M) + λ * Q)
105+
B = Mt * popwrapper(ret)
117106
ldiv!(popwrapper(ret), K, B)
118107

119108
ret
@@ -122,7 +111,6 @@ end
122111
function prefilter!(
123112
::Type{TWeights}, ret::TCoefs, its::Tuple{Vararg{Union{BSpline,NoInterp}}}
124113
) where {TWeights,TCoefs<:AbstractArray}
125-
local buf, shape, retrs
126114
sz = size(ret)
127115
for dim in 1:ndims(ret)
128116
it = iextract(its, dim)

0 commit comments

Comments
 (0)