@@ -31,18 +31,48 @@ 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)
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{}
45
+ end
46
+ @traitfn function constspace_promote_rule (:: Type{<:ConstantSpace} ,
47
+ B:: Type{X} ) where {X; ContainsConstant{X}}
48
+ B
49
+ end
50
+
51
+ union_rule (A:: ConstantSpace , B:: Space ) = constspace_union_rule (A, B)
52
+ # 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)
58
+
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}}
63
+ ApproxFunBase. VFun{S,promote_type (CT,T)}
64
+ 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}}
69
+ ApproxFunBase. VFun{S,T}
70
+ end
71
+
34
72
# setup conversions for spaces that contain constants
35
73
macro containsconstants (SP)
36
74
esc (quote
37
- ApproxFunBase. union_rule (A:: (ApproxFunBase.ConstantSpace) ,B:: $SP ) = B
38
- Base. promote_rule (A:: Type{<:(ApproxFunBase.ConstantSpace)} ,B:: Type{<:($SP)} ) = B
39
-
40
- Base. promote_rule (:: Type{ApproxFunBase.Fun{S,V,VV}} ,:: Type{T} ) where {T<: Number ,S<: $SP ,V,VV} =
41
- ApproxFunBase. VFun{S,promote_type (V,T)}
42
- Base. promote_rule (:: Type{ApproxFunBase.Fun{S}} ,:: Type{T} ) where {T<: Number ,S<: $SP } = ApproxFunBase. VFun{S,T}
43
- Base. promote_rule (:: Type{ApproxFunBase.Fun{S,V,VV}} ,
44
- :: Type{Fun{ApproxFunBase.ConstantSpace{ApproxFunBase.AnyDomain},T,VT}} ) where {T,S<: $SP ,V,VV,VT} =
45
- ApproxFunBase. VFun{S,promote_type (V,T)}
75
+ ApproxFunBase. containsconstant (:: Type{<:$SP} ) = true
46
76
end )
47
77
end
48
78
@@ -78,7 +108,6 @@ Number(f::Fun) = strictconvert(Number, f)
78
108
Base. promote_rule (:: Type{Fun{CS}} ,:: Type{T} ) where {CS<: ConstantSpace ,T<: Number } = Fun{CS,T}
79
109
Base. promote_rule (:: Type{Fun{CS,V}} ,:: Type{T} ) where {CS<: ConstantSpace ,T<: Number ,V} =
80
110
Fun{CS,promote_type (T,V)}
81
- Base. promote_rule (:: Type{IF} ,:: Type{T} ) where {T<: Number ,IF<: Fun } = Fun
82
111
83
112
84
113
# we know multiplication by constants preserves types
@@ -107,10 +136,6 @@ maxspace_rule(A::ZeroSpace,B::Space) = B
107
136
Conversion (A:: ZeroSpace ,B:: ZeroSpace ) = ConversionWrapper (ZeroOperator (A,B))
108
137
Conversion (A:: ZeroSpace ,B:: Space ) = ConversionWrapper (ZeroOperator (A,B))
109
138
110
- # TODO : this seems like it needs more thought
111
- union_rule (A:: ConstantSpace ,B:: Space ) = ConstantSpace (domain (B))⊕ B
112
-
113
-
114
139
# # Special Multiplication and Conversion for constantspace
115
140
116
141
# TODO : this is a special work around but really we want it to be blocks
0 commit comments