Skip to content

Commit

Permalink
disallow zero layers, let's try this out
Browse files Browse the repository at this point in the history
  • Loading branch information
mcabbott committed Mar 13, 2024
1 parent 86cc7a4 commit 0544711
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/layers/basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -558,9 +558,10 @@ function Parallel(connection; kw...)
if :layers in keys(layers) || :connection in keys(layers)
throw(ArgumentError("a Parallel layer cannot have a named sub-layer called `connection` or `layers`"))
end
isempty(layers) && return Parallel(connection, ())
Parallel(connection, layers)
end
Parallel(connection, layers::Union{Tuple{}, @NamedTuple{}}) =
throw(ArgumentError("cannot construct a Parallel layer with no sub-layers"))

@layer :expand Parallel

Expand Down
7 changes: 2 additions & 5 deletions test/layers/basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,8 @@ using Flux: activations
@test_throws ArgumentError Parallel(hcat, inv)()
@test_throws ArgumentError Parallel(hcat, inv, sqrt)()

# zero layers -- not useful... can we make this an error without a breaking change?
@test Parallel(hcat) isa Parallel{typeof(hcat), Tuple{}} # not a NamedTuple
@test Parallel(hcat)(1) == hcat()

@test Parallel(hcat, inv)(2) == hcat(1/2) # still calls connection once.
# zero layers -- not useful... now made an error
@test_throws ArgumentError Parallel(hcat)
end

@testset "connection is called once" begin
Expand Down

0 comments on commit 0544711

Please sign in to comment.