Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flexibility in dispatch for iszero_tuple #667

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/dual.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ end
##########
Base.ArithmeticStyle(::Type{<:Dual{T,V}}) where {T,V} = Base.ArithmeticStyle(V)

unwrap_dual(::Type{Dual{T,V,N}}) where {T,V,N} = unwrap_dual(V)
unwrap_dual(::Type{V}) where V = V

##############
# Exceptions #
##############
Expand Down
6 changes: 5 additions & 1 deletion src/partials.jl
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,11 @@ end
@inline rand_tuple(::AbstractRNG, ::Type{Tuple{}}) = tuple()
@inline rand_tuple(::Type{Tuple{}}) = tuple()

@generated function iszero_tuple(tup::NTuple{N,V}) where {N,V}
iszero_tuple(tup::NTuple{N,V}) where {N,V} = _iszero_tuple(unwrap_dual(V), tup)

# default implementation; specific number types (e.g., Interval from IntervalArithmetic)
# can add specializations.
@generated function _iszero_tuple(::Type{V0}, tup::NTuple{N,V}) where {V0,N,V}
ex = Expr(:&&, [:(z == tup[$i]) for i=1:N]...)
return quote
z = zero(V)
Expand Down
Loading