@@ -38,17 +38,28 @@ differentiate(p::MatPolynomial, x) = differentiate(Polynomial(p), x)
38
38
39
39
differentiate (p:: RationalPoly , x:: PolyVar ) = (differentiate (p. num, x) * p. den - p. num * differentiate (p. den, x)) / p. den^ 2
40
40
41
- function differentiate {C} (p:: PolyType{C} , xs:: Vector{PolyVar{C}} )
41
+ # even if I annotate with ::Array{_diff_promote_op(T, PolyVar{C}), N+1}, it cannot detect the type since it seems to be unable to determine the dimension N+1 :(
42
+ function differentiate {N, C, T<:PolyType{C}} (ps:: AbstractArray{T, N} , xs:: Union{AbstractVector{PolyVar{C}}, Tuple} )
43
+ qs = Array {_diff_promote_op(T, PolyVar{C}), N+1} (length (xs), size (ps)... )
44
+ for (i, x) in enumerate (xs)
45
+ for j in linearindices (ps)
46
+ J = ind2sub (ps, j)
47
+ qs[i, J... ] = differentiate (ps[J... ], x)
48
+ end
49
+ end
50
+ qs
51
+ end
52
+ function differentiate {C} (p:: PolyType{C} , xs:: Union{AbstractVector{PolyVar{C}}, Tuple} )
42
53
[differentiate (p, x) for x in xs]
43
54
end
44
55
45
56
# In Julia v0.5, Base.promote_op returns Any for PolyVar, Monomial and MatPolynomial
57
+ # Even on Julia v0.6 and Polynomial, Base.promote_op returns Any...
46
58
_diff_promote_op (S, T) = Base. promote_op (differentiate, S, T)
47
- _diff_promote_op {C} (:: Type{PolyVar{C}} , :: Type{PolyVar{C}} ) = Term{true , Int}
48
- _diff_promote_op {C} (:: Type{Monomial{C}} , :: Type{PolyVar{C}} ) = Term{true , Int}
49
- _diff_promote_op {C, T} (:: Type{MatPolynomial{C, T}} , :: Type{PolyVar{C}} ) = Polynomial{true , Base. promote_op (* , T, Int)}
59
+ _diff_promote_op {C} (:: Union{Type{PolyVar{C}}, Type{Monomial{C}}} , :: Type{PolyVar{C}} ) = Term{true , Int}
60
+ _diff_promote_op {C, T} (:: Union{Type{Polynomial{C, T}}, Type{MatPolynomial{C, T}}} , :: Type{PolyVar{C}} ) = Polynomial{true , Base. promote_op (* , T, Int)}
50
61
51
- function differentiate (p:: PolyType , x, deg:: Int )
62
+ function differentiate {T<:PolyType} (p:: Union{T, AbstractArray{T}} , x, deg:: Int )
52
63
if deg < 0
53
64
throw (DomainError ())
54
65
elseif deg == 0
0 commit comments