code: def test_kernel_density_sampling(n_samples=100, n_features=3):
      rng = np.random.RandomState(0)
      X = rng.randn(n_samples, n_features)
  
      bandwidth = 0.2
  
      for kernel in ["gaussian", "tophat"]:
          # draw a tophat sample
          kde = KernelDensity(bandwidth=bandwidth, kernel=kernel).fit(X)
          samp = kde.sample(100)
          assert X.shape == samp.shape
  
          # check that samples are in the right range
          nbrs = NearestNeighbors(n_neighbors=1).fit(X)
          dist, ind = nbrs.kneighbors(X, return_distance=True)
  
          if kernel == "tophat":
              assert np.all(dist < bandwidth)
          elif kernel == "gaussian":
              # 5 standard deviations is safe for 100 samples, but there's a
              # very small chance this test could fail.
              assert np.all(dist < 5 * bandwidth)
  
      # check unsupported kernels
      for kernel in ["epanechnikov", "exponential", "linear", "cosine"]:
          kde = KernelDensity(bandwidth=bandwidth, kernel=kernel).fit(X)
          with pytest.raises(NotImplementedError):
              kde.sample(100)
  
      # non-regression test: used to return a scalar
      X = rng.randn(4, 1)
      kde = KernelDensity(kernel="gaussian").fit(X)
      assert kde.sample().shape == (1, 1)
  
imports: import joblib
  import numpy
  import pytest
  from sklearn.datasets import make_blobs
  from sklearn.exceptions import NotFittedError
  from sklearn.model_selection import GridSearchCV
  from sklearn.neighbors import KDTree, KernelDensity, NearestNeighbors
  from sklearn.neighbors._ball_tree import kernel_norm
  from sklearn.pipeline import make_pipeline
  from sklearn.preprocessing import StandardScaler
  from sklearn.utils._testing import assert_allclose
label_desc: Use image node_id 4 for calling a global function with example usage: test_kernel_density_sampling(n_samples, n_features) without return types