Skip to content

Commit dfe7e3a

Browse files
authored
Improve inference in Fun * Operator (#112)
* improve bandwidth inference * Add tests * return type assertion in isafunctional
1 parent c869c7f commit dfe7e3a

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ApproxFunBase"
22
uuid = "fbd15aa5-315a-5a7d-a8a4-24992e37be05"
3-
version = "0.5.10"
3+
version = "0.5.11"
44

55
[deps]
66
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"

src/Operators/Operator.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ domain(A::Operator) = domain(domainspace(A))
3636

3737
isconstspace(_) = false
3838
## Functionals
39-
isafunctional(A::Operator) = size(A,1)==1 && isconstspace(rangespace(A))
39+
isafunctional(A::Operator)::Bool = size(A,1)==1 && isconstspace(rangespace(A))
4040

4141

4242
isonesvec(A) = A isa AbstractFill && getindex_value(A) == 1

src/Operators/general/algebra.jl

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,13 @@ struct TimesOperator{T,BI} <: Operator{T}
240240
end
241241
end
242242

243-
bandwidthssum(P, k) = bandwidthssum(P)[k]
243+
bandwidthssum(P, k::Integer) = bandwidthssum(P)[k]
244244
bandwidthssum(P) = mapreduce(bandwidths, (t1, t2) -> t1 .+ t2, P, init = (0,0))
245+
_bandwidthssum(A::Operator, B::Operator) = __bandwidthssum(bandwidths(A), bandwidths(B))
246+
__bandwidthssum(A::NTuple{2,InfiniteCardinal{0}}, B::NTuple{2,InfiniteCardinal{0}}) = A
247+
__bandwidthssum(A::NTuple{2,InfiniteCardinal{0}}, B) = A
248+
__bandwidthssum(A, B::NTuple{2,InfiniteCardinal{0}}) = B
249+
__bandwidthssum(A, B) = reduce((t1, t2) -> t1 .+ t2, (A, B), init = (0,0))
245250

246251
TimesOperator(ops::Vector{Operator{T}},bi::Tuple{N1,N2}) where {T,N1,N2} =
247252
TimesOperator{T,typeof(bi)}(ops,bi)
@@ -251,13 +256,13 @@ TimesOperator(ops::Vector{OT}) where {OT<:Operator} =
251256
TimesOperator(convert(Vector{Operator{eltype(OT)}},ops),bandwidthssum(ops))
252257

253258
TimesOperator(A::TimesOperator,B::TimesOperator) =
254-
TimesOperator(Operator{promote_type(eltype(A),eltype(B))}[A.ops; B.ops])
259+
TimesOperator(Operator{promote_type(eltype(A),eltype(B))}[A.ops; B.ops], _bandwidthssum(A, B))
255260
TimesOperator(A::TimesOperator,B::Operator) =
256-
TimesOperator(Operator{promote_type(eltype(A),eltype(B))}[A.ops; B])
261+
TimesOperator(Operator{promote_type(eltype(A),eltype(B))}[A.ops; B], _bandwidthssum(A, B))
257262
TimesOperator(A::Operator,B::TimesOperator) =
258-
TimesOperator(Operator{promote_type(eltype(A),eltype(B))}[A; B.ops])
263+
TimesOperator(Operator{promote_type(eltype(A),eltype(B))}[A; B.ops], _bandwidthssum(A, B))
259264
TimesOperator(A::Operator,B::Operator) =
260-
TimesOperator(Operator{promote_type(eltype(A),eltype(B))}[A,B])
265+
TimesOperator(Operator{promote_type(eltype(A),eltype(B))}[A,B], _bandwidthssum(A, B))
261266

262267

263268
==(A::TimesOperator,B::TimesOperator)=A.ops==B.ops

test/SpacesTest.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ import ApproxFunBase: PointSpace, HeavisideSpace, PiecewiseSegment, dimension, V
2727
@test (@inferred oftype(f, fany)) isa typeof(f)
2828
end
2929

30+
A = @inferred f * Multiplication(f)
31+
@test A * f == f^3
32+
33+
@testset "inafunctional inference" begin
34+
@test @inferred !ApproxFunBase.isafunctional(Multiplication(f))
35+
end
36+
3037
@testset "real/complex coefficients" begin
3138
c = [1:4;]
3239
for c2 in Any[c, c*im]

0 commit comments

Comments
 (0)