@@ -31,53 +31,40 @@ coefficients(cfs::AbstractVector,::SequenceSpace) = cfs # all vectors are conve
3131
3232# # Constant space defintions
3333
34- @traitdef ContainsConstant{X}
35- @traitimpl ContainsConstant{X} < - containsconstant (X )
34+ containsconstant (A :: Space ) = containsconstant ( typeof (A))
35+ containsconstant ( @nospecialize (_)) = Val ( false )
3636
37- containsconstant (@nospecialize (_)) = false
38-
39- promote_rule (TS1:: Type{<:ConstantSpace} , TS2:: Type{<:Space} ) =
40- constspace_promote_rule (TS1, TS2)
41-
42- @traitfn function constspace_promote_rule (:: Type{<:ConstantSpace} ,
43- B:: Type{X} ) where {X; ! ContainsConstant{X}}
44- Union{}
37+ # setup conversions for spaces that contain constants
38+ macro containsconstants (SP)
39+ esc (quote
40+ ApproxFunBase. containsconstant (:: Type{<:$SP} ) = Val (true )
41+ end )
4542end
46- @traitfn function constspace_promote_rule ( :: Type{<:ConstantSpace} ,
47- B :: Type{X } ) where {X; ContainsConstant{X} }
48- B
43+
44+ function promote_rule (TS1 :: Type{<:ConstantSpace} , :: Type{TS2 } ) where {TS2 <: Space }
45+ constspace_promote_rule (TS1, TS2, containsconstant (TS2))
4946end
47+ constspace_promote_rule (:: Type{<:ConstantSpace} , :: Type{<:Space} , :: Val{false} ) = Union{}
48+ constspace_promote_rule (:: Type{<:ConstantSpace} , :: Type{B} , :: Val{true} ) where {B<: Space } = B
5049
51- union_rule (A:: ConstantSpace , B:: Space ) = constspace_union_rule (A, B)
50+ union_rule (A:: ConstantSpace , B:: Space ) = constspace_union_rule (A, B, containsconstant (B) )
5251# TODO : this seems like it needs more thought
53- @traitfn constspace_union_rule (A:: ConstantSpace , B:: X ) where {X; ! ContainsConstant{X}} =
54- ConstantSpace (domain (B))⊕ B
55- @traitfn constspace_union_rule (A:: ConstantSpace , B:: X ) where {X; ContainsConstant{X}} = B
56-
57- promote_rule (TF:: Type{<:Fun} , TN:: Type{<:Number} ) = fun_promote_rule (TF, TN)
52+ function constspace_union_rule (@nospecialize (_:: ConstantSpace ), B:: Space , :: Val{false} )
53+ ConstantSpace (domain (B)) ⊕ B
54+ end
55+ constspace_union_rule (@nospecialize (_:: ConstantSpace ), B:: Space , :: Val{true} ) = B
5856
59- @traitfn fun_promote_rule (:: Type{<:Fun{S,CT}} ,
60- :: Type{T} ) where {T<: Number ,CT,S; ! ContainsConstant{S}} = Fun
61- @traitfn function fun_promote_rule (:: Type{<:Fun{S,CT}} ,
62- :: Type{T} ) where {T<: Number ,CT,S; ContainsConstant{S}}
57+ function promote_rule (TF:: Type{<:Fun{S}} , TN:: Type{<:Number} ) where {S}
58+ fun_promote_rule (TF, TN, containsconstant (S))
59+ end
60+ fun_promote_rule (:: Type{<:Fun} , :: Type{<:Number} , :: Val{false} ) = Fun
61+ function fun_promote_rule (:: Type{<:Fun{S,CT}} , :: Type{T} , :: Val{true} ) where {T<: Number ,CT,S}
6362 ApproxFunBase. VFun{S,promote_type (CT,T)}
6463end
65- @traitfn fun_promote_rule (:: Type{Fun{S}} ,
66- :: Type{T} ) where {T<: Number ,S; ! ContainsConstant{S}} = Fun
67- @traitfn function fun_promote_rule (:: Type{<:Fun{S}} ,
68- :: Type{T} ) where {T<: Number ,S; ContainsConstant{S}}
64+ function fun_promote_rule (:: Type{<:Fun{S}} , :: Type{T} , :: Val{true} ) where {T<: Number ,S}
6965 ApproxFunBase. VFun{S,T}
7066end
7167
72- # setup conversions for spaces that contain constants
73- macro containsconstants (SP)
74- esc (quote
75- ApproxFunBase. containsconstant (:: Type{<:$SP} ) = true
76- end )
77- end
78-
79-
80-
8168Fun (c:: Number ) = Fun (ConstantSpace (typeof (c)),[c])
8269Fun (c:: Number ,d:: ConstantSpace ) = Fun (d,[c])
8370
0 commit comments