From 4b2c810df590501995948259682e5e8feee95f9c Mon Sep 17 00:00:00 2001 From: Frames White Date: Wed, 28 Feb 2024 08:54:06 +0800 Subject: [PATCH] Bools have no tangent --- src/tangent_types/abstract_zero.jl | 3 +++ test/tangent_types/abstract_zero.jl | 2 ++ 2 files changed, 5 insertions(+) diff --git a/src/tangent_types/abstract_zero.jl b/src/tangent_types/abstract_zero.jl index 30bdba54f..a78e949dc 100644 --- a/src/tangent_types/abstract_zero.jl +++ b/src/tangent_types/abstract_zero.jl @@ -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))) @@ -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} diff --git a/test/tangent_types/abstract_zero.jl b/test/tangent_types/abstract_zero.jl index b7d2eba5c..7da7cfadc 100644 --- a/test/tangent_types/abstract_zero.jl +++ b/test/tangent_types/abstract_zero.jl @@ -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