Skip to content

Commit

Permalink
Merge pull request #667 from JuliaDiff/ox/nobool
Browse files Browse the repository at this point in the history
Bools have no tangent
  • Loading branch information
oxinabox authored Mar 1, 2024
2 parents 75e84bc + 4b2c810 commit 7730f38
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/tangent_types/abstract_zero.jl
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ In general, it is more likely to produce a structural tangent.
function zero_tangent end

zero_tangent(x::Number) = zero(x)
zero_tangent(x::Bool) = NoTangent()

function zero_tangent(x::MutableTangent{P}) where {P}
zb = backing(zero_tangent(backing(x)))
Expand Down Expand Up @@ -178,6 +179,8 @@ end

# Sad heauristic methods we need because of unassigned values
guess_zero_tangent_type(::Type{T}) where {T<:Number} = T
guess_zero_tangent_type(::Type{Bool}) = NoTangent()

guess_zero_tangent_type(::Type{T}) where {T<:Integer} = typeof(float(zero(T)))
function guess_zero_tangent_type(::Type{<:Array{T,N}}) where {T,N}
return Array{guess_zero_tangent_type(T),N}
Expand Down
2 changes: 2 additions & 0 deletions test/tangent_types/abstract_zero.jl
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ end
@testset "basics" begin
@test zero_tangent(1) === 0
@test zero_tangent(1.0) === 0.0
@test zero_tangent(true) === NoTangent()

mutable struct MutDemo
x::Float64
end
Expand Down

0 comments on commit 7730f38

Please sign in to comment.