Skip to content

Store domainspace in TimesOperator #440

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "ApproxFunBase"
uuid = "fbd15aa5-315a-5a7d-a8a4-24992e37be05"
version = "0.9.15"
version = "0.10.0"

[deps]
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"
Expand Down
26 changes: 16 additions & 10 deletions src/Operators/general/algebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ function splice_times(ops)
newops
end

struct TimesOperator{T,BW,SZ,O<:Operator{T},BBW,SBBW} <: Operator{T}
struct TimesOperator{T,BW,SZ,O<:Operator{T},BBW,SBBW,D} <: Operator{T}
ops::Vector{O}
bandwidths::BW
sz::SZ
Expand All @@ -249,19 +249,21 @@ struct TimesOperator{T,BW,SZ,O<:Operator{T},BBW,SBBW} <: Operator{T}
isbandedblockbanded::Bool
israggedbelow::Bool
isafunctional::Bool
domainspace::D

Base.@constprop :aggressive function TimesOperator{T,BW,SZ,O,BBW,SBBW}(ops::Vector{O}, bw::BW,
sz::SZ, bbw::BBW, sbbw::SBBW,
ibbb::Bool, irb::Bool, isaf::Bool;
anytimesop = any(x -> x isa TimesOperator, ops)) where {T,O<:Operator{T},BW,SZ,BBW,SBBW}
ibbb::Bool, irb::Bool, isaf::Bool, dsp::D;
anytimesop = any(x -> x isa TimesOperator, ops)) where {T,O<:Operator{T},BW,SZ,BBW,SBBW,D}

dsp == domainspace(ops[end]) || throw(ArgumentError("incompatible domainspace"))
# check compatible
check_times(ops)

# remove TimesOperators buried inside ops
newops = anytimesop ? splice_times(ops) : ops

new{T,BW,SZ,O,BBW,SBBW}(newops, bw, sz, bbw, sbbw, ibbb, irb, isaf)
new{T,BW,SZ,O,BBW,SBBW,D}(newops, bw, sz, bbw, sbbw, ibbb, irb, isaf, dsp)
end
end

Expand All @@ -280,11 +282,12 @@ function TimesOperator(ops::AbstractVector{O},
sbbw::Tuple{Any,Any}=bandwidthssum(subblockbandwidths, ops),
ibbb::Bool=all(isbandedblockbanded, ops),
irb::Bool=all(israggedbelow, ops),
isaf::Bool = sz[1] == 1 && isconstspace(rangespace(first(ops)));
isaf::Bool = sz[1] == 1 && isconstspace(rangespace(first(ops))),
dsp = domainspace(last(ops));
anytimesop = any(x -> x isa TimesOperator, ops),
) where {O<:Operator}
TimesOperator{eltype(O),typeof(bw),typeof(sz),O,typeof(bbw),typeof(sbbw)}(
convert_vector(ops), bw, sz, bbw, sbbw, ibbb, irb, isaf; anytimesop)
convert_vector(ops), bw, sz, bbw, sbbw, ibbb, irb, isaf, dsp; anytimesop)
end

_extractops(A::TimesOperator, ::typeof(*)) = A.ops
Expand All @@ -300,8 +303,9 @@ function TimesOperator(A::Operator, Bs::Operator...)
bwsum = bandwidthssum(bandwidths, ops)
bbwsum = bandwidthssum(blockbandwidths, ops)
subbbwsum = bandwidthssum(subblockbandwidths, ops)
dsp = domainspace(last(ops))
TimesOperator(convert_vector(v), bwsum, sz,
bbwsum, subbbwsum, ibbb, irb, isaf;
bbwsum, subbbwsum, ibbb, irb, isaf, dsp;
anytimesop)
end

Expand All @@ -317,7 +321,8 @@ function convert(::Type{Operator{T}}, P::TimesOperator) where {T}
_convertops(Operator{T}, ops),
bandwidths(P), size(P), blockbandwidths(P),
subblockbandwidths(P), isbandedblockbanded(P),
israggedbelow(P), P.isafunctional, anytimesop = false)::Operator{T}
israggedbelow(P), P.isafunctional, domainspace(P),
anytimesop = false)::Operator{T}
end
end

Expand All @@ -330,7 +335,7 @@ Base.@constprop :aggressive function promotetimes(opsin,
sz = _timessize(ops)
isaf = sz[1] == 1 && isconstspace(rangespace(first(ops)))
anytimesop = any(x -> x isa TimesOperator, ops)
TimesOperator(convert_vector(ops), bw, sz, bbw, sbbw, ibbb, irb, isaf; anytimesop)
TimesOperator(convert_vector(ops), bw, sz, bbw, sbbw, ibbb, irb, isaf, dsp; anytimesop)
end
maybenarroweltype(::AbstractVector{Operator{T}}) where {T} = Operator{T}
maybenarroweltype(opsin) = mapreduce(operatortype, promote_type, opsin)
Expand Down Expand Up @@ -384,7 +389,8 @@ end
end
end

domainspace(P::PlusOrTimesOp) = domainspace(last(P.ops))
domainspace(P::PlusOperator) = domainspace(last(P.ops))
domainspace(T::TimesOperator) = T.domainspace
rangespace(P::PlusOrTimesOp) = rangespace(first(P.ops))

domain(P::TimesOperator) = commondomain(P.ops)
Expand Down
5 changes: 3 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,10 @@ end
f = Fun(sp, coeff)
for sp2 in Any[(), (sp,)]
M = Multiplication(f, sp2...)
a = (M * M) * M
b = M * (M * M)
a = TimesOperator(M, M) * M
b = M * TimesOperator(M, M)
@test a == b
@test (@inferred domainspace(a)) == domainspace(M)
@test bandwidths(a) == bandwidths(b)
end
M = Multiplication(Fun(PointSpace(1:3)))
Expand Down