From 758137248939a5cbca08452afb13d7988e7a18f3 Mon Sep 17 00:00:00 2001 From: Luis Benet Date: Thu, 2 Dec 2021 13:35:52 -0600 Subject: [PATCH] Add numtype to replace eltype (#289) * Add numtype (not exported) to replace eltype * Add numtype docstrings and add it to the docs * Add more tests * Export normalize_taylor from intervals.jl * Add docstrings of nonlinear_polynomial to docs * Bump patch version, and upgrade some compat entries --- Project.toml | 4 ++-- docs/src/api.md | 2 ++ docs/src/index.md | 5 +++++ src/TaylorSeries.jl | 9 +++++---- src/arithmetic.jl | 8 ++++---- src/auxiliary.jl | 11 +++++++++-- src/calculus.jl | 15 +++++++-------- src/functions.jl | 10 +++++----- src/intervals.jl | 1 + test/intervals.jl | 14 +++++++++----- test/manyvariables.jl | 13 +++++++++---- test/mixtures.jl | 33 ++++++++++++++++++++++----------- test/onevariable.jl | 35 +++++++++++++++++++++++++---------- 13 files changed, 105 insertions(+), 55 deletions(-) diff --git a/Project.toml b/Project.toml index 3c8d2217..d1d9598b 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "TaylorSeries" uuid = "6aa5eb33-94cf-58f4-a9d0-e4b2c4fc25ea" repo = "https://github.com/JuliaDiff/TaylorSeries.jl.git" -version = "0.11.2" +version = "0.11.3" [deps] LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" @@ -10,7 +10,7 @@ Requires = "ae029012-a4dd-5104-9daa-d747884805df" SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" [compat] -IntervalArithmetic = "0.15, 0.16, 0.17, 0.18" +IntervalArithmetic = "0.15, 0.16, 0.17, 0.18, 0.19, 0.20" Requires = "0.5.2, 1.0, 1.1" julia = "1" diff --git a/docs/src/api.md b/docs/src/api.md index f173b3eb..c71cc28b 100644 --- a/docs/src/api.md +++ b/docs/src/api.md @@ -45,6 +45,7 @@ hessian hessian! constant_term linear_polynomial +nonlinear_polynomial inverse abs norm @@ -67,6 +68,7 @@ in_base make_inverse_dict resize_coeffs1! resize_coeffsHP! +numtype mul! mul!(::HomogeneousPolynomial, ::HomogeneousPolynomial, ::HomogeneousPolynomial) mul!(::Vector{Taylor1{T}}, ::Union{Matrix{T},SparseMatrixCSC{T}},::Vector{Taylor1{T}}) where {T<:Number} diff --git a/docs/src/index.md b/docs/src/index.md index 5d37a869..d7ac947c 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -11,6 +11,11 @@ A [Julia](http://julialang.org) package for Taylor expansions in one or more ind - [David P. Sanders](http://sistemas.fciencias.unam.mx/~dsanders/), Facultad de Ciencias, Universidad Nacional Autónoma de México (UNAM). +### Citing + +If you find useful this package, please cite the paper: + +Benet, L., & Sanders, D. P. (2019). TaylorSeries.jl: Taylor expansions in one and several variables in Julia. Journal of Open Source Software, 4(36), 1–4. https://doi.org/10.5281/zenodo.2601941 ### License diff --git a/src/TaylorSeries.jl b/src/TaylorSeries.jl index b978e094..faafa3ef 100644 --- a/src/TaylorSeries.jl +++ b/src/TaylorSeries.jl @@ -45,7 +45,7 @@ import Base: zero, one, zeros, ones, isinf, isnan, iszero, power_by_squaring, rtoldefault, isfinite, isapprox, rad2deg, deg2rad -export Taylor1, TaylorN, HomogeneousPolynomial, AbstractSeries +export Taylor1, TaylorN, HomogeneousPolynomial, AbstractSeries, TS export getcoeff, derivative, integrate, differentiate, evaluate, evaluate!, inverse, set_taylor1_varname, @@ -54,9 +54,10 @@ export getcoeff, derivative, integrate, differentiate, set_variables, get_variables, get_variable_names, get_variable_symbols, # jacobian, hessian, jacobian!, hessian!, - ∇, taylor_expand, update!, - constant_term, linear_polynomial, nonlinear_polynomial, - normalize_taylor + ∇, taylor_expand, update!, + constant_term, linear_polynomial, nonlinear_polynomial + +const TS = TaylorSeries include("parameters.jl") include("hash_tables.jl") diff --git a/src/arithmetic.jl b/src/arithmetic.jl index 0e639a63..ad6fc0fb 100644 --- a/src/arithmetic.jl +++ b/src/arithmetic.jl @@ -172,7 +172,7 @@ for (f, fc) in ((:+, :(add!)), (:-, :(subst!))) function ($f)(a::TaylorN{Taylor1{T}}, b::Taylor1{S}) where {T<:NumberNotSeries,S<:NumberNotSeries} @inbounds aux = $f(a[0][1], b) - R = eltype(aux) + R = TS.numtype(aux) coeffs = Array{HomogeneousPolynomial{Taylor1{R}}}(undef, a.order+1) coeffs .= a.coeffs @inbounds coeffs[1] = aux @@ -182,7 +182,7 @@ for (f, fc) in ((:+, :(add!)), (:-, :(subst!))) function ($f)(b::Taylor1{S}, a::TaylorN{Taylor1{T}}) where {T<:NumberNotSeries,S<:NumberNotSeries} @inbounds aux = $f(b, a[0][1]) - R = eltype(aux) + R = TS.numtype(aux) coeffs = Array{HomogeneousPolynomial{Taylor1{R}}}(undef, a.order+1) @__dot__ coeffs = $f(a.coeffs) @inbounds coeffs[1] = aux @@ -192,7 +192,7 @@ for (f, fc) in ((:+, :(add!)), (:-, :(subst!))) function ($f)(a::Taylor1{TaylorN{T}}, b::TaylorN{S}) where {T<:NumberNotSeries,S<:NumberNotSeries} @inbounds aux = $f(a[0], b) - R = eltype(aux) + R = TS.numtype(aux) coeffs = Array{TaylorN{R}}(undef, a.order+1) coeffs .= a.coeffs @inbounds coeffs[1] = aux @@ -202,7 +202,7 @@ for (f, fc) in ((:+, :(add!)), (:-, :(subst!))) function ($f)(b::TaylorN{S}, a::Taylor1{TaylorN{T}}) where {T<:NumberNotSeries,S<:NumberNotSeries} @inbounds aux = $f(b, a[0]) - R = eltype(aux) + R = TS.numtype(aux) coeffs = Array{TaylorN{R}}(undef, a.order+1) @__dot__ coeffs = $f(a.coeffs) @inbounds coeffs[1] = aux diff --git a/src/auxiliary.jl b/src/auxiliary.jl index f26e6ee4..79358bbb 100644 --- a/src/auxiliary.jl +++ b/src/auxiliary.jl @@ -229,12 +229,19 @@ for T in (:Taylor1, :HomogeneousPolynomial, :TaylorN) @inline lastindex(a::$T) = a.order end @inline eachindex(a::$T) = firstindex(a):lastindex(a) - @inline eltype(::$T{S}) where {S<:Number} = S + @inline numtype(::$T{S}) where {S<:Number} = S @inline size(a::$T) = size(a.coeffs) @inline get_order(a::$T) = a.order @inline axes(a::$T) = () end end +numtype(a) = eltype(a) + +@doc doc""" + numtype(a::AbstractSeries) + +Return the type of the elements of the coefficients of `a`. +""" numtype ## fixorder ## @@ -305,7 +312,7 @@ constant_term(a::Number) = a """ linear_polynomial(a) -Returns the linear part of `a` as a polynomial (`Taylor1` or `TaylorN`), +Returns the linear part of `a` as a polynomial (`Taylor1` or `TaylorN`), *without* the constant term. The fallback behavior is to return `a` itself. """ linear_polynomial(a::Taylor1) = Taylor1([zero(a[1]), a[1]], a.order) diff --git a/src/calculus.jl b/src/calculus.jl index d758e016..a0eebd76 100644 --- a/src/calculus.jl +++ b/src/calculus.jl @@ -34,7 +34,7 @@ const derivative = differentiate differentiate!(res, a) --> nothing In-place version of `differentiate`. Compute the `Taylor1` polynomial of the -differential of `a::Taylor1` and return it as `res` (order of `res` remains +differential of `a::Taylor1` and return it as `res` (order of `res` remains unchanged). """ function differentiate!(res::Taylor1, a::Taylor1) @@ -127,8 +127,7 @@ to the `r`-th variable. """ function differentiate(a::HomogeneousPolynomial, r::Int) @assert 1 ≤ r ≤ get_numvars() - # @show zero(a[1]) zero(eltype(a)) - T = eltype(a) + T = TS.numtype(a) a.order == 0 && return HomogeneousPolynomial(zero(a[1]), 0) @inbounds num_coeffs = size_table[a.order] coeffs = zeros(T,num_coeffs) @@ -158,7 +157,7 @@ to the `r`-th variable. The `r`-th variable may be also specified through its symbol. """ function differentiate(a::TaylorN, r=1::Int) - T = eltype(a) + T = TS.numtype(a) coeffs = Array{HomogeneousPolynomial{T}}(undef, a.order) @inbounds for ord = 1:a.order @@ -223,7 +222,7 @@ end Compute the gradient of the polynomial `f::TaylorN`. """ function gradient(f::TaylorN) - T = eltype(f) + T = TS.numtype(f) numVars = get_numvars() grad = Array{TaylorN{T}}(undef, numVars) @inbounds for nv = 1:numVars @@ -361,7 +360,7 @@ function integrate(a::HomogeneousPolynomial, r::Int) @inbounds posTb = pos_table[a.order+2] @inbounds num_coeffs = size_table[a.order+1] - T = promote_type(eltype(a), eltype(a[1]/1)) + T = promote_type(TS.numtype(a), TS.numtype(a[1]/1)) coeffs = zeros(T, size_table[a.order+2]) @inbounds for i = 1:num_coeffs @@ -388,7 +387,7 @@ where `x0` the integration constant and must be independent of the `r`-th variable; if `x0` is ommitted, it is taken as zero. """ function integrate(a::TaylorN, r::Int) - T = promote_type(eltype(a), eltype(a[0]/1)) + T = promote_type(TS.numtype(a), TS.numtype(a[0]/1)) order_max = min(get_order(), a.order+1) coeffs = zeros(HomogeneousPolynomial{T}, order_max) @@ -408,7 +407,7 @@ function integrate(a::TaylorN, r::Int, x0::TaylorN) return x0+res end integrate(a::TaylorN, r::Int, x0) = - integrate(a,r,TaylorN(HomogeneousPolynomial([convert(eltype(a),x0)], 0))) + integrate(a,r,TaylorN(HomogeneousPolynomial([convert(TS.numtype(a),x0)], 0))) integrate(a::TaylorN, s::Symbol) = integrate(a, lookupvar(s)) integrate(a::TaylorN, s::Symbol, x0::TaylorN) = integrate(a, lookupvar(s), x0) diff --git a/src/functions.jl b/src/functions.jl index dfc8f51d..8aaabccb 100644 --- a/src/functions.jl +++ b/src/functions.jl @@ -22,7 +22,7 @@ for T in (:Taylor1, :TaylorN) end function log(a::$T) - iszero(constant_term(a)) && throw(DomainError(a, + iszero(constant_term(a)) && throw(DomainError(a, """The 0-th order coefficient must be non-zero in order to expand `log` around 0.""")) order = a.order @@ -63,7 +63,7 @@ for T in (:Taylor1, :TaylorN) function asin(a::$T) a0 = constant_term(a) - a0^2 == one(a0) && throw(DomainError(a, + a0^2 == one(a0) && throw(DomainError(a, """Series expansion of asin(x) diverges at x = ±1.""")) order = a.order @@ -79,7 +79,7 @@ for T in (:Taylor1, :TaylorN) function acos(a::$T) a0 = constant_term(a) - a0^2 == one(a0) && throw(DomainError(a, + a0^2 == one(a0) && throw(DomainError(a, """Series expansion of asin(x) diverges at x = ±1.""")) order = a.order @@ -100,7 +100,7 @@ for T in (:Taylor1, :TaylorN) aa = one(aux) * a c = $T( aux, order) r = $T(one(aux) + a0^2, order) - iszero(constant_term(r)) && throw(DomainError(a, + iszero(constant_term(r)) && throw(DomainError(a, """Series expansion of atan(x) diverges at x = ±im.""")) for k in eachindex(a) @@ -576,7 +576,7 @@ function inverse(f::Taylor1{T}) where {T<:Number} z = Taylor1(T,f.order) zdivf = z/f zdivfpown = zdivf - S = eltype(zdivf) + S = TS.numtype(zdivf) coeffs = zeros(S,f.order+1) @inbounds for n in 1:f.order diff --git a/src/intervals.jl b/src/intervals.jl index b1cf25cf..ae870e47 100644 --- a/src/intervals.jl +++ b/src/intervals.jl @@ -105,6 +105,7 @@ are mapped by an affine transformation to the intervals `-1..1` normalize_taylor(a::TaylorN, I::IntervalBox{N,T}, symI::Bool=true) where {T<:Real,N} = _normalize(a, I, Val(symI)) +export normalize_taylor # I -> -1..1 function _normalize(a::Taylor1, I::Interval{T}, ::Val{true}) where {T<:Real} diff --git a/test/intervals.jl b/test/intervals.jl index 884e990a..fff721fa 100644 --- a/test/intervals.jl +++ b/test/intervals.jl @@ -15,8 +15,12 @@ eeuler = Base.MathConstants.e ti = Taylor1(Interval{Float64}, 10) x, y = set_variables(Interval{Float64}, "x y") - @test eltype(ti) == Interval{Float64} - @test eltype(x) == Interval{Float64} + # @test eltype(ti) == Interval{Float64} + # @test eltype(x) == Interval{Float64} + @test eltype(ti) == Taylor1{Interval{Float64}} + @test eltype(x) == TaylorN{Interval{Float64}} + @test TS.numtype(ti) == Interval{Float64} + @test TS.numtype(x) == Interval{Float64} @test p4(ti,-a) == (ti-a)^4 @test p5(ti,-a) == (ti-a)^5 @@ -85,12 +89,12 @@ eeuler = Base.MathConstants.e @test diam(g1(-1..1)) < diam(gt(ii)) # Test display for Taylor1{Complex{Interval{T}}} - vc = [complex(1.5 .. 2, 0 ), complex(-2 .. -1, -1 .. 1 ), + vc = [complex(1.5 .. 2, 0 ), complex(-2 .. -1, -1 .. 1 ), complex( -1 .. 1.5, -1 .. 1.5), complex( 0..0, -1 .. 1.5)] displayBigO(false) - @test string(Taylor1(vc, 5)) == + @test string(Taylor1(vc, 5)) == " ( [1.5, 2] + [0, 0]im ) - ( [1, 2] + [-1, 1]im ) t + ( [-1, 1.5] + [-1, 1.5]im ) t² + ( [0, 0] + [-1, 1.5]im ) t³ " displayBigO(true) - @test string(Taylor1(vc, 5)) == + @test string(Taylor1(vc, 5)) == " ( [1.5, 2] + [0, 0]im ) - ( [1, 2] + [-1, 1]im ) t + ( [-1, 1.5] + [-1, 1.5]im ) t² + ( [0, 0] + [-1, 1.5]im ) t³ + 𝒪(t⁶)" end diff --git a/test/manyvariables.jl b/test/manyvariables.jl index 35bd715a..9f321d99 100644 --- a/test/manyvariables.jl +++ b/test/manyvariables.jl @@ -175,7 +175,9 @@ using LinearAlgebra @test !iszero(uT) @test iszero(zeroT) - @test eltype(xH) == Int + @test convert(eltype(xH), xH) === xH + @test eltype(xH) == HomogeneousPolynomial{Int} + @test TS.numtype(xH) == Int @test length(xH) == 2 @test zero(xH) == 0*xH @test one(yH) == xH+yH @@ -192,7 +194,9 @@ using LinearAlgebra @test TaylorN(uT) == convert(TaylorN{Complex},1) @test get_numvars() == 2 @test length(uT) == get_order()+1 - @test eltype(convert(TaylorN{Complex{Float64}},1)) == Complex{Float64} + @test convert(eltype(xT), xT) === xT + @test eltype(convert(TaylorN{Complex{Float64}},1)) == TaylorN{Complex{Float64}} + @test TS.numtype(convert(TaylorN{Complex{Float64}},1)) == Complex{Float64} @test 1+xT+yT == TaylorN(1,1) + TaylorN([xH,yH],1) @test xT-yT-1 == TaylorN([-1,xH-yH]) @@ -222,7 +226,7 @@ using LinearAlgebra @test (xH/complex(0,BigInt(3)))' == im*HomogeneousPolynomial([BigInt(1),0])/3 @test evaluate(xH) == zero(eltype(xH)) - @test xH() == zero(eltype(xH)) + @test xH() == zero(TS.numtype(xH)) @test xH([1,1]) == evaluate(xH, [1,1]) @test xH((1,1)) == xH(1, 1.0) == evaluate(xH, (1, 1.0)) == 1 hp = -5.4xH+6.89yH @@ -653,7 +657,8 @@ using LinearAlgebra @test taylor_expand(f11, 1.0,2.0) == taylor_expand(f22, [1,2.0]) @test evaluate(taylor_expand(x->x[1] + x[2], [1,2])) == 3.0 f33(x,y) = 3x+y - @test eltype(taylor_expand(f33,1,1)) == eltype(1) + @test eltype(taylor_expand(f33,1,1)) == TaylorN{eltype(1)} + @test TS.numtype(taylor_expand(f33,1,1)) == eltype(1) x,y = get_variables() xysq = x^2 + y^2 update!(xysq,[1.0,-2.0]) diff --git a/test/mixtures.jl b/test/mixtures.jl index beebd1e2..0d58642e 100644 --- a/test/mixtures.jl +++ b/test/mixtures.jl @@ -15,8 +15,11 @@ using LinearAlgebra, SparseArrays yH = HomogeneousPolynomial(Int, 2) tN = Taylor1(TaylorN{Float64}, 3) - @test eltype(xH) == Int - @test eltype(tN) == TaylorN{Float64} + @test convert(eltype(tN), tN) == tN + @test eltype(xH) == HomogeneousPolynomial{Int} + @test TS.numtype(xH) == Int + @test eltype(tN) == Taylor1{TaylorN{Float64}} + @test TS.numtype(tN) == TaylorN{Float64} @test tN.order == 3 @test string(zero(tN)) == " 0.0 + 𝒪(‖x‖¹) + 𝒪(t⁴)" @test string(tN) == " ( 1.0 + 𝒪(‖x‖¹)) t + 𝒪(t⁴)" @@ -39,7 +42,9 @@ using LinearAlgebra, SparseArrays t = Taylor1(3) xHt = HomogeneousPolynomial(typeof(t), 1) - @test eltype(xHt) == Taylor1{Float64} + @test convert(eltype(xHt), xHt) === xHt + @test eltype(xHt) == HomogeneousPolynomial{Taylor1{Float64}} + @test TS.numtype(xHt) == Taylor1{Float64} @test string(xHt) == " ( 1.0 + 𝒪(t¹)) x₁" xHt = HomogeneousPolynomial([one(t), zero(t)]) yHt = HomogeneousPolynomial([zero(t), t]) @@ -49,7 +54,8 @@ using LinearAlgebra, SparseArrays @test 3*xHt == HomogeneousPolynomial([3*one(t), zero(t)]) @test t*xHt == HomogeneousPolynomial([t, zero(t)]) @test complex(0,1)*xHt == HomogeneousPolynomial([1im*one(t), zero(1im*t)]) - @test eltype(complex(0,1)*xHt) == Taylor1{Complex{Float64}} + @test eltype(complex(0,1)*xHt) == HomogeneousPolynomial{Taylor1{Complex{Float64}}} + @test TS.numtype(complex(0,1)*xHt) == Taylor1{Complex{Float64}} @test (xHt+yHt)(1, 1) == 1+t @test (xHt+yHt)([1, 1]) == (xHt+yHt)((1, 1)) @@ -60,10 +66,13 @@ using LinearAlgebra, SparseArrays t1N = convert(Taylor1{TaylorN{Float64}}, tN1) @test t1N[0] == HomogeneousPolynomial(1) ctN1 = convert(TaylorN{Taylor1{Float64}}, t1N) - @test eltype(xHt) == Taylor1{Float64} - @test eltype(tN1) == Taylor1{Float64} - @test eltype(Taylor1([xH])) == HomogeneousPolynomial{Int} - @test eltype(tN1) == Taylor1{Float64} + @test convert(eltype(tN1), tN1) === tN1 + @test eltype(xHt) == HomogeneousPolynomial{Taylor1{Float64}} + @test eltype(tN1) == TaylorN{Taylor1{Float64}} + @test eltype(Taylor1([xH])) == Taylor1{HomogeneousPolynomial{Int}} + @test TS.numtype(xHt) == Taylor1{Float64} + @test TS.numtype(tN1) == Taylor1{Float64} + @test TS.numtype(Taylor1([xH])) == HomogeneousPolynomial{Int} @test get_order(HomogeneousPolynomial([Taylor1(1), 1.0+Taylor1(2)])) == 1 @test 3*tN1 == TaylorN([HomogeneousPolynomial([3t]),3xHt,3yHt^2]) @test t*tN1 == TaylorN([HomogeneousPolynomial([t^2]),xHt*t,t*yHt^2]) @@ -158,7 +167,8 @@ using LinearAlgebra, SparseArrays x = TaylorN( [HomogeneousPolynomial(zero(t), 5), HomogeneousPolynomial([one(t),zero(t)])], 5) y = TaylorN(typeof(tint), 2, order=5) @test typeof(x) == TaylorN{Taylor1{Float64}} - @test eltype(y) == Taylor1{Int} + @test eltype(y) == TaylorN{Taylor1{Int}} + @test TS.numtype(y) == Taylor1{Int} @test -x == 0 - x @test +y == y @test one(y)/(1+x) == 1 - x + x^2 - x^3 + x^4 - x^5 @@ -170,7 +180,8 @@ using LinearAlgebra, SparseArrays δx, δy = set_variables("δx δy") xx = 1+Taylor1(δx,5) @test typeof(xx) == Taylor1{TaylorN{Float64}} - @test eltype(xx) == TaylorN{Float64} + @test eltype(xx) == Taylor1{TaylorN{Float64}} + @test TS.numtype(xx) == TaylorN{Float64} @test !isnan(xx) @test !isnan(δx) @test !isinf(xx) @@ -318,6 +329,7 @@ end @testset "Tests with nested Taylor1s" begin ti = Taylor1(3) to = Taylor1([zero(ti), one(ti)], 9) + @test convert(eltype(to), to) === to @test string(to) == " ( 1.0 + 𝒪(t⁴)) t + 𝒪(t¹⁰)" @test string(to^2) == " ( 1.0 + 𝒪(t⁴)) t² + 𝒪(t¹⁰)" @test ti + to == Taylor1([ti, one(ti)], 9) @@ -327,7 +339,6 @@ end @test get_order(tito/to) == get_order(to)-1 @test tito / ti == to @test get_order(tito/ti) == get_order(to) - # @test get_order((tito/ti)[1]) == get_order(ti)-1 @test ti^2-to^2 == (ti+to)*(ti-to) @test sin(to) ≈ Taylor1(one(ti) .* sin(Taylor1(10)).coeffs, 9) @test to(1 + ti) == 1 + ti diff --git a/test/onevariable.jl b/test/onevariable.jl index 63bd02d5..fd0b6e0b 100644 --- a/test/onevariable.jl +++ b/test/onevariable.jl @@ -22,8 +22,11 @@ Base.iszero(::SymbNumber) = false ot = 1.0*one(t) tol1 = eps(1.0) + @test TS === TaylorSeries @test Taylor1 <: AbstractSeries @test Taylor1{Float64} <: AbstractSeries{Float64} + @test TS.numtype(1.0) == eltype(1.0) + @test TS.numtype([1.0]) == eltype([1.0]) @test Taylor1([1,2,3,4,5], 2) == Taylor1([1,2,3]) @test Taylor1(t[0:3]) == Taylor1(t[0:get_order(t)], 4) @@ -105,24 +108,34 @@ Base.iszero(::SymbNumber) = false @test Taylor1(Complex{Float64},3)[1] == complex(1.0,0.0) @test getindex(Taylor1(3),1) == 1.0 @inferred convert(Taylor1{Complex{Float64}},ot) == Taylor1{Complex{Float64}} - @test eltype(convert(Taylor1{Complex{Float64}},ot)) == Complex{Float64} - @test eltype(convert(Taylor1{Complex{Float64}},1)) == Complex{Float64} - @test eltype(convert(Taylor1, 1im)) == Complex{Int} + @test eltype(convert(Taylor1{Complex{Float64}},ot)) == Taylor1{Complex{Float64}} + @test eltype(convert(Taylor1{Complex{Float64}},1)) == Taylor1{Complex{Float64}} + @test eltype(convert(Taylor1, 1im)) == Taylor1{Complex{Int}} + @test TS.numtype(convert(Taylor1{Complex{Float64}},ot)) == Complex{Float64} + @test TS.numtype(convert(Taylor1{Complex{Float64}},1)) == Complex{Float64} + @test TS.numtype(convert(Taylor1, 1im)) == Complex{Int} @test convert(Taylor1, 1im) == Taylor1(1im, 0) + @test convert(eltype(t), t) === t + @test convert(eltype(ot), ot) === ot @test convert(Taylor1{Int},[0,2]) == 2*t @test convert(Taylor1{Complex{Int}},[0,2]) == (2+0im)*t @test convert(Taylor1{BigFloat},[0.0, 1.0]) == ta(big(0.0)) @test promote(t,Taylor1(1.0,0)) == (ta(0.0),ot) @test promote(0,Taylor1(1.0,0)) == (zt,ot) - @test eltype(promote(ta(0),zeros(Int,2))[2]) == Int - @test eltype(promote(ta(0.0),zeros(Int,2))[2]) == Float64 - @test eltype(promote(0,Taylor1(ot))[1]) == Float64 - @test eltype(promote(1.0+im, zt)[1]) == Complex{Float64} + @test eltype(promote(ta(0),zeros(Int,2))[2]) == Taylor1{Int} + @test eltype(promote(ta(0.0),zeros(Int,2))[2]) == Taylor1{Float64} + @test eltype(promote(0,Taylor1(ot))[1]) == Taylor1{Float64} + @test eltype(promote(1.0+im, zt)[1]) == Taylor1{Complex{Float64}} + @test TS.numtype(promote(ta(0),zeros(Int,2))[2]) == Int + @test TS.numtype(promote(ta(0.0),zeros(Int,2))[2]) == Float64 + @test TS.numtype(promote(0,Taylor1(ot))[1]) == Float64 + @test TS.numtype(promote(1.0+im, zt)[1]) == Complex{Float64} @test length(Taylor1(10)) == 11 @test length.( TaylorSeries.fixorder(zt, Taylor1([1])) ) == (16, 16) @test length.( TaylorSeries.fixorder(zt, Taylor1([1], 1)) ) == (2, 2) - @test eltype(TaylorSeries.fixorder(zt,Taylor1([1]))[1]) == Int + @test eltype(TaylorSeries.fixorder(zt,Taylor1([1]))[1]) == Taylor1{Int} + @test TS.numtype(TaylorSeries.fixorder(zt,Taylor1([1]))[1]) == Int @test TaylorSeries.findfirst(t) == 1 @test TaylorSeries.findfirst(t^2) == 2 @test TaylorSeries.findfirst(ot) == 0 @@ -216,7 +229,8 @@ Base.iszero(::SymbNumber) = false trational = ta(0//1) @inferred ta(0//1) == Taylor1{Rational{Int}} - @test eltype(trational) == Rational{Int} + @test eltype(trational) == Taylor1{Rational{Int}} + @test TS.numtype(trational) == Rational{Int} @test trational + 1//3 == Taylor1([1//3,1],15) @test complex(3,1)*trational^2 == Taylor1([0//1,0//1,complex(3,1)//1],15) @test trational^2/3 == Taylor1([0//1,0//1,1//3],15) @@ -237,7 +251,8 @@ Base.iszero(::SymbNumber) = false @test taylor_expand(x->x^2+1) == Taylor1(15)*Taylor1(15) + 1 @test evaluate(taylor_expand(cos,0.)) == cos(0.) @test evaluate(taylor_expand(tan,pi/4)) == tan(pi/4) - @test eltype(taylor_expand(x->x^2+1,1)) == eltype(1) + @test eltype(taylor_expand(x->x^2+1,1)) == Taylor1{Int} + @test TS.numtype(taylor_expand(x->x^2+1,1)) == Int tsq = t^2 update!(tsq,2.0) @test tsq == (t+2.0)^2