Skip to content

Commit

Permalink
format self-refrential (squash me into prev)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
oxinabox and github-actions[bot] authored Jan 23, 2024
1 parent 465a733 commit f6e6bd8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/tangent_types/abstract_zero.jl
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ end
end
end

zero_tangent(primal::Tuple, _cache=nothing) = Tangent{typeof(primal)}(map(x->zero_tangent(x, _cache), primal)...)
function zero_tangent(primal::Tuple, _cache=nothing)
return Tangent{typeof(primal)}(map(x -> zero_tangent(x, _cache), primal)...)
end

function zero_tangent(x::Array{P,N}, _cache=nothing) where {P,N}
if (isbitstype(P) || all(i -> isassigned(x, i), eachindex(x)))
Expand All @@ -199,4 +201,6 @@ function guess_zero_tangent_type(::Type{<:Array{T,N}}) where {T,N}
end

# The following will fall back to `Any` if it is hard to infer
guess_zero_tangent_type(::Type{T}) where {T} = Core.Compiler.return_type(zero_tangent, Tuple{T})
function guess_zero_tangent_type(::Type{T}) where {T}
return Core.Compiler.return_type(zero_tangent, Tuple{T})
end
3 changes: 1 addition & 2 deletions test/tangent_types/abstract_zero.jl
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ end
Link(data) = new(data)
end

lk= Link(1.5)
lk = Link(1.5)
lk.next = lk

d = zero_tangent(lk)
Expand All @@ -305,7 +305,6 @@ end
@test_broken d_ca[1] == 0.0
@test_broken d_ca[2] === _ca


# Idea: check if typeof(xs) <: eltype(xs), if so need to cache it before computing
xs = Any[1.5]
push!(xs, xs)
Expand Down

0 comments on commit f6e6bd8

Please sign in to comment.