From 9ee2c69f27dce129019903a420f4709cdb0b20eb Mon Sep 17 00:00:00 2001 From: Michael Abbott <32575566+mcabbott@users.noreply.github.com> Date: Wed, 13 Mar 2024 11:55:12 -0400 Subject: [PATCH] disallow zero layers, let's try this out --- src/layers/basic.jl | 3 ++- test/layers/basic.jl | 7 ++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/layers/basic.jl b/src/layers/basic.jl index 3f57d628ca..a240a089f9 100644 --- a/src/layers/basic.jl +++ b/src/layers/basic.jl @@ -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 diff --git a/test/layers/basic.jl b/test/layers/basic.jl index d09579c257..8e33340611 100644 --- a/test/layers/basic.jl +++ b/test/layers/basic.jl @@ -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