@@ -31,53 +31,40 @@ coefficients(cfs::AbstractVector,::SequenceSpace) = cfs # all vectors are conve
31
31
32
32
# # Constant space defintions
33
33
34
- @traitdef ContainsConstant{X}
35
- @traitimpl ContainsConstant{X} < - containsconstant (X )
34
+ containsconstant (A :: Space ) = containsconstant ( typeof (A))
35
+ containsconstant ( @nospecialize (_)) = Val ( false )
36
36
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 )
45
42
end
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))
49
46
end
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
50
49
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) )
52
51
# 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
58
56
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}
63
62
ApproxFunBase. VFun{S,promote_type (CT,T)}
64
63
end
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}
69
65
ApproxFunBase. VFun{S,T}
70
66
end
71
67
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
-
81
68
Fun (c:: Number ) = Fun (ConstantSpace (typeof (c)),[c])
82
69
Fun (c:: Number ,d:: ConstantSpace ) = Fun (d,[c])
83
70
0 commit comments