code: def test_singular_array_init_or_prior_strictpd(
      estimator, build_dataset, w0
  ):
      """Tests that when using a custom array init (or prior), it returns the
      appropriate error if it is singular, for algorithms
      that need a strictly PD prior or init (see
      https://github.com/scikit-learn-contrib/metric-learn/issues/202 and
      https://github.com/scikit-learn-contrib/metric-learn/pull/195#issuecomment
      -492332451)
      """
      matrices_to_set = []
      if hasattr(estimator, "init"):
          matrices_to_set.append("init")
      if hasattr(estimator, "prior"):
          matrices_to_set.append("prior")
  
      rng = np.random.RandomState(42)
      input_data, labels, _, X = build_dataset()
      for param in matrices_to_set:
          model = clone(estimator)
          set_random_state(model)
  
          P = ortho_group.rvs(X.shape[1], random_state=rng)
          w = np.abs(rng.randn(X.shape[1]))
          w[0] = w0
          M = P.dot(np.diag(w)).dot(P.T)
          if hasattr(model, "init"):
              model.set_params(init=M)
          if hasattr(model, "prior"):
              model.set_params(prior=M)
          if not hasattr(model, "prior") and not hasattr(model, "init"):
              raise RuntimeError(
                  "Neither prior or init could be set in the model."
              )
          msg = (
              "You should provide a strictly positive definite "
              "matrix as `{}`. This one is not definite. Try another"
              " {}, or an algorithm that does not "
              "require the {} to be strictly positive definite.".format(
                  *(param,) * 3
              )
          )
          with pytest.raises(LinAlgError) as raised_err:
              model.fit(input_data, labels)
          assert str(raised_err.value) == msg
  
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 21 for calling a global function with example usage: test_singular_array_init_or_prior_strictpd(estimator, build_dataset, w0) without return types