Skip to content

Commit

Permalink
ArgumentErrorfor promotion among non-compatible Taylor1 and TaylorN (#…
Browse files Browse the repository at this point in the history
…220)

Fixes #219
  • Loading branch information
lbenet authored Jul 12, 2019
1 parent e82c031 commit ad6f423
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/arithmetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ for (f, fc) in ((:+, :(add!)), (:-, :(subst!)))
end
end

+(a::Taylor1{T}, b::TaylorN{S}) where {T<:NumberNotSeries,S<:NumberNotSeries} =
+(promote(a,b)...)
-(a::Taylor1{T}, b::TaylorN{S}) where {T<:NumberNotSeries,S<:NumberNotSeries} =
-(promote(a,b)...)


## Multiplication ##
Expand Down
3 changes: 3 additions & 0 deletions src/conversion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,6 @@ promote_rule(::Type{S}, ::Type{T}) where {S<:NumberNotSeries, T<:AbstractSeries}

promote_rule(::Type{S}, ::Type{T}) where
{S<:AbstractIrrational, T<:AbstractSeries} = promote_rule(T,S)

promote_rule(::Type{Taylor1{T}}, ::Type{TaylorN{S}}) where {T<:NumberNotSeries, S<:NumberNotSeries} =
throw(ArgumentError("There is no reasonable promotion among `Taylor1{$T}` and `TaylorN{$S}` types"))
5 changes: 5 additions & 0 deletions test/mixtures.jl
Original file line number Diff line number Diff line change
Expand Up @@ -273,4 +273,9 @@ using LinearAlgebra, SparseArrays
Qv = convert.(Taylor1{TaylorN{Float64}}, Pv)

@test TaylorSeries.jacobian(Pv) == TaylorSeries.jacobian(Qv)

@test_throws ArgumentError Taylor1(2) + TaylorN(1)
@test_throws ArgumentError Taylor1(2) - TaylorN(1)
@test_throws ArgumentError Taylor1(2) * TaylorN(1)
@test_throws ArgumentError TaylorN(2) / Taylor1(1)
end

0 comments on commit ad6f423

Please sign in to comment.