code: def test_precision_score():
      """Test simulation metrics."""
      pytest.importorskip("sklearn")
      from sklearn.exceptions import UndefinedMetricWarning
  
      src = read_source_spaces(src_fname)
      vert1 = [src[0]["vertno"][0:2], []]
      vert2 = [src[0]["vertno"][1:3], []]
      vert3 = [src[0]["vertno"][0:1], []]
      data1 = np.ones((2, 2))
      data2 = np.ones((2, 2))
      data3 = np.array([[0.8, 1]])
      stc_true = SourceEstimate(
          data1, vert1, 0, 0.002, subject="sample"
      )
      stc_est1 = SourceEstimate(
          data2, vert2, 0, 0.002, subject="sample"
      )
      stc_est2 = SourceEstimate(
          data3, vert3, 0, 0.002, subject="sample"
      )
  
      E_unique1 = precision_score(stc_true, stc_est1, per_sample=False)
      E_unique2 = precision_score(stc_true, stc_est2, per_sample=False)
      with pytest.warns(
          UndefinedMetricWarning, match="no predicted samples"
      ):
          E_per_sample1 = precision_score(stc_true, stc_est2)
      E_per_sample2 = precision_score(
          stc_true, stc_est2, threshold="70%"
      )
      with pytest.raises(ValueError, match="0 and 1"):
          precision_score(stc_true, stc_est2, threshold=2)
  
      # ### Tests to add
      assert_allclose(E_unique1, 0.5)
      assert_allclose(E_unique2, 1.0)
      assert_allclose(E_per_sample1, [0.0, 1.0])
      assert_allclose(E_per_sample2, [1.0, 1.0])
  
file_path: mne-python/mne/simulation/metrics/tests/test_metrics.py
imports: import numpy
  import pytest
  from numpy.testing import assert_allclose
  from scipy.linalg import norm
  from mne import SourceEstimate, read_source_spaces
  from mne.datasets import testing
  from mne.simulation import metrics
  from mne.simulation.metrics import cosine_score, f1_score, peak_position_error, precision_score, recall_score, region_localization_error, roc_auc_score, spatial_deviation_error
label_desc: Use image node_id 4 for calling a global function with example usage: test_precision_score() without return types