Skip to content

Commit

Permalink
Merge pull request #12 from JuliaGNI/chain_for_named_tuples
Browse files Browse the repository at this point in the history
Added an option to call a chain with a NamedTuple.
  • Loading branch information
michakraus authored Nov 21, 2023
2 parents ea6113d + 51d4094 commit 070bba2
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/chain.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Base.iterate(c::Chain, i=1) = i > length(c) ? nothing : (layer(c, i), i+1)
Base.eachindex(c::Chain) = 1:length(c)


@generated function applychain(layers::Tuple, x::AbstractArray, ps::Tuple)
@generated function applychain(layers::Tuple, x::Union{AbstractArray, NamedTuple{(:q, :p), Tuple{AT, AT}}}, ps::Tuple) where AT<:AbstractArray
N = length(fieldtypes((layers)))
x_symbols = vcat([:x], [gensym() for _ in 1:N])
calls = [:(($(x_symbols[i + 1])) = layers[$i]($(x_symbols[i]), ps[$i])) for i in 1:N]
Expand Down

0 comments on commit 070bba2

Please sign in to comment.