Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for forward method #48

Merged
merged 2 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/generics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,21 @@ end
function (rlayer::AbstractRecurrentLayer{false})(inp::AbstractArray,
state::Union{AbstractVecOrMat, Tuple{AbstractVecOrMat, AbstractVecOrMat}})
@assert ndims(inp) == 2 || ndims(inp) == 3
@assert typeof(state)==typeof(initialstates(rlayer)) """\n
The layer $rlayer is calling states not supported by its
forward method. Check if this is a single or double return
recurrent layer, and adjust your inputs accordingly.
"""
return first(scan(rlayer.cell, inp, state))
end

function (rlayer::AbstractRecurrentLayer{true})(inp::AbstractArray,
state::Union{AbstractVecOrMat, Tuple{AbstractVecOrMat, AbstractVecOrMat}})
@assert ndims(inp) == 2 || ndims(inp) == 3
@assert typeof(state)==typeof(initialstates(rlayer)) """\n
The layer $rlayer is calling states not supported by its
forward method. Check if this is a single or double return
recurrent layer, and adjust your inputs accordingly.
"""
return scan(rlayer.cell, inp, state)
end
4 changes: 3 additions & 1 deletion src/wrappers/stackedrnn.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ function StackedRNN(rlayer, (input_size, hidden_size)::Pair{<:Int, <:Int}, args.
end

function (stackedrnn::StackedRNN)(inp::AbstractArray)
@assert length(stackedrnn.layers)==length(stackedrnn.states) "Mismatch in layers vs. states length!"
@assert length(stackedrnn.layers)==length(stackedrnn.states) """\n
Mismatch in layers vs. states length!
"""
@assert !isempty(stackedrnn.layers) "StackedRNN has no layers!"
for idx in eachindex(stackedrnn.layers)
inp = stackedrnn.layers[idx](inp, stackedrnn.states[idx])
Expand Down
Loading