From ad6f42367beed965197c237a6fc832ca809cbdaa Mon Sep 17 00:00:00 2001 From: Luis Benet Date: Fri, 12 Jul 2019 11:09:28 -0500 Subject: [PATCH] ArgumentErrorfor promotion among non-compatible Taylor1 and TaylorN (#220) Fixes #219 --- src/arithmetic.jl | 4 ++++ src/conversion.jl | 3 +++ test/mixtures.jl | 5 +++++ 3 files changed, 12 insertions(+) diff --git a/src/arithmetic.jl b/src/arithmetic.jl index 0b5112ef..1f8bd90c 100644 --- a/src/arithmetic.jl +++ b/src/arithmetic.jl @@ -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 ## diff --git a/src/conversion.jl b/src/conversion.jl index aeba6d31..0c8b0dfb 100644 --- a/src/conversion.jl +++ b/src/conversion.jl @@ -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")) diff --git a/test/mixtures.jl b/test/mixtures.jl index 4ec22a15..36b93857 100644 --- a/test/mixtures.jl +++ b/test/mixtures.jl @@ -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