Skip to content

Commit

Permalink
Change slicing to tail
Browse files Browse the repository at this point in the history
  • Loading branch information
tansongchen authored and lrnv committed Sep 25, 2024
1 parent 32e0aef commit ecf0418
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
20 changes: 18 additions & 2 deletions src/primitive.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}
Expand Down
7 changes: 3 additions & 4 deletions src/scalar.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import Base: zero, one, adjoint, conj, transpose
import Base: +, -, *, /
import Base: convert, promote_rule

export TaylorScalar
Expand Down Expand Up @@ -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}
Expand Down

0 comments on commit ecf0418

Please sign in to comment.