Skip to content

Commit

Permalink
Fix performance
Browse files Browse the repository at this point in the history
  • Loading branch information
willtebbutt committed Dec 17, 2024
1 parent f22068b commit 824acd0
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/fwds_rvs_data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -238,20 +238,20 @@ end
Extract the forwards data from tangent `t`.
"""
@generated function fdata(t::T) where {T}
function fdata(t::T) where {T}

# Ask for the forwards-data type. Useful catch-all error checking for unexpected types.
F = fdata_type(T)

# Catch-all for anything with no forwards-data.
F == NoFData && return :(NoFData())
F == NoFData && return NoFData()

# Catch-all for anything where we return the whole object (mutable structs, arrays...).
F == T && return :(t)
F == T && return t

# T must be a `Tangent` by now. If it's not, something has gone wrong.
!(T <: Tangent) && return :(error("Unhandled type $T"))
return :($F(fdata(t.fields)))
T <: Tangent || error("Unhandled type $T")
return F(fdata(t.fields))
end

function fdata(t::T) where {T<:PossiblyUninitTangent}
Expand Down Expand Up @@ -493,20 +493,20 @@ Extract the reverse data from tangent `t`.
See extended help section of [fdata_type](@ref).
"""
@generated function rdata(t::T) where {T}
function rdata(t::T) where {T}

# Ask for the reverse-data type. Useful catch-all error checking for unexpected types.
R = rdata_type(T)

# Catch-all for anything with no reverse-data.
R == NoRData && return :(NoRData())
R == NoRData && return NoRData()

# Catch-all for anything where we return the whole object (Float64, isbits structs, ...)
R == T && return :(t)
R == T && return t

# T must be a `Tangent` by now. If it's not, something has gone wrong.
!(T <: Tangent) && return :(error("Unhandled type $T"))
return :($(rdata_type(T))(rdata(t.fields)))
T <: Tangent || error("Unhandled type $T")
return R(rdata(t.fields))
end

function rdata(t::T) where {T<:PossiblyUninitTangent}
Expand Down

0 comments on commit 824acd0

Please sign in to comment.