Repository: Lightning-AI/torchmetrics

Issue:
ClasswiseWrapper yields different results 
## 🐛 Bug

Using `JaccardIndex` with  `ClasswiseWrapper` results in different values than without `ClasswiseWrapper`. 

### To Reproduce

Steps to reproduce the behavior...

Run the code snippet. 

#### Code sample

```python
from torchmetrics import ClasswiseWrapper, JaccardIndex
import torch 

target = torch.randint(0, 2, (10, 25, 25))
preds = [ torch.randint(0, 2, (10, 25, 25)) for i in range (3)]
jaccard_single = JaccardIndex(num_classes=2, average=None)
class_wrapper = ClasswiseWrapper(
        JaccardIndex(num_classes=2, average=None),
        labels=["class1", "class2"]
    )

for p in preds:
    print("Metric ",jaccard_single(p,target))    
    print("Wraped metric ",class_wrapper(p,target))
```

The code produces the following output: 

```
Metric  tensor([0.3351, 0.3333])
Wraped metric  {'jaccardindex_class1': tensor(0.3351), 'jaccardindex_class2': tensor(0.3333)}
Metric  tensor([0.3293, 0.3357])
Wraped metric  {'jaccardindex_class1': tensor(0.3322), 'jaccardindex_class2': tensor(0.3345)}
Metric  tensor([0.3424, 0.3435])
Wraped metric  {'jaccardindex_class1': tensor(0.3356), 'jaccardindex_class2': tensor(0.3375)}
```

### Expected behavior

I would expect that the wrapped metric outputs the same values as the simple `JaccardIndex`. 

### Environment

- TorchMetrics version (and how you installed TM, e.g. `conda`, `pip`, build from source): 
 Installed version 0.9.2 using pip 
- Python & PyTorch Version (e.g., 1.0):
 Tested with Python 3.8.14 and pytorch 1.3.1
- Any other relevant information such as OS (e.g., Linux):

### Additional context

<!-- Add any other context about the problem here. -->



Discussion:
Hi! thanks for your contribution!, great first issue!

Resolving patch:
diff --git a/src/torchmetrics/wrappers/classwise.py b/src/torchmetrics/wrappers/classwise.py
--- a/src/torchmetrics/wrappers/classwise.py
+++ b/src/torchmetrics/wrappers/classwise.py
@@ -51,6 +51,8 @@ class ClasswiseWrapper(Metric):
         'recall_horse': tensor(0.), 'recall_fish': tensor(0.3333), 'recall_dog': tensor(0.4000)}
     """
 
+    full_state_update: Optional[bool] = True
+
     def __init__(self, metric: Metric, labels: Optional[List[str]] = None) -> None:
         super().__init__()
         if not isinstance(metric, Metric):
@@ -71,3 +73,6 @@ def update(self, *args: Any, **kwargs: Any) -> None:
 
     def compute(self) -> Dict[str, Tensor]:
         return self._convert(self.metric.compute())
+
+    def reset(self) -> None:
+        self.metric.reset()


Test patch:
diff --git a/tests/unittests/wrappers/test_classwise.py b/tests/unittests/wrappers/test_classwise.py
--- a/tests/unittests/wrappers/test_classwise.py
+++ b/tests/unittests/wrappers/test_classwise.py
@@ -15,27 +15,35 @@ def test_raises_error_on_wrong_input():
 
 def test_output_no_labels():
     """Test that wrapper works with no label input."""
+    base = Accuracy(num_classes=3, average=None)
     metric = ClasswiseWrapper(Accuracy(num_classes=3, average=None))
-    preds = torch.randn(10, 3).softmax(dim=-1)
-    target = torch.randint(3, (10,))
-    val = metric(preds, target)
-    assert isinstance(val, dict)
-    assert len(val) == 3
-    for i in range(3):
-        assert f"accuracy_{i}" in val
+    for _ in range(2):
+        preds = torch.randn(10, 3).softmax(dim=-1)
+        target = torch.randint(3, (10,))
+        val = metric(preds, target)
+        val_base = base(preds, target)
+        assert isinstance(val, dict)
+        assert len(val) == 3
+        for i in range(3):
+            assert f"accuracy_{i}" in val
+            assert val[f"accuracy_{i}"] == val_base[i]
 
 
 def test_output_with_labels():
     """Test that wrapper works with label input."""
     labels = ["horse", "fish", "cat"]
+    base = Accuracy(num_classes=3, average=None)
     metric = ClasswiseWrapper(Accuracy(num_classes=3, average=None), labels=labels)
-    preds = torch.randn(10, 3).softmax(dim=-1)
-    target = torch.randint(3, (10,))
-    val = metric(preds, target)
-    assert isinstance(val, dict)
-    assert len(val) == 3
-    for lab in labels:
-        assert f"accuracy_{lab}" in val
+    for _ in range(2):
+        preds = torch.randn(10, 3).softmax(dim=-1)
+        target = torch.randint(3, (10,))
+        val = metric(preds, target)
+        val_base = base(preds, target)
+        assert isinstance(val, dict)
+        assert len(val) == 3
+        for i, lab in enumerate(labels):
+            assert f"accuracy_{lab}" in val
+            assert val[f"accuracy_{lab}"] == val_base[i]
 
 
 @pytest.mark.parametrize("prefix", [None, "pre_"])