Skip to content

Commit a79b022

Browse files
authored
Add StaticArrays extension (#353)
* Add StaticArrays extension * Bump patch version * Add promote_op for matrix-matrix product * Update runtests.jl * Add Base.float dispatches for TaylorSeries types and variables
1 parent ee8a685 commit a79b022

File tree

9 files changed

+87
-4
lines changed

9 files changed

+87
-4
lines changed

Project.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "TaylorSeries"
22
uuid = "6aa5eb33-94cf-58f4-a9d0-e4b2c4fc25ea"
33
repo = "https://github.com/JuliaDiff/TaylorSeries.jl.git"
4-
version = "0.17.2"
4+
version = "0.17.3"
55

66
[deps]
77
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
@@ -11,9 +11,11 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1111

1212
[weakdeps]
1313
IntervalArithmetic = "d1acc4aa-44c8-5952-acd4-ba5d80a2a253"
14+
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
1415

1516
[extensions]
1617
TaylorSeriesIAExt = "IntervalArithmetic"
18+
TaylorSeriesSAExt = "StaticArrays"
1719

1820
[compat]
1921
Aqua = "0.8"
@@ -22,6 +24,7 @@ LinearAlgebra = "<0.0.1, 1"
2224
Markdown = "<0.0.1, 1"
2325
Requires = "0.5.2, 1"
2426
SparseArrays = "<0.0.1, 1"
27+
StaticArrays = "1"
2528
Test = "<0.0.1, 1"
2629
julia = "1"
2730

@@ -30,7 +33,8 @@ Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
3033
IntervalArithmetic = "d1acc4aa-44c8-5952-acd4-ba5d80a2a253"
3134
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
3235
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
36+
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
3337
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
3438

3539
[targets]
36-
test = ["IntervalArithmetic", "LinearAlgebra", "SparseArrays", "Test", "Aqua"]
40+
test = ["IntervalArithmetic", "LinearAlgebra", "SparseArrays", "StaticArrays", "Test", "Aqua"]

ext/TaylorSeriesSAExt.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module TaylorSeriesSAExt
2+
3+
using TaylorSeries
4+
5+
import Base.promote_op
6+
import LinearAlgebra: matprod
7+
8+
isdefined(Base, :get_extension) ? (using StaticArrays) : (using ..StaticArrays)
9+
10+
promote_op(::typeof(adjoint), ::Type{T}) where {T<:AbstractSeries} = T
11+
promote_op(::typeof(matprod), ::Type{T}, ::Type{U}) where {T <: AbstractSeries, U <: AbstractFloat} = T
12+
promote_op(::typeof(matprod), ::Type{T}, ::Type{T}) where {T <: AbstractSeries} = T
13+
14+
end

src/TaylorSeries.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ import Base: zero, one, zeros, ones, isinf, isnan, iszero, isless,
4949
power_by_squaring,
5050
rtoldefault, isfinite, isapprox, rad2deg, deg2rad
5151

52+
import Base.float
53+
5254
export Taylor1, TaylorN, HomogeneousPolynomial, AbstractSeries, TS
5355

5456
export getcoeff, derivative, integrate, differentiate,
@@ -84,6 +86,9 @@ function __init__()
8486
@require IntervalArithmetic = "d1acc4aa-44c8-5952-acd4-ba5d80a2a253" begin
8587
include("../ext/TaylorSeriesIAExt.jl")
8688
end
89+
@require StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" begin
90+
include("../ext/TaylorSeriesSAExt.jl")
91+
end
8792
end
8893
end
8994

src/conversion.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,3 +201,12 @@ function promote(a::Taylor1{Taylor1{T}}, b::Taylor1{T}) where {T<:NumberNotSerie
201201
end
202202
promote(b::Taylor1{T}, a::Taylor1{Taylor1{T}}) where {T<:NumberNotSeriesN} =
203203
reverse(promote(a, b))
204+
205+
# float
206+
float(::Type{Taylor1{T}}) where T<:Number = Taylor1{float(T)}
207+
float(::Type{HomogeneousPolynomial{T}}) where T<:Number = HomogeneousPolynomial{float(T)}
208+
float(::Type{TaylorN{T}}) where T<:Number = TaylorN{float(T)}
209+
210+
float(x::Taylor1{T}) where T<:Number = convert(Taylor1{float(T)}, x)
211+
float(x::HomogeneousPolynomial{T}) where T<:Number = convert(HomogeneousPolynomial{float(T)}, x)
212+
float(x::TaylorN{T}) where T<:Number = convert(TaylorN{float(T)}, x)

test/manyvariables.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,15 @@ end
782782
# Lexicographic tests with 4 vars
783783
@test 1 > dx[1] > dx[2] > dx[3] > dx[4]
784784
@test dx[4]^2 < dx[3]*dx[4] < dx[3]^2 < dx[2]*dx[4] < dx[2]*dx[3] < dx[2]^2 < dx[1]*dx[4] < dx[1]*dx[3] < dx[1]*dx[2] < dx[1]^2
785+
786+
@testset "Test Base.float overloads for HomogeneousPolynomial and TaylorN" begin
787+
@test float(HomogeneousPolynomial(-7, 2)) == HomogeneousPolynomial(-7.0, 2)
788+
@test float(HomogeneousPolynomial(1+im, 2)) == HomogeneousPolynomial(float(1+im), 2)
789+
@test float(TaylorN(Int, 2)) == TaylorN(2)
790+
@test float(TaylorN(Complex{Rational}, 2)) == TaylorN(float(Complex{Rational}), 2)
791+
@test float(HomogeneousPolynomial{Complex{Int}}) == float(HomogeneousPolynomial{Complex{Float64}})
792+
@test float(TaylorN{Complex{Rational}}) == float(TaylorN{Complex{Float64}})
793+
end
785794
end
786795

787796
@testset "Integrate for several variables" begin

test/mixtures.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,17 @@ using Test
495495
two = 2one(x[0])
496496
@test two/x == 2/x == 2.0/x
497497
@test (2one(x))/x == 2/x
498+
499+
@testset "Test Base.float overloads for Taylor1 and TaylorN mixtures" begin
500+
q = get_variables(Int)
501+
x1N = Taylor1(q)
502+
@test float(x1N) == Taylor1(float.(q))
503+
xN1 = convert(TaylorN{Taylor1{Int}}, x1N)
504+
@test float(xN1) == convert(TaylorN{Taylor1{Float64}}, Taylor1(float.(q)))
505+
@test float(Taylor1{TaylorN{Int}}) == Taylor1{TaylorN{Float64}}
506+
@test float(TaylorN{Taylor1{Int}}) == TaylorN{Taylor1{Float64}}
507+
@test float(TaylorN{Taylor1{Complex{Int}}}) == TaylorN{Taylor1{Complex{Float64}}}
508+
end
498509
end
499510

500511
@testset "Tests with nested Taylor1s" begin

test/onevariable.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,17 @@ Base.iszero(::SymbNumber) = false
625625
# Test fallback pretty_print
626626
st = Taylor1([SymbNumber(:x₀), SymbNumber(:x₁)])
627627
@test string(st) == " SymbNumber(:x₀) + SymbNumber(:x₁) t + 𝒪(t²)"
628+
629+
@testset "Test Base.float overloads for Taylor1" begin
630+
@test float(Taylor1(-3, 2)) == Taylor1(-3.0, 2)
631+
@test float(Taylor1(-1//2, 2)) == Taylor1(-0.5, 2)
632+
@test float(Taylor1(3 - 0im, 2)) == Taylor1(3.0 - 0.0im, 2)
633+
x = Taylor1(rand(5))
634+
@test float(x) == x
635+
@test float(Taylor1{Int32}) == Taylor1{Float64}
636+
@test float(Taylor1{Int}) == Taylor1{Float64}
637+
@test float(Taylor1{Complex{Int}}) == Taylor1{ComplexF64}
638+
end
628639
end
629640

630641
@testset "Test inv for Matrix{Taylor1{Float64}}" begin

test/runtests.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
# Tests for TaylorSeries
44

55
testfiles = (
6-
"aqua.jl",
76
"onevariable.jl",
87
"manyvariables.jl",
98
"mixtures.jl",
109
"mutatingfuncts.jl",
1110
"intervals.jl",
1211
"broadcasting.jl",
1312
"identities_Euler.jl",
14-
"fateman40.jl"
13+
"fateman40.jl",
14+
"staticarrays.jl"
1515
)
1616

1717
for file in testfiles

test/staticarrays.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# This file is part of TaylorSeries.jl, MIT licensed
2+
#
3+
4+
using TaylorSeries, StaticArrays
5+
6+
using Test
7+
# eeuler = Base.MathConstants.e
8+
9+
@testset "Tests TaylorSeries operations over StaticArrays types" begin
10+
q = set_variables("q", order=2, numvars=2)
11+
m = @SMatrix fill(Taylor1(rand(2).*q), 3, 3)
12+
mt = m'
13+
@test m isa SMatrix{3, 3, Taylor1{TaylorN{Float64}}, 9}
14+
@test mt isa SMatrix{3, 3, Taylor1{TaylorN{Float64}}, 9}
15+
v = @SVector [-1.1, 3.4, 7.62345e-1]
16+
mtv = mt * v
17+
@test mtv isa SVector{3, Taylor1{TaylorN{Float64}}}
18+
mmt = m * mt
19+
@test mmt isa SMatrix{3, 3, Taylor1{TaylorN{Float64}}, 9}
20+
end

0 commit comments

Comments
 (0)