From ecf0418ecb2ac5d248d36cbb1c0c244320d446e7 Mon Sep 17 00:00:00 2001 From: Songchen Tan Date: Wed, 25 Sep 2024 14:20:57 +0200 Subject: [PATCH] Change slicing to tail --- src/primitive.jl | 20 ++++++++++++++++++-- src/scalar.jl | 7 +++---- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/primitive.jl b/src/primitive.jl index 7aa8d13..17b94a4 100644 --- a/src/primitive.jl +++ b/src/primitive.jl @@ -5,9 +5,21 @@ import Base: asin, acos, atan, acot, asec, acsc, asinh, acosh, atanh, acoth, ase import Base: sinc, cosc import Base: +, -, *, /, \, ^, >, <, >=, <=, == import Base: hypot, max, min +import Base: zero, one, adjoint, conj, transpose + +using Base: tail # Unary +@inline zero(::Type{TaylorScalar{T, N}}) where {T, N} = TaylorScalar{T, N}(zero(T)) +@inline one(::Type{TaylorScalar{T, N}}) where {T, N} = TaylorScalar{T, N}(one(T)) +@inline zero(::TaylorScalar{T, N}) where {T, N} = zero(TaylorScalar{T, N}) +@inline one(::TaylorScalar{T, N}) where {T, N} = one(TaylorScalar{T, N}) + +transpose(t::TaylorScalar) = t +adjoint(t::TaylorScalar) = t +conj(t::TaylorScalar) = t + ## Delegated @inline sqrt(t::TaylorScalar) = t^0.5 @@ -113,8 +125,12 @@ end ex = :($ex; TaylorScalar($([Symbol('v', i) for i in 1:N]...))) return :(@inbounds $ex) end -@inline *(a::TaylorScalar{T1, N}, b::TaylorScalar{T2, N}) where {T1,T2,N} = *(promote(a,b)...) -@inline /(a::TaylorScalar{T1, N}, b::TaylorScalar{T2, N}) where {T1,T2,N} = *(promote(a,b)...) +@inline function *(a::TaylorScalar{T1, N}, b::TaylorScalar{T2, N}) where {T1, T2, N} + *(promote(a, b)...) +end +@inline function /(a::TaylorScalar{T1, N}, b::TaylorScalar{T2, N}) where {T1, T2, N} + *(promote(a, b)...) +end for R in (Integer, Real) @eval @generated function ^(t::TaylorScalar{T, N}, n::S) where {S <: $R, T, N} diff --git a/src/scalar.jl b/src/scalar.jl index 16791b5..8f3814b 100644 --- a/src/scalar.jl +++ b/src/scalar.jl @@ -1,5 +1,3 @@ -import Base: zero, one, adjoint, conj, transpose -import Base: +, -, *, / import Base: convert, promote_rule export TaylorScalar @@ -89,8 +87,9 @@ function promote_rule(::Type{TaylorScalar{T, N}}, ::Type{S}) where {T, S, N} TaylorScalar{promote_type(T, S), N} end -function promote_rule(::Type{TaylorScalar{T1, N}}, ::Type{TaylorScalar{T2,N}}) where {T1, T2, N} -TaylorScalar{promote_type(T1,T2), N} +function promote_rule(::Type{TaylorScalar{T1, N}}, + ::Type{TaylorScalar{T2, N}}) where {T1, T2, N} + TaylorScalar{promote_type(T1, T2), N} end function (::Type{F})(x::TaylorScalar{T, N}) where {T, N, F <: AbstractFloat}