code: def test_pair_distance_pairwise(estimator, build_dataset):
      # Computing pairwise scores should return a euclidean distance matrix.
      input_data, labels, _, X = build_dataset()
      n_samples = 20
      X = X[:n_samples]
      model = clone(estimator)
      set_random_state(model)
      model.fit(*remove_y(estimator, input_data, labels))
  
      pairwise = model.pair_distance(
          np.array(list(product(X, X)))
      ).reshape(n_samples, n_samples)
  
      check_is_distance_matrix(pairwise)
  
      # a necessary condition for euclidean distance matrices: (see
      # https://en.wikipedia.org/wiki/Euclidean_distance_matrix)
      assert np.linalg.matrix_rank(pairwise**2) <= min(X.shape) + 2
  
      # assert that this distance is coherent with pdist on embeddings
      assert_array_almost_equal(
          squareform(pairwise), pdist(model.transform(X))
      )
  
imports: from itertools import product
  import pytest
  import numpy
  from numpy.linalg import LinAlgError
  from numpy.testing import assert_array_almost_equal, assert_allclose, assert_array_equal
  from scipy.spatial.distance import pdist, squareform, mahalanobis
  from scipy.stats import ortho_group
  from sklearn import clone
  from sklearn.cluster import DBSCAN
  from sklearn.datasets import make_spd_matrix, make_blobs
  from sklearn.utils import check_random_state, shuffle
  from sklearn.utils.multiclass import type_of_target
  from metric_learn.sklearn_shims import set_random_state
  from metric_learn._util import make_context, _initialize_metric_mahalanobis
  from metric_learn.sdml import _BaseSDML
  from metric_learn.base_metric import _QuadrupletsClassifierMixin, _TripletsClassifierMixin, _PairsClassifierMixin
  from metric_learn.exceptions import NonPSDError
  from test.test_utils import ids_metric_learners, metric_learners, remove_y, ids_classifiers
label_desc: Use image node_id 2 for calling a global function with example usage: test_pair_distance_pairwise(estimator, build_dataset) without return types