Skip to content

Commit

Permalink
Bools have no tangent
Browse files Browse the repository at this point in the history
  • Loading branch information
oxinabox committed Feb 28, 2024
1 parent 75e84bc commit 4b2c810
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()

Check warning on line 182 in src/tangent_types/abstract_zero.jl

View check run for this annotation

Codecov / codecov/patch

src/tangent_types/abstract_zero.jl#L182

Added line #L182 was not covered by tests

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 4b2c810

Please sign in to comment.