Skip to content

Constant propagation in Sumspace/Piecewisespace deriv #404

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions src/Spaces/ProductSpaceOperators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ for TYP in (:PiecewiseSpace,:ArraySpace)
end
function interlace_choosedomainspace(ops,rs::$TYP)
@assert length(ops) == length(rs)
# this ensures correct dispatch for unino
# this ensures correct dispatch for union
sps = Array{Space}(
filter(x->!isambiguous(x),map((op,s)->choosedomainspace(op,s),ops,rs)))
if isempty(sps)
Expand Down Expand Up @@ -222,25 +222,33 @@ end
#TODO: do in @calculus_operator?

for (Op,OpWrap) in ((:Derivative,:DerivativeWrapper),(:Integral,:IntegralWrapper))
_Op = Symbol(:_, Op)
@eval begin
function $Op(S::PiecewiseSpace, k::Number)
@inline function $_Op(S::PiecewiseSpace, k::Number)
assert_integer(k)
t = map(s->$Op(s,k),components(S))
D = Diagonal(convert_vector_or_svector(t))
O = InterlaceOperator(D, PiecewiseSpace)
$OpWrap(O,k)
end
function $Op(S::ArraySpace, k::Number)
@inline function $_Op(S::ArraySpace, k::Number)
assert_integer(k)
ops = map(s->$Op(s,k),S)
RS = ArraySpace(reshape(map(rangespace, ops), size(S)))
O = InterlaceOperator(Diagonal(ops), S, RS)
$OpWrap(O,k)
end
@static if VERSION >= v"1.8"
Base.@constprop :aggressive $Op(s::PiecewiseSpace, k::Number) = $_Op(s, k)
Base.@constprop :aggressive $Op(s::ArraySpace, k::Number) = $_Op(s, k)
else
$Op(s::PiecewiseSpace, k::Number) = $_Op(s, k)
$Op(s::ArraySpace, k::Number) = $_Op(s, k)
end
end
end

function Derivative(S::SumSpace, k::Number)
@inline function _Derivative(S::SumSpace, k::Number)
assert_integer(k)
# we want to map before we decompose, as the map may introduce
# mixed bases.
Expand All @@ -254,6 +262,12 @@ function Derivative(S::SumSpace, k::Number)
end
end

@static if VERSION >= v"1.8"
Base.@constprop :aggressive Derivative(s::SumSpace, k::Number) = _Derivative(s, k)
else
Derivative(s::SumSpace, k::Number) = _Derivative(s, k)
end

choosedomainspace(M::CalculusOperator{UnsetSpace},sp::SumSpace)=mapreduce(s->choosedomainspace(M,s),union,sp.spaces)

## Multiplcation for Array*Vector
Expand Down