@@ -229,6 +229,11 @@ def compute_fn(y_preds, y_targets):
229229 assert isinstance (result , torch .Tensor )
230230 assert result .shape == (3 ,)
231231
232+ preds = torch .cat ([output1 [0 ], output2 [0 ]], dim = 0 )
233+ targets = torch .cat ([output1 [1 ], output2 [1 ]], dim = 0 )
234+ expected = compute_fn (preds , targets )
235+ assert torch .allclose (result , expected )
236+
232237
233238def test_epoch_metric_compute_fn_tuple_output ():
234239 """Test EpochMetric with compute_fn returning a tuple of tensors."""
@@ -249,6 +254,12 @@ def compute_fn(y_preds, y_targets):
249254 assert isinstance (result , tuple )
250255 assert len (result ) == 2
251256
257+ preds = torch .cat ([output1 [0 ], output2 [0 ]], dim = 0 )
258+ targets = torch .cat ([output1 [1 ], output2 [1 ]], dim = 0 )
259+ expected = compute_fn (preds , targets )
260+ assert torch .allclose (result [0 ], expected [0 ])
261+ assert torch .allclose (result [1 ], expected [1 ])
262+
252263
253264def test_epoch_metric_compute_fn_invalid_output ():
254265 """Test EpochMetric raises TypeError for unsupported compute_fn output."""
@@ -278,11 +289,19 @@ def compute_fn(y_preds, y_targets):
278289 em .reset ()
279290 output1 = (torch .rand (4 , 3 ), torch .randint (0 , 2 , size = (4 , 3 ), dtype = torch .long ))
280291 em .update (output1 )
292+ output2 = (torch .rand (4 , 3 ), torch .randint (0 , 2 , size = (4 , 3 ), dtype = torch .long ))
293+ em .update (output2 )
281294
282295 result = em .compute ()
283296 assert isinstance (result , list )
284297 assert len (result ) == 2
285298
299+ preds = torch .cat ([output1 [0 ], output2 [0 ]], dim = 0 )
300+ targets = torch .cat ([output1 [1 ], output2 [1 ]], dim = 0 )
301+ expected = compute_fn (preds , targets )
302+ assert torch .allclose (result [0 ], expected [0 ])
303+ assert torch .allclose (result [1 ], expected [1 ])
304+
286305
287306def test_epoch_metric_compute_fn_dict_output ():
288307 """Test EpochMetric with compute_fn returning a dict of tensors."""
@@ -297,8 +316,16 @@ def compute_fn(y_preds, y_targets):
297316 em .reset ()
298317 output1 = (torch .rand (4 , 3 ), torch .randint (0 , 2 , size = (4 , 3 ), dtype = torch .long ))
299318 em .update (output1 )
319+ output2 = (torch .rand (4 , 3 ), torch .randint (0 , 2 , size = (4 , 3 ), dtype = torch .long ))
320+ em .update (output2 )
300321
301322 result = em .compute ()
302323 assert isinstance (result , dict )
303324 assert "mse" in result
304- assert "mae" in result
325+ assert "mae" in result
326+
327+ preds = torch .cat ([output1 [0 ], output2 [0 ]], dim = 0 )
328+ targets = torch .cat ([output1 [1 ], output2 [1 ]], dim = 0 )
329+ expected = compute_fn (preds , targets )
330+ assert torch .allclose (result ["mse" ], expected ["mse" ])
331+ assert torch .allclose (result ["mae" ], expected ["mae" ])
0 commit comments