@@ -57,8 +57,35 @@ macro register(name)
57
57
end
58
58
59
59
60
+ macro registerN (name, params... )
61
+ poly = esc (name)
62
+ αs = tuple (esc .(params)... )
63
+ quote
64
+ Base. convert (:: Type{P} , q:: Q ) where {$ (αs... ),T, P<: $poly{$(αs...),T} , Q <: $poly{$(αs...),T} } = q
65
+ Base. convert (:: Type{$poly{$(αs...)}} , q:: Q ) where {$ (αs... ),T, Q <: $poly{$(αs...),T} } = q
66
+ Base. promote (p:: P , q:: Q ) where {$ (αs... ),T, P <: $poly{$(αs...),T} , Q <: $poly{$(αs...),T} } = p,q
67
+ Base. promote_rule (:: Type{<:$poly{$(αs...),T}} , :: Type{<:$poly{$(αs...),S}} ) where {$ (αs... ),T,S} =
68
+ $ poly{$ (αs... ),promote_type (T, S)}
69
+ Base. promote_rule (:: Type{<:$poly{$(αs...),T}} , :: Type{S} ) where {$ (αs... ),T,S<: Number } =
70
+ $ poly{$ (αs... ),promote_type (T,S)}
71
+
72
+ function $poly {$(αs...),T} (x:: AbstractVector{S} , var:: SymbolLike = :x ) where {$ (αs... ),T,S}
73
+ $ poly {$(αs...),T} (T .(x), Symbol (var))
74
+ end
75
+ $ poly {$(αs...)} (coeffs:: AbstractVector{T} , var:: SymbolLike = :x ) where {$ (αs... ),T} =
76
+ $ poly {$(αs...),T} (coeffs, Symbol (var))
77
+ $ poly {$(αs...),T} (n:: Number , var:: SymbolLike = :x ) where {$ (αs... ),T} = n* one ($ poly{$ (αs... ),T}, Symbol (var))
78
+ $ poly {$(αs...)} (n:: Number , var:: SymbolLike = :x ) where {$ (αs... )} = n* one ($ poly{$ (αs... )}, Symbol (var))
79
+ $ poly {$(αs...),T} (var:: SymbolLike = :x ) where {$ (αs... ), T} = variable ($ poly{$ (αs... ),T}, Symbol (var))
80
+ $ poly {$(αs...)} (var:: SymbolLike = :x ) where {$ (αs... )} = variable ($ poly{$ (αs... )}, Symbol (var))
81
+ end
82
+ end
83
+
84
+
85
+ # deprecated. If desired, replace with @registerN type parameters... macro
60
86
# Macros to register POLY{α, T} and POLY{α, β, T}
61
87
macro register1 (name)
88
+ @warn " @register1 is deprecated use @registerN"
62
89
poly = esc (name)
63
90
quote
64
91
Base. convert (:: Type{P} , p:: P ) where {P<: $poly } = p
82
109
83
110
# Macro to register POLY{α, β, T}
84
111
macro register2 (name)
112
+ @warn " @register2 is deprecated use @registerN"
85
113
poly = esc (name)
86
114
quote
87
115
Base. convert (:: Type{P} , p:: P ) where {P<: $poly } = p
0 commit comments