Skip to content

Commit 0bc1b31

Browse files
authored
constant propagation in sumspace deriv (#404)
1 parent 5d3b373 commit 0bc1b31

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/Spaces/ProductSpaceOperators.jl

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ for TYP in (:PiecewiseSpace,:ArraySpace)
1414
end
1515
function interlace_choosedomainspace(ops,rs::$TYP)
1616
@assert length(ops) == length(rs)
17-
# this ensures correct dispatch for unino
17+
# this ensures correct dispatch for union
1818
sps = Array{Space}(
1919
filter(x->!isambiguous(x),map((op,s)->choosedomainspace(op,s),ops,rs)))
2020
if isempty(sps)
@@ -222,25 +222,33 @@ end
222222
#TODO: do in @calculus_operator?
223223

224224
for (Op,OpWrap) in ((:Derivative,:DerivativeWrapper),(:Integral,:IntegralWrapper))
225+
_Op = Symbol(:_, Op)
225226
@eval begin
226-
function $Op(S::PiecewiseSpace, k::Number)
227+
@inline function $_Op(S::PiecewiseSpace, k::Number)
227228
assert_integer(k)
228229
t = map(s->$Op(s,k),components(S))
229230
D = Diagonal(convert_vector_or_svector(t))
230231
O = InterlaceOperator(D, PiecewiseSpace)
231232
$OpWrap(O,k)
232233
end
233-
function $Op(S::ArraySpace, k::Number)
234+
@inline function $_Op(S::ArraySpace, k::Number)
234235
assert_integer(k)
235236
ops = map(s->$Op(s,k),S)
236237
RS = ArraySpace(reshape(map(rangespace, ops), size(S)))
237238
O = InterlaceOperator(Diagonal(ops), S, RS)
238239
$OpWrap(O,k)
239240
end
241+
@static if VERSION >= v"1.8"
242+
Base.@constprop :aggressive $Op(s::PiecewiseSpace, k::Number) = $_Op(s, k)
243+
Base.@constprop :aggressive $Op(s::ArraySpace, k::Number) = $_Op(s, k)
244+
else
245+
$Op(s::PiecewiseSpace, k::Number) = $_Op(s, k)
246+
$Op(s::ArraySpace, k::Number) = $_Op(s, k)
247+
end
240248
end
241249
end
242250

243-
function Derivative(S::SumSpace, k::Number)
251+
@inline function _Derivative(S::SumSpace, k::Number)
244252
assert_integer(k)
245253
# we want to map before we decompose, as the map may introduce
246254
# mixed bases.
@@ -254,6 +262,12 @@ function Derivative(S::SumSpace, k::Number)
254262
end
255263
end
256264

265+
@static if VERSION >= v"1.8"
266+
Base.@constprop :aggressive Derivative(s::SumSpace, k::Number) = _Derivative(s, k)
267+
else
268+
Derivative(s::SumSpace, k::Number) = _Derivative(s, k)
269+
end
270+
257271
choosedomainspace(M::CalculusOperator{UnsetSpace},sp::SumSpace)=mapreduce(s->choosedomainspace(M,s),union,sp.spaces)
258272

259273
## Multiplcation for Array*Vector

0 commit comments

Comments
 (0)