@@ -250,6 +250,44 @@ def test_trainable_parameter_variants(self) -> None:
250250 self .assertTrue (net_mixed .layers [0 ].trainable )
251251 self .assertFalse (net_mixed .layers [1 ].trainable )
252252
253+ def test_empty_layers_round_trip (self ) -> None :
254+ """Test EmbeddingNet with empty neuron list (edge case for deserialize).
255+
256+ This tests the fix for IndexError when neuron=[] results in empty layers.
257+ The deserialize method should handle this case without trying to access
258+ layers[0] when the list is empty.
259+ """
260+ in_dim = 4
261+ neuron = [] # Empty neuron list
262+
263+ # Create network with empty layers
264+ net = EmbeddingNet (
265+ in_dim = in_dim ,
266+ neuron = neuron ,
267+ activation_function = "tanh" ,
268+ resnet_dt = True ,
269+ precision = "float64" ,
270+ )
271+
272+ # Verify it has no layers
273+ self .assertEqual (len (net .layers ), 0 )
274+
275+ # Serialize and deserialize
276+ serialized = net .serialize ()
277+ net_restored = EmbeddingNet .deserialize (serialized )
278+
279+ # Verify restored network also has no layers
280+ self .assertEqual (len (net_restored .layers ), 0 )
281+ self .assertEqual (net_restored .in_dim , in_dim )
282+ self .assertEqual (net_restored .neuron , neuron )
283+
284+ # Verify forward pass works (should return input unchanged)
285+ rng = np .random .default_rng ()
286+ x = rng .standard_normal ((5 , in_dim ))
287+ out = net_restored .call (x )
288+ # With no layers, output should equal input
289+ np .testing .assert_allclose (out , x )
290+
253291
254292class TestFittingNet (unittest .TestCase ):
255293 def test_fitting_net (self ) -> None :
0 commit comments