Repository: Lightning-AI/torchmetrics

Issue:
AUPRC `sample_weights` supported, but not used
## 🐛 Bug

The [AUPRC](https://torchmetrics.readthedocs.io/en/stable/classification/average_precision.html?highlight=average_precisionv) metric supports the `sample_weights` argument, but it is [never used](https://github.com/Lightning-AI/metrics/blob/master/src/torchmetrics/functional/classification/average_precision.py#L93). Using the `sample_weights` argument won't throw any error, nor does its documentation mention that its not yet actually supported. I think this is a silent bug that can cause confusion or invalidate results without people realizing it. 

### To Reproduce

#### Code sample
```python
import torch
from torchmetrics.functional import average_precision

pred = torch.tensor([1, 1, 0, 0])
target = torch.tensor([1, 0, 1, 0])
weights = torch.tensor([1, 0, 0, 0])

average_precision(pred, target)
# Returns: tensor(0.5000)

average_precision(pred, target, sample_weights=weights)
# Returns: tensor(0.5000)

```

Now if we compare this to [the implementation in Scikit-learn](https://scikit-learn.org/stable/modules/generated/sklearn.metrics.average_precision_score.html?highlight=average_precision#sklearn.metrics.average_precision_score):
```python
import numpy as np
from sklearn.metrics import average_precision_score 

pred = np.array([1, 1, 0, 0])
target = np.array([1, 0, 1, 0])
weights = np.array([1, 0, 0, 0])

average_precision_score(pred, target)
# Returns: 0.5

average_precision_score(pred, target, sample_weights=weights)
# Returns: 1.0
```

<!-- Ideally attach a minimal code sample to reproduce the decried issue.
Minimal means having the shortest code but still preserving the bug. -->

### Expected behavior
I would expect a `NotImplementedError` to be thrown and the documentation to mention that it is not yet supported. 

### Environment

- TorchMetrics version (and how you installed TM, e.g. `conda`, `pip`, build from source): 
  - Version 0.9.1
  - Installed with `mamba`
  
- Python & PyTorch Version (e.g., 1.0): 
  - Python: 3.9.13
  - PyTorch: 1.11.0.post202
  
- Any other relevant information such as OS (e.g., Linux):
  - I am on Ubuntu, Linux. 




Discussion:
Hi! thanks for your contribution!, great first issue!
I would be happy to open a PR with my proposed fix once it is confirmed that this is indeed a bug.
Hi @cwognum, 
That is indeed a bug. I would say that the simple solution is to simply remove the argument completely.
We can always re-introduce it if we decide to support the feature in the future.
That's a good point! Happy to propose this fix later today! 

Resolving patch:
diff --git a/src/torchmetrics/functional/classification/average_precision.py b/src/torchmetrics/functional/classification/average_precision.py
--- a/src/torchmetrics/functional/classification/average_precision.py
+++ b/src/torchmetrics/functional/classification/average_precision.py
@@ -12,7 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 import warnings
-from typing import List, Optional, Sequence, Tuple, Union
+from typing import List, Optional, Tuple, Union
 
 import torch
 from torch import Tensor
@@ -55,7 +55,6 @@ def _average_precision_compute(
     num_classes: int,
     pos_label: Optional[int] = None,
     average: Optional[str] = "macro",
-    sample_weights: Optional[Sequence] = None,
 ) -> Union[List[Tensor], Tensor]:
     """Computes the average precision score.
 
@@ -67,7 +66,6 @@ def _average_precision_compute(
             to 1. For multiclass problems his argument should not be set as we iteratively change it in the
             range ``[0, num_classes-1]``
         average: reduction method for multi-class or multi-label problems
-        sample_weights: sample weights for each data point
 
     Example:
         >>> # binary case
@@ -90,7 +88,6 @@ def _average_precision_compute(
         [tensor(1.), tensor(1.), tensor(0.2500), tensor(0.2500), tensor(nan)]
     """
 
-    # todo: `sample_weights` is unused
     if average == "micro" and preds.ndim == target.ndim:
         preds = preds.flatten()
         target = target.flatten()
@@ -182,7 +179,6 @@ def average_precision(
     num_classes: Optional[int] = None,
     pos_label: Optional[int] = None,
     average: Optional[str] = "macro",
-    sample_weights: Optional[Sequence] = None,
 ) -> Union[List[Tensor], Tensor]:
     """Computes the average precision score.
 
@@ -207,8 +203,6 @@ def average_precision(
             - ``'none'`` or ``None``: Calculate the metric for each class separately, and return
               the metric for every class.
 
-        sample_weights: sample weights for each data point
-
     Returns:
         tensor with average precision. If multiclass will return list
         of such tensors, one for each class
@@ -229,6 +223,5 @@ def average_precision(
         >>> average_precision(pred, target, num_classes=5, average=None)
         [tensor(1.), tensor(1.), tensor(0.2500), tensor(0.2500), tensor(nan)]
     """
-    # fixme: `sample_weights` is unused
     preds, target, num_classes, pos_label = _average_precision_update(preds, target, num_classes, pos_label, average)
-    return _average_precision_compute(preds, target, num_classes, pos_label, average, sample_weights)
+    return _average_precision_compute(preds, target, num_classes, pos_label, average)


Test patch: