code: def test_sparse_scikit_vs_scipy(global_random_seed):
      # Test scikit linkage with full connectivity (i.e. unstructured) vs scipy
      n, p, k = 10, 5, 3
      rng = np.random.RandomState(global_random_seed)
  
      # Not using a lil_matrix here, just to check that non sparse
      # matrices are well handled
      connectivity = np.ones((n, n))
      for linkage in _TREE_BUILDERS.keys():
          for i in range(5):
              X = 0.1 * rng.normal(size=(n, p))
              X -= 4.0 * np.arange(n)[:, np.newaxis]
              X -= X.mean(axis=1)[:, np.newaxis]
  
              out = hierarchy.linkage(X, method=linkage)
  
              children_ = out[:, :2].astype(int, copy=False)
              children, _, n_leaves, _ = _TREE_BUILDERS[linkage](
                  X, connectivity=connectivity
              )
  
              # Sort the order of child nodes per row for consistency
              children.sort(axis=1)
              assert_array_equal(
                  children,
                  children_,
                  "linkage tree differs from scipy impl for linkage: "
                  + linkage,
              )
  
              cut = _hc_cut(k, children, n_leaves)
              cut_ = _hc_cut(k, children_, n_leaves)
              assess_same_labelling(cut, cut_)
  
      # Test error management in _hc_cut
      with pytest.raises(ValueError):
          _hc_cut(n_leaves + 1, children, n_leaves)
  
imports: import itertools
  import shutil
  from functools import partial
  from tempfile import mkdtemp
  import numpy
  import pytest
  from scipy.cluster import hierarchy
  from scipy.sparse.csgraph import connected_components
  from sklearn.cluster import AgglomerativeClustering, FeatureAgglomeration, ward_tree
  from sklearn.cluster._agglomerative import _TREE_BUILDERS, _fix_connectivity, _hc_cut, linkage_tree
  from sklearn.cluster._hierarchical_fast import average_merge, max_merge, mst_linkage_core
  from sklearn.datasets import make_circles, make_moons
  from sklearn.feature_extraction.image import grid_to_graph
  from sklearn.metrics import DistanceMetric
  from sklearn.metrics.cluster import adjusted_rand_score, normalized_mutual_info_score
  from sklearn.metrics.pairwise import PAIRED_DISTANCES, cosine_distances, manhattan_distances, pairwise_distances
  from sklearn.metrics.tests.test_dist_metrics import METRICS_DEFAULT_PARAMS
  from sklearn.neighbors import kneighbors_graph
  from sklearn.utils._fast_dict import IntFloatDict
  from sklearn.utils._testing import assert_almost_equal, assert_array_almost_equal, assert_array_equal, create_memmap_backed_data, ignore_warnings
  from sklearn.utils.fixes import LIL_CONTAINERS
label_desc: Use image node_id 12 for calling a global function with example usage: test_sparse_scikit_vs_scipy(global_random_seed) without return types