Skip to content

Commit 0360d8f

Browse files
committed
separate out interlace bandwidth
pass sumspace deriv bandwidth to interlaceop version bump to v0.8.5 bandwidth for piecewise derivative fix rangespace for PiecewiseSpace multiplication
1 parent 6d044d1 commit 0360d8f

File tree

3 files changed

+50
-24
lines changed

3 files changed

+50
-24
lines changed

src/Operators/general/InterlaceOperator.jl

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -81,22 +81,28 @@ end
8181
const VectorInterlaceOperator = InterlaceOperator{T,1,DS,RS} where {T,DS,RS<:Space{D,R}} where {D,R<:AbstractVector}
8282
const MatrixInterlaceOperator = InterlaceOperator{T,2,DS,RS} where {T,DS,RS<:Space{D,R}} where {D,R<:AbstractVector}
8383

84+
@static if VERSION >= v"1.8"
85+
Base.@constprop :aggressive interlace_bandwidths(args...) = _interlace_bandwidths(args...)
86+
else
87+
interlace_bandwidths(args...) = _interlace_bandwidths(args...)
88+
end
8489

85-
function InterlaceOperator(ops::AbstractMatrix{<:Operator},ds::Space,rs::Space)
90+
@inline function _interlace_bandwidths(ops::AbstractMatrix{<:Operator},
91+
ds, rs, allbanded = all(isbanded,ops))
8692
# calculate bandwidths TODO: generalize
8793
p=size(ops,1)
8894
dsi = interlacer(ds)
8995
rsi = interlacer(rs)
9096

91-
if size(ops,2) == p && all(isbanded,ops) &&# only support blocksize (1,) for now
97+
if size(ops,2) == p && allbanded &&# only support blocksize (1,) for now
9298
all(i->isa(i,AbstractFill) && getindex_value(i) == 1, dsi.blocks) &&
9399
all(i->isa(i,AbstractFill) && getindex_value(i) == 1, rsi.blocks)
94100

95101
l,u = 0,0
96-
for k=1:p,j=1:p
102+
for k=axes(ops,1), j=axes(ops,2)
97103
l=max(l,p*bandwidth(ops[k,j],1)+k-j)
98104
end
99-
for k=1:p,j=1:p
105+
for k=axes(ops,1), j=axes(ops,2)
100106
u=max(u,p*bandwidth(ops[k,j],2)+j-k)
101107
end
102108
elseif p == 1 && size(ops,2) == 2 && size(ops[1],2) == 1
@@ -105,20 +111,14 @@ function InterlaceOperator(ops::AbstractMatrix{<:Operator},ds::Space,rs::Space)
105111
else
106112
l,u = (1-dimension(rs),dimension(ds)-1) # not banded
107113
end
108-
109-
MT = Matrix{Operator{promote_eltypeof(ops)}}
110-
opsm = strictconvert(MT, ops)
111-
InterlaceOperator(opsm,ds,rs,
112-
cache(dsi),
113-
cache(rsi),
114-
(l,u))
114+
l,u
115115
end
116116

117-
118-
function InterlaceOperator(ops::VectorOrTupleOfOp, ds::Space, rs::Space)
117+
@inline function _interlace_bandwidths(ops::VectorOrTupleOfOp,
118+
ds, rs, allbanded = all(isbanded,ops))
119119
# calculate bandwidths
120120
p=size(ops,1)
121-
if all(isbanded,ops)
121+
if allbanded
122122
l,u = 0,0
123123
#TODO: this code assumes an interlace strategy that might not be right
124124
for k=1:p
@@ -130,13 +130,33 @@ function InterlaceOperator(ops::VectorOrTupleOfOp, ds::Space, rs::Space)
130130
else
131131
l,u = (1-dimension(rs),dimension(ds)-1) # not banded
132132
end
133+
l,u
134+
end
135+
136+
function InterlaceOperator(ops::AbstractMatrix{<:Operator}, ds::Space, rs::Space,
137+
bw = interlace_bandwidths(ops, ds, rs))
138+
139+
dsi = interlacer(ds)
140+
rsi = interlacer(rs)
141+
142+
MT = Matrix{Operator{promote_eltypeof(ops)}}
143+
opsm = strictconvert(MT, ops)
144+
InterlaceOperator(opsm,ds,rs,
145+
cache(dsi),
146+
cache(rsi),
147+
bw)
148+
end
149+
150+
151+
function InterlaceOperator(ops::VectorOrTupleOfOp, ds::Space, rs::Space,
152+
bw = interlace_bandwidths(ops, ds, rs))
133153

134154
VT = Vector{Operator{promote_eltypeof(ops)}}
135155
opsv = strictconvert(VT, convert_vector(ops))
136156
InterlaceOperator(opsv,ds,rs,
137157
cache(BlockInterlacer(tuple(blocklengths(ds)))),
138158
cache(interlacer(rs)),
139-
(l,u))
159+
bw)
140160
end
141161

142162
interlace_domainspace(ops::AbstractMatrix, ::Type{NoSpace}) = domainspace(ops)

src/Spaces/ProductSpaceOperators.jl

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -220,15 +220,24 @@ end
220220
## Derivative
221221

222222
#TODO: do in @calculus_operator?
223+
_spacename(::SumSpace) = SumSpace
224+
_spacename(::PiecewiseSpace) = PiecewiseSpace
225+
226+
function InterlaceOperator_Diagonal(t, S)
227+
allbanded = all(isbanded, t)
228+
ds, rs = S, _spacename(S)(map(rangespace, t))
229+
D = Diagonal(convert_vector_or_svector(t))
230+
bw = interlace_bandwidths(D, ds, rs, allbanded)
231+
InterlaceOperator(D, ds, rs, bw)
232+
end
223233

224234
for (Op,OpWrap) in ((:Derivative,:DerivativeWrapper),(:Integral,:IntegralWrapper))
225235
_Op = Symbol(:_, Op)
226236
@eval begin
227237
@inline function $_Op(S::PiecewiseSpace, k::Number)
228238
assert_integer(k)
229239
t = map(s->$Op(s,k),components(S))
230-
D = Diagonal(convert_vector_or_svector(t))
231-
O = InterlaceOperator(D, PiecewiseSpace)
240+
O = InterlaceOperator_Diagonal(t, S)
232241
$OpWrap(O,k)
233242
end
234243
@inline function $_Op(S::ArraySpace, k::Number)
@@ -254,8 +263,7 @@ end
254263
# mixed bases.
255264
if typeof(canonicaldomain(S))==typeof(domain(S))
256265
t = map(s->Derivative(s,k),components(S))
257-
D = Diagonal(convert_vector_or_svector(t))
258-
O = InterlaceOperator(D, SumSpace)
266+
O = InterlaceOperator_Diagonal(t, S)
259267
DerivativeWrapper(O,k)
260268
else
261269
DefaultDerivative(S,k)
@@ -291,8 +299,7 @@ function Multiplication(f::Fun{<:PiecewiseSpace}, sp::PiecewiseSpace)
291299
p=perm(domain(f).domains,domain(sp).domains) # sort f
292300
vf=components(f)[p]
293301
t = map(Multiplication,vf,sp.spaces)
294-
D = Diagonal(convert_vector_or_svector(t))
295-
O = InterlaceOperator(D, PiecewiseSpace)
302+
O = InterlaceOperator_Diagonal(t, sp)
296303
MultiplicationWrapper(f, O)
297304
end
298305

@@ -301,8 +308,7 @@ Multiplication(f::Fun{SumSpace{SV1,D,R1}},sp::SumSpace{SV2,D,R2}) where {SV1,SV2
301308

302309
function Multiplication(f::Fun, sp::SumSpace)
303310
t = map(s->Multiplication(f,s),components(sp))
304-
D = Diagonal(convert_vector_or_svector(t))
305-
O = InterlaceOperator(D, SumSpace)
311+
O = InterlaceOperator_Diagonal(t, sp)
306312
MultiplicationWrapper(f, O)
307313
end
308314

src/show.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ function show(io::IO,ss::PiecewiseSpace)
158158
end
159159
show(io,s[1])
160160
for sp in s[2:end]
161-
print(io,"")
161+
print(io,"")
162162
show(io,sp)
163163
end
164164
if length(s) == 1

0 commit comments

Comments
 (0)