Skip to content

Commit d1df620

Browse files
la vie est belle sans SubArray
1 parent aa1dcf1 commit d1df620

File tree

3 files changed

+31
-15
lines changed

3 files changed

+31
-15
lines changed

src/SphericalHarmonics/Butterfly.jl

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@ end
2828

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

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

35-
LRAOpts = LRAOptions(T; rtol = eps(real(T))*max(m, n))
35+
LRAOpts = LRAOptions(T; opts...)
36+
LRAOpts.rtol = eps(real(T))*max(m, n)
3637

3738
columns = Vector{Matrix{T}}(tL)
3839
factors = Vector{Vector{IDPackedV{T}}}(L+1)
@@ -50,7 +51,7 @@ function Butterfly{T}(A::AbstractMatrix{T}, L::Int64)
5051
nu = nd
5152
indices[1][1] = 1
5253
for j = 1:tL
53-
factors[1][j] = idfact(view(A,:,nl:nu), LRAOpts)
54+
factors[1][j] = idfact(A[:,nl:nu], LRAOpts)
5455
permutations[1][j] = factors[1][j][:P]
5556
indices[1][j+1] = indices[1][j] + size(factors[1][j], 1)
5657
cs[1][j] = factors[1][j].sk+nl-1
@@ -74,7 +75,14 @@ function Butterfly{T}(A::AbstractMatrix{T}, L::Int64)
7475
shft = 2jj*div(ctr,2jj)
7576
for j = 1:jj
7677
cols = vcat(cs[l-1][2j-1+shft],cs[l-1][2j+shft])
77-
factors[l][j+ctr] = idfact(view(A, ml:mu, cols), LRAOpts)
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
7886
permutations[l][j+ctr] = factors[l][j+ctr][:P]
7987
indices[l][j+ctr+1] = indices[l][j+ctr] + size(factors[l][j+ctr], 1)
8088
cs[l][j+ctr] = cols[factors[l][j+ctr].sk]
@@ -101,11 +109,12 @@ function Butterfly{T}(A::AbstractMatrix{T}, L::Int64)
101109
Butterfly(columns, factors, permutations, indices, zeros(T, kk), zeros(T, kk), zeros(T, kk))
102110
end
103111

104-
function orthogonalButterfly{T}(A::AbstractMatrix{T}, L::Int64)
112+
function orthogonalButterfly{T}(A::AbstractMatrix{T}, L::Int64; opts...)
105113
m, n = size(A)
106114
tL = 2^L
107115

108-
LRAOpts = LRAOptions(T; rtol = eps(real(T))*max(m, n))
116+
LRAOpts = LRAOptions(T; opts...)
117+
LRAOpts.rtol = eps(real(T))*max(m, n)
109118

110119
columns = Vector{Matrix{T}}(tL)
111120
factors = Vector{Vector{IDPackedV{T}}}(L+1)
@@ -147,7 +156,14 @@ function orthogonalButterfly{T}(A::AbstractMatrix{T}, L::Int64)
147156
shft = 2jj*div(ctr,2jj)
148157
for j = 1:jj
149158
cols = vcat(cs[l-1][2j-1+shft],cs[l-1][2j+shft])
150-
factors[l][j+ctr] = idfact(view(A, ml:mu, cols), LRAOpts)
159+
lc = length(cols)
160+
Av = A[ml:mu,cols]
161+
if maximum(abs, Av) < realmin(real(T))/eps(real(T))
162+
factors[l][j+ctr] = IDPackedV{T}(Int64[], collect(1:lc), Array{T}(0,lc))
163+
else
164+
LRAOpts.rtol = eps(real(T))*max(length(ml:mu),lc)
165+
factors[l][j+ctr] = idfact(Av, LRAOpts)
166+
end
151167
permutations[l][j+ctr] = factors[l][j+ctr][:P]
152168
indices[l][j+ctr+1] = indices[l][j+ctr] + size(factors[l][j+ctr], 1)
153169
cs[l][j+ctr] = cols[factors[l][j+ctr].sk]

src/SphericalHarmonics/fastplan.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ immutable FastSphericalHarmonicPlan{T}
88
B::Matrix{T}
99
end
1010

11-
function FastSphericalHarmonicPlan{T}(A::Matrix{T}, L::Int)
11+
function FastSphericalHarmonicPlan{T}(A::Matrix{T}, L::Int; opts...)
1212
M, N = size(A)
1313
@assert ispow2(M)
1414
@assert N == 2M-1
@@ -25,18 +25,18 @@ function FastSphericalHarmonicPlan{T}(A::Matrix{T}, L::Int)
2525
BF = Vector{Butterfly{T}}(n-2)
2626
for j = 1:2:n-2
2727
A_mul_B!(Ce, RP.layers[j])
28-
BF[j] = orthogonalButterfly(Ce, L)
28+
BF[j] = orthogonalButterfly(Ce, L; opts...)
2929
println("Layer: ",j)
3030
end
3131
for j = 2:2:n-2
3232
A_mul_B!(Co, RP.layers[j])
33-
BF[j] = orthogonalButterfly(Co, L)
33+
BF[j] = orthogonalButterfly(Co, L; opts...)
3434
println("Layer: ",j)
3535
end
3636
FastSphericalHarmonicPlan(RP, BF, p1, p2, p1inv, p2inv, B)
3737
end
3838

39-
FastSphericalHarmonicPlan(A::Matrix) = FastSphericalHarmonicPlan(A, round(Int, log2(size(A, 1)+1)-6))
39+
FastSphericalHarmonicPlan(A::Matrix; opts...) = FastSphericalHarmonicPlan(A, round(Int, log2(size(A, 1)+1)-6); opts...)
4040

4141
function A_mul_B!(Y::Matrix, FP::FastSphericalHarmonicPlan, X::Matrix)
4242
RP, BF, p1, p2, B = FP.RP, FP.BF, FP.p1, FP.p2, FP.B

src/SphericalHarmonics/thinplan.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ immutable ThinSphericalHarmonicPlan{T}
1212
B::Matrix{T}
1313
end
1414

15-
function ThinSphericalHarmonicPlan{T}(A::Matrix{T}, L::Int)
15+
function ThinSphericalHarmonicPlan{T}(A::Matrix{T}, L::Int; opts...)
1616
M, N = size(A)
1717
@assert ispow2(M)
1818
@assert N == 2M-1
@@ -29,16 +29,16 @@ function ThinSphericalHarmonicPlan{T}(A::Matrix{T}, L::Int)
2929
BF = Vector{Butterfly{T}}(n-2)
3030
for j = 1:2:n-2
3131
A_mul_B!(Ce, RP.layers[j])
32-
checklayer(j+1) && (BF[j] = orthogonalButterfly(Ce, L);println("Layer: ",j))
32+
checklayer(j+1) && (BF[j] = orthogonalButterfly(Ce, L; opts...);println("Layer: ",j))
3333
end
3434
for j = 2:2:n-2
3535
A_mul_B!(Co, RP.layers[j])
36-
checklayer(j) && (BF[j] = orthogonalButterfly(Co, L);println("Layer: ",j))
36+
checklayer(j) && (BF[j] = orthogonalButterfly(Co, L; opts...);println("Layer: ",j))
3737
end
3838
ThinSphericalHarmonicPlan(RP, BF, p1, p2, p1inv, p2inv, B)
3939
end
4040

41-
ThinSphericalHarmonicPlan(A::Matrix) = ThinSphericalHarmonicPlan(A, round(Int, log2(size(A, 1)+1)-6))
41+
ThinSphericalHarmonicPlan(A::Matrix; opts...) = ThinSphericalHarmonicPlan(A, round(Int, log2(size(A, 1)+1)-6); opts...)
4242

4343
function A_mul_B!(Y::Matrix, TP::ThinSphericalHarmonicPlan, X::Matrix)
4444
RP, BF, p1, p2, B = TP.RP, TP.BF, TP.p1, TP.p2, TP.B

0 commit comments

Comments
 (0)