Skip to content

Commit

Permalink
handling type-known empty containers in zero_tangent
Browse files Browse the repository at this point in the history
  • Loading branch information
oxinabox authored Feb 13, 2024
1 parent 2387dc1 commit 9c8c812
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/tangent_types/abstract_zero.jl
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ end
function zero_tangent(::T) where {K,V,T<:AbstractDict{K,V}}
return Tangent{T}(Dict{K,guess_zero_tangent_type(V)}())
end
zero_tangent(::Base.Pairs{Symbol, Union{}, Tuple{}, @NamedTuple{}}) = NoTangent()


# Sad heauristic methods we need because of unassigned values
guess_zero_tangent_type(::Type{T}) where {T<:Number} = T
Expand All @@ -180,6 +182,9 @@ function guess_zero_tangent_type(::Type{<:Array{T,N}}) where {T,N}
return Array{guess_zero_tangent_type(T),N}
end
guess_zero_tangent_type(T::Type) = Any
guess_zero_tangent_type(::Union{}) = Union{} # This will only show up for empty containers



# Stuff that conceptually has its own identity regardless of structual implementation and doesn't have a tangent
zero_tangent(::Base.AbstractLogger) = NoTangent()
Expand All @@ -190,4 +195,4 @@ zero_tangent(::Expr) = NoTangent()
zero_tangent(::Core.Compiler.AbstractInterpreter) = NoTangent()
zero_tangent(::Core.Compiler.InstructionStream) = NoTangent()
zero_tangent(::Core.CodeInfo) = NoTangent()
zero_tangent(::Core.MethodInstance) = NoTangent()
zero_tangent(::Core.MethodInstance) = NoTangent()

0 comments on commit 9c8c812

Please sign in to comment.