Skip to content

Commit 4f39dbf

Browse files
add progress meter
update for HierarchicalMatrices.A_mul_B!
1 parent d1df620 commit 4f39dbf

File tree

11 files changed

+74
-157
lines changed

11 files changed

+74
-157
lines changed

REQUIRE

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
julia 0.5
22
ToeplitzMatrices 0.2
3-
Compat 0.19
3+
LowRankApprox 0.0.2
4+
ProgressMeter 0.3.4
5+
Compat 0.18

src/FastTransforms.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
__precompile__()
22
module FastTransforms
33

4-
using Base, ToeplitzMatrices, HierarchicalMatrices, LowRankApprox, Compat
4+
using Base, ToeplitzMatrices, HierarchicalMatrices, LowRankApprox, ProgressMeter, Compat
55

6-
import Base: *, size, view, A_mul_B!, Ac_mul_B!, At_mul_B!
6+
import Base: *, size, view, A_mul_B!, At_mul_B!, Ac_mul_B!
77
import Base: getindex, setindex!, Factorization, length
88
import Base.LinAlg: BlasFloat, BlasInt
99
import HierarchicalMatrices: HierarchicalMatrix, unsafe_broadcasttimes!

src/SphericalHarmonics/Butterfly.jl

Lines changed: 10 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ end
2828

2929
size(B::Butterfly) = size(B, 1), size(B, 2)
3030

31-
function Butterfly{T}(A::AbstractMatrix{T}, L::Int64; opts...)
31+
function Butterfly{T}(A::AbstractMatrix{T}, L::Int64; isorthogonal::Bool = false, opts...)
3232
m, n = size(A)
3333
tL = 2^L
3434

@@ -51,88 +51,11 @@ function Butterfly{T}(A::AbstractMatrix{T}, L::Int64; opts...)
5151
nu = nd
5252
indices[1][1] = 1
5353
for j = 1:tL
54-
factors[1][j] = idfact(A[:,nl:nu], LRAOpts)
55-
permutations[1][j] = factors[1][j][:P]
56-
indices[1][j+1] = indices[1][j] + size(factors[1][j], 1)
57-
cs[1][j] = factors[1][j].sk+nl-1
58-
nl += nd
59-
nu += nd
60-
end
61-
62-
ii, jj = 2, (tL>>1)
63-
for l = 2:L+1
64-
factors[l] = Vector{IDPackedV{T}}(tL)
65-
permutations[l] = Vector{ColumnPermutation}(tL)
66-
indices[l] = Vector{Int64}(tL+1)
67-
cs[l] = Vector{Vector{Int64}}(tL)
68-
69-
ctr = 0
70-
md = m÷ii
71-
ml = 1
72-
mu = md
73-
indices[l][1] = 1
74-
for i = 1:ii
75-
shft = 2jj*div(ctr,2jj)
76-
for j = 1:jj
77-
cols = vcat(cs[l-1][2j-1+shft],cs[l-1][2j+shft])
78-
lc = length(cols)
79-
Av = A[ml:mu,cols]
80-
if maximum(abs, Av) < realmin(real(T))/eps(real(T))
81-
factors[l][j+ctr] = IDPackedV{T}(Int64[], collect(1:lc), Array{T}(0,lc))
82-
else
83-
LRAOpts.rtol = eps(real(T))*max(length(ml:mu),lc)
84-
factors[l][j+ctr] = idfact(Av, LRAOpts)
85-
end
86-
permutations[l][j+ctr] = factors[l][j+ctr][:P]
87-
indices[l][j+ctr+1] = indices[l][j+ctr] + size(factors[l][j+ctr], 1)
88-
cs[l][j+ctr] = cols[factors[l][j+ctr].sk]
89-
end
90-
ml += md
91-
mu += md
92-
ctr += jj
54+
if isorthogonal
55+
factors[1][j] = IDPackedV{T}(collect(1:nd),Int64[],Array{T}(nd,0))
56+
else
57+
factors[1][j] = idfact!(A[:,nl:nu], LRAOpts)
9358
end
94-
ii <<= 1
95-
jj >>= 1
96-
end
97-
98-
md = m÷tL
99-
ml = 1
100-
mu = md
101-
for i = 1:tL
102-
columns[i] = A[ml:mu,cs[L+1][i]]
103-
ml += md
104-
mu += md
105-
end
106-
107-
kk = sumkmax(indices)
108-
109-
Butterfly(columns, factors, permutations, indices, zeros(T, kk), zeros(T, kk), zeros(T, kk))
110-
end
111-
112-
function orthogonalButterfly{T}(A::AbstractMatrix{T}, L::Int64; opts...)
113-
m, n = size(A)
114-
tL = 2^L
115-
116-
LRAOpts = LRAOptions(T; opts...)
117-
LRAOpts.rtol = eps(real(T))*max(m, n)
118-
119-
columns = Vector{Matrix{T}}(tL)
120-
factors = Vector{Vector{IDPackedV{T}}}(L+1)
121-
permutations = Vector{Vector{ColumnPermutation}}(L+1)
122-
indices = Vector{Vector{Int64}}(L+1)
123-
cs = Vector{Vector{Vector{Int64}}}(L+1)
124-
125-
factors[1] = Vector{IDPackedV{T}}(tL)
126-
permutations[1] = Vector{ColumnPermutation}(tL)
127-
indices[1] = Vector{Int64}(tL+1)
128-
cs[1] = Vector{Vector{Int64}}(tL)
129-
130-
nd = n÷tL
131-
nl = 1
132-
nu = nd
133-
indices[1][1] = 1
134-
for j = 1:tL
135-
factors[1][j] = IDPackedV{T}(collect(1:nd),Int64[],Array{T}(nd,0))
13659
permutations[1][j] = factors[1][j][:P]
13760
indices[1][j+1] = indices[1][j] + size(factors[1][j], 1)
13861
cs[1][j] = factors[1][j].sk+nl-1
@@ -162,7 +85,7 @@ function orthogonalButterfly{T}(A::AbstractMatrix{T}, L::Int64; opts...)
16285
factors[l][j+ctr] = IDPackedV{T}(Int64[], collect(1:lc), Array{T}(0,lc))
16386
else
16487
LRAOpts.rtol = eps(real(T))*max(length(ml:mu),lc)
165-
factors[l][j+ctr] = idfact(Av, LRAOpts)
88+
factors[l][j+ctr] = idfact!(Av, LRAOpts)
16689
end
16790
permutations[l][j+ctr] = factors[l][j+ctr][:P]
16891
indices[l][j+ctr+1] = indices[l][j+ctr] + size(factors[l][j+ctr], 1)
@@ -243,7 +166,7 @@ function A_mul_B!{T}(y::AbstractVecOrMat{T}, A::IDPackedV{T}, P::ColumnPermutati
243166
k, n = size(A)
244167
At_mul_B!(P, x, jstart)
245168
copy!(y, istart, x, jstart, k)
246-
A_mul_B!(y, A.T, x, istart, jstart+k)
169+
HierarchicalMatrices.A_mul_B!(y, A.T, x, istart, jstart+k)
247170
A_mul_B!(P, x, jstart)
248171
y
249172
end
@@ -253,7 +176,7 @@ for f! in (:At_mul_B!, :Ac_mul_B!)
253176
function $f!{T}(y::AbstractVecOrMat{T}, A::IDPackedV{T}, P::ColumnPermutation, x::AbstractVecOrMat{T}, istart::Int, jstart::Int)
254177
k, n = size(A)
255178
copy!(y, istart, x, jstart, k)
256-
$f!(y, A.T, x, istart+k, jstart)
179+
HierarchicalMatrices.$f!(y, A.T, x, istart+k, jstart)
257180
A_mul_B!(P, y, istart)
258181
y
259182
end
@@ -314,7 +237,7 @@ function A_mul_B_col_J!{T}(u::VecOrMat{T}, B::Butterfly{T}, b::VecOrMat{T}, J::I
314237
for i = 1:tL
315238
ml = mu+1
316239
mu += size(columns[i], 1)
317-
A_mul_B!(u, columns[i], temp1, ml+COLSHIFT, inds[i])
240+
HierarchicalMatrices.A_mul_B!(u, columns[i], temp1, ml+COLSHIFT, inds[i])
318241
end
319242

320243
u
@@ -344,7 +267,7 @@ for f! in (:At_mul_B!,:Ac_mul_B!)
344267
for i = 1:tL
345268
ml = mu+1
346269
mu += size(columns[i], 1)
347-
$f!(temp1, columns[i], b, inds[i], ml+COLSHIFT)
270+
HierarchicalMatrices.$f!(temp1, columns[i], b, inds[i], ml+COLSHIFT)
348271
end
349272

350273
ii, jj = tL, 1

src/SphericalHarmonics/fastplan.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,16 @@ function FastSphericalHarmonicPlan{T}(A::Matrix{T}, L::Int; opts...)
2323
Ce = eye(T, M)
2424
Co = eye(T, M)
2525
BF = Vector{Butterfly{T}}(n-2)
26+
P = Progress(n-2, 0.1, "Pre-computing fast plan...", 50)
2627
for j = 1:2:n-2
2728
A_mul_B!(Ce, RP.layers[j])
28-
BF[j] = orthogonalButterfly(Ce, L; opts...)
29-
println("Layer: ",j)
29+
BF[j] = Butterfly(Ce, L; isorthogonal = true, opts...)
30+
next!(P)
3031
end
3132
for j = 2:2:n-2
3233
A_mul_B!(Co, RP.layers[j])
33-
BF[j] = orthogonalButterfly(Co, L; opts...)
34-
println("Layer: ",j)
34+
BF[j] = Butterfly(Co, L; isorthogonal = true, opts...)
35+
next!(P)
3536
end
3637
FastSphericalHarmonicPlan(RP, BF, p1, p2, p1inv, p2inv, B)
3738
end

src/SphericalHarmonics/thinplan.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,16 @@ function ThinSphericalHarmonicPlan{T}(A::Matrix{T}, L::Int; opts...)
2727
Ce = eye(T, M)
2828
Co = eye(T, M)
2929
BF = Vector{Butterfly{T}}(n-2)
30+
P = Progress(n-2, 0.1, "Pre-computing thin plan...", 50)
3031
for j = 1:2:n-2
3132
A_mul_B!(Ce, RP.layers[j])
32-
checklayer(j+1) && (BF[j] = orthogonalButterfly(Ce, L; opts...);println("Layer: ",j))
33+
checklayer(j+1) && (BF[j] = Butterfly(Ce, L; isorthogonal = true, opts...))
34+
next!(P)
3335
end
3436
for j = 2:2:n-2
3537
A_mul_B!(Co, RP.layers[j])
36-
checklayer(j) && (BF[j] = orthogonalButterfly(Co, L; opts...);println("Layer: ",j))
38+
checklayer(j) && (BF[j] = Butterfly(Co, L; isorthogonal = true, opts...))
39+
next!(P)
3740
end
3841
ThinSphericalHarmonicPlan(RP, BF, p1, p2, p1inv, p2inv, B)
3942
end

src/hierarchical.jl

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -170,23 +170,23 @@ leg2cheb(v::Vector) = plan_leg2cheb(v)*v
170170
cheb2leg(v::Vector) = plan_cheb2leg(v)*v
171171

172172
function A_mul_B!(y::Vector, P::LegendreToChebyshevPlan, x::AbstractVector)
173-
A_mul_B!(y, P.even, x, 1, 1, 2, 2)
174-
A_mul_B!(y, P.odd, x, 2, 2, 2, 2)
173+
HierarchicalMatrices.A_mul_B!(y, P.even, x, 1, 1, 2, 2)
174+
HierarchicalMatrices.A_mul_B!(y, P.odd, x, 2, 2, 2, 2)
175175
scale!(2/π, y)
176176
y[1] *= 0.5
177177
y
178178
end
179179

180180
function A_mul_B!(y::Vector, P::ChebyshevToLegendrePlan, x::AbstractVector)
181-
A_mul_B!(y, P.even, x, 1, 1, 2, 2)
182-
A_mul_B!(y, P.odd, x, 2, 2, 2, 2)
181+
HierarchicalMatrices.A_mul_B!(y, P.even, x, 1, 1, 2, 2)
182+
HierarchicalMatrices.A_mul_B!(y, P.odd, x, 2, 2, 2, 2)
183183
end
184184

185185
function A_mul_B!(Y::Matrix, P::LegendreToChebyshevPlan, X::Matrix)
186186
m, n = size(X)
187187
for j = 1:n
188-
A_mul_B!(Y, P.even, X, 1+m*(j-1), 1+m*(j-1), 2, 2)
189-
A_mul_B!(Y, P.odd, X, 2+m*(j-1), 2+m*(j-1), 2, 2)
188+
HierarchicalMatrices.A_mul_B!(Y, P.even, X, 1+m*(j-1), 1+m*(j-1), 2, 2)
189+
HierarchicalMatrices.A_mul_B!(Y, P.odd, X, 2+m*(j-1), 2+m*(j-1), 2, 2)
190190
end
191191
scale!(2/π, Y)
192192
for j = 1:n
@@ -198,8 +198,8 @@ end
198198
function A_mul_B!(Y::Matrix, P::ChebyshevToLegendrePlan, X::Matrix)
199199
m, n = size(X)
200200
for j = 1:n
201-
A_mul_B!(Y, P.even, X, 1+m*(j-1), 1+m*(j-1), 2, 2)
202-
A_mul_B!(Y, P.odd, X, 2+m*(j-1), 2+m*(j-1), 2, 2)
201+
HierarchicalMatrices.A_mul_B!(Y, P.even, X, 1+m*(j-1), 1+m*(j-1), 2, 2)
202+
HierarchicalMatrices.A_mul_B!(Y, P.odd, X, 2+m*(j-1), 2+m*(j-1), 2, 2)
203203
end
204204
Y
205205
end
@@ -288,25 +288,25 @@ cheb2normleg(v::Vector) = plan_cheb2normleg(v)*v
288288

289289
function A_mul_B!!(y::Vector, P::NormalizedLegendreToChebyshevPlan, x::AbstractVector)
290290
unsafe_broadcasttimes!(x, P.scl)
291-
A_mul_B!(y, P.even, x, 1, 1, 2, 2)
292-
A_mul_B!(y, P.odd, x, 2, 2, 2, 2)
291+
HierarchicalMatrices.A_mul_B!(y, P.even, x, 1, 1, 2, 2)
292+
HierarchicalMatrices.A_mul_B!(y, P.odd, x, 2, 2, 2, 2)
293293
scale!(2/π, y)
294294
y[1] *= 0.5
295295
y
296296
end
297297

298298
function A_mul_B!(y::Vector, P::ChebyshevToNormalizedLegendrePlan, x::AbstractVector)
299-
A_mul_B!(y, P.even, x, 1, 1, 2, 2)
300-
A_mul_B!(y, P.odd, x, 2, 2, 2, 2)
299+
HierarchicalMatrices.A_mul_B!(y, P.even, x, 1, 1, 2, 2)
300+
HierarchicalMatrices.A_mul_B!(y, P.odd, x, 2, 2, 2, 2)
301301
unsafe_broadcasttimes!(y, P.scl)
302302
end
303303

304304
function A_mul_B!!(Y::Matrix, P::NormalizedLegendreToChebyshevPlan, X::Matrix)
305305
m, n = size(X)
306306
scale!(P.scl, X)
307307
for j = 1:n
308-
A_mul_B!(Y, P.even, X, 1+m*(j-1), 1+m*(j-1), 2, 2)
309-
A_mul_B!(Y, P.odd, X, 2+m*(j-1), 2+m*(j-1), 2, 2)
308+
HierarchicalMatrices.A_mul_B!(Y, P.even, X, 1+m*(j-1), 1+m*(j-1), 2, 2)
309+
HierarchicalMatrices.A_mul_B!(Y, P.odd, X, 2+m*(j-1), 2+m*(j-1), 2, 2)
310310
end
311311
scale!(2/π, Y)
312312
@inbounds @simd for j = 1:n
@@ -318,8 +318,8 @@ end
318318
function A_mul_B!(Y::Matrix, P::ChebyshevToNormalizedLegendrePlan, X::Matrix)
319319
m, n = size(X)
320320
for j = 1:n
321-
A_mul_B!(Y, P.even, X, 1+m*(j-1), 1+m*(j-1), 2, 2)
322-
A_mul_B!(Y, P.odd, X, 2+m*(j-1), 2+m*(j-1), 2, 2)
321+
HierarchicalMatrices.A_mul_B!(Y, P.even, X, 1+m*(j-1), 1+m*(j-1), 2, 2)
322+
HierarchicalMatrices.A_mul_B!(Y, P.odd, X, 2+m*(j-1), 2+m*(j-1), 2, 2)
323323
end
324324
scale!(P.scl, Y)
325325
end
@@ -328,8 +328,8 @@ function A_mul_B_col_J!!(Y::Matrix, P::NormalizedLegendreToChebyshevPlan, X::Mat
328328
m, n = size(X)
329329
COLSHIFT = m*(J-1)
330330
scale_col_J!(P.scl, X, J)
331-
A_mul_B!(Y, P.even, X, 1+COLSHIFT, 1+COLSHIFT, 2, 2)
332-
A_mul_B!(Y, P.odd, X, 2+COLSHIFT, 2+COLSHIFT, 2, 2)
331+
HierarchicalMatrices.A_mul_B!(Y, P.even, X, 1+COLSHIFT, 1+COLSHIFT, 2, 2)
332+
HierarchicalMatrices.A_mul_B!(Y, P.odd, X, 2+COLSHIFT, 2+COLSHIFT, 2, 2)
333333
scale_col_J!(2/π, Y, J)
334334
@inbounds Y[1+COLSHIFT] *= 0.5
335335
Y
@@ -338,8 +338,8 @@ end
338338
function A_mul_B_col_J!(Y::Matrix, P::ChebyshevToNormalizedLegendrePlan, X::Matrix, J::Int)
339339
m, n = size(X)
340340
COLSHIFT = m*(J-1)
341-
A_mul_B!(Y, P.even, X, 1+COLSHIFT, 1+COLSHIFT, 2, 2)
342-
A_mul_B!(Y, P.odd, X, 2+COLSHIFT, 2+COLSHIFT, 2, 2)
341+
HierarchicalMatrices.A_mul_B!(Y, P.even, X, 1+COLSHIFT, 1+COLSHIFT, 2, 2)
342+
HierarchicalMatrices.A_mul_B!(Y, P.odd, X, 2+COLSHIFT, 2+COLSHIFT, 2, 2)
343343
scale_col_J!(P.scl, Y, J)
344344
end
345345

@@ -411,31 +411,31 @@ cheb22normleg1(v::Vector) = plan_cheb22normleg1(v)*v
411411

412412
function A_mul_B!!(y::Vector, P::NormalizedLegendre1ToChebyshev2Plan, x::AbstractVector)
413413
unsafe_broadcasttimes!(x, P.scl)
414-
A_mul_B!(y, P.even, x, 1, 1, 2, 2)
415-
A_mul_B!(y, P.odd, x, 2, 2, 2, 2)
414+
HierarchicalMatrices.A_mul_B!(y, P.even, x, 1, 1, 2, 2)
415+
HierarchicalMatrices.A_mul_B!(y, P.odd, x, 2, 2, 2, 2)
416416
end
417417

418418
function A_mul_B!(y::Vector, P::Chebyshev2ToNormalizedLegendre1Plan, x::AbstractVector)
419-
A_mul_B!(y, P.even, x, 1, 1, 2, 2)
420-
A_mul_B!(y, P.odd, x, 2, 2, 2, 2)
419+
HierarchicalMatrices.A_mul_B!(y, P.even, x, 1, 1, 2, 2)
420+
HierarchicalMatrices.A_mul_B!(y, P.odd, x, 2, 2, 2, 2)
421421
unsafe_broadcasttimes!(y, P.scl)
422422
end
423423

424424
function A_mul_B!!(Y::Matrix, P::NormalizedLegendre1ToChebyshev2Plan, X::Matrix)
425425
m, n = size(X)
426426
scale!(P.scl, X)
427427
for j = 1:n
428-
A_mul_B!(Y, P.even, X, 1+m*(j-1), 1+m*(j-1), 2, 2)
429-
A_mul_B!(Y, P.odd, X, 2+m*(j-1), 2+m*(j-1), 2, 2)
428+
HierarchicalMatrices.A_mul_B!(Y, P.even, X, 1+m*(j-1), 1+m*(j-1), 2, 2)
429+
HierarchicalMatrices.A_mul_B!(Y, P.odd, X, 2+m*(j-1), 2+m*(j-1), 2, 2)
430430
end
431431
Y
432432
end
433433

434434
function A_mul_B!(Y::Matrix, P::Chebyshev2ToNormalizedLegendre1Plan, X::Matrix)
435435
m, n = size(X)
436436
for j = 1:n
437-
A_mul_B!(Y, P.even, X, 1+m*(j-1), 1+m*(j-1), 2, 2)
438-
A_mul_B!(Y, P.odd, X, 2+m*(j-1), 2+m*(j-1), 2, 2)
437+
HierarchicalMatrices.A_mul_B!(Y, P.even, X, 1+m*(j-1), 1+m*(j-1), 2, 2)
438+
HierarchicalMatrices.A_mul_B!(Y, P.odd, X, 2+m*(j-1), 2+m*(j-1), 2, 2)
439439
end
440440
scale!(P.scl, Y)
441441
end
@@ -444,15 +444,15 @@ function A_mul_B_col_J!!(Y::Matrix, P::NormalizedLegendre1ToChebyshev2Plan, X::M
444444
m, n = size(X)
445445
COLSHIFT = m*(J-1)
446446
scale_col_J!(P.scl, X, J)
447-
A_mul_B!(Y, P.even, X, 1+COLSHIFT, 1+COLSHIFT, 2, 2)
448-
A_mul_B!(Y, P.odd, X, 2+COLSHIFT, 2+COLSHIFT, 2, 2)
447+
HierarchicalMatrices.A_mul_B!(Y, P.even, X, 1+COLSHIFT, 1+COLSHIFT, 2, 2)
448+
HierarchicalMatrices.A_mul_B!(Y, P.odd, X, 2+COLSHIFT, 2+COLSHIFT, 2, 2)
449449
Y
450450
end
451451

452452
function A_mul_B_col_J!(Y::Matrix, P::Chebyshev2ToNormalizedLegendre1Plan, X::Matrix, J::Int)
453453
m, n = size(X)
454454
COLSHIFT = m*(J-1)
455-
A_mul_B!(Y, P.even, X, 1+COLSHIFT, 1+COLSHIFT, 2, 2)
456-
A_mul_B!(Y, P.odd, X, 2+COLSHIFT, 2+COLSHIFT, 2, 2)
455+
HierarchicalMatrices.A_mul_B!(Y, P.even, X, 1+COLSHIFT, 1+COLSHIFT, 2, 2)
456+
HierarchicalMatrices.A_mul_B!(Y, P.odd, X, 2+COLSHIFT, 2+COLSHIFT, 2, 2)
457457
scale_col_J!(P.scl, Y, J)
458458
end

0 commit comments

Comments
 (0)