def test_evaluate(self):
        """Test using the metric in the same way as Evalutor."""
        y_true = torch.tensor([[1, 0, 1, 0, 0, 1, 0, 0, 1, 1],
                               [0, 1, 0, 0, 1, 0, 1, 0, 0, 0]])
        y_pred = torch.tensor([np.linspace(0.95, 0.05, 10)] * 2)

        pred = [
            DataSample().set_pred_score(i).set_gt_score(j)
            for i, j in zip(y_pred, y_true)
        ]

        # Test with default macro avergae
        metric = METRICS.build(dict(type='RetrievalAveragePrecision', topk=10))
        metric.process([], pred)
        res = metric.evaluate(len(pred))
        self.assertIsInstance(res, dict)
        self.assertAlmostEqual(
            res['retrieval/mAP@10'], 53.25396825396825, places=4)

        # Test with invalid topk
        with self.assertRaisesRegex(ValueError, '`topk` must be a'):
            METRICS.build(dict(type='RetrievalAveragePrecision', topk=-1))

        # Test with invalid mode
        with self.assertRaisesRegex(AssertionError, 'Invalid `mode` '):
            METRICS.build(
                dict(type='RetrievalAveragePrecision', topk=5, mode='m'))
Test using the metric in the same way as Evalutor.
tests/test_evaluation/test_metrics/test_retrieval.py