From 288f8d50bae7fb193c070d0e1f57a9567dbd3106 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 a8cb0a9d1c..3c615ae06d 100644 --- a/src/layers/basic.jl +++ b/src/layers/basic.jl @@ -562,9 +562,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