code: def test_sample(dataset, seed):
      """Test sampling reconstruction."""
  
      # Unpack dataset.
      X = dataset["X_train"]
      feature_names = dataset["metadata"]["feature_names"]
      category_map = dataset["metadata"].get("category_map", {})
  
      # Get heterogeneous preprocessor.
      preprocessor, inv_preprocessor = get_he_preprocessor(
          X=X, feature_names=feature_names, category_map=category_map
      )
  
      # Preprocess dataset.
      X_ohe = preprocessor(X)
      X_ohe_split_num, X_ohe_split_cat = split_ohe(
          X_ohe=X_ohe, category_map=category_map
      )
      X_ohe_split = X_ohe_split_num + X_ohe_split_cat
  
      # Compute dataset statistics.
      stats = get_statistics(
          X=X, preprocessor=preprocessor, category_map=category_map
      )
  
      # Define numerical ranges.
      ranges = {}
      for i, fn in enumerate(feature_names):
          if i not in category_map:
              ranges[fn] = [-np.random.rand(), np.random.rand()]
  
      # Define list of immutable attributes.
      np.random.seed(seed)
      immutable_attributes = np.random.choice(
          feature_names,
          size=np.random.randint(low=0, high=len(feature_names)),
      )
  
      # Generate conditional vector.
      C = get_conditional_vector(
          X=X,
          condition={},
          preprocessor=preprocessor,
          feature_names=feature_names,
          category_map=category_map,
          stats=stats,
          ranges=ranges,
          immutable_features=immutable_attributes,
      )
  
      # Generate some random reconstruction
      X_hat = np.random.randn(*X_ohe.shape)
      X_hat_split_num, X_hat_split_cat = split_ohe(
          X_ohe=X_hat, category_map=category_map
      )
      X_hat_split = X_hat_split_num + X_hat_split_cat
  
      # Sample reconstruction.
      X_hat_ohe_split = sample(
          X_hat_split=X_hat_split,
          X_ohe=X_ohe,
          C=C,
          category_map=category_map,
          stats=stats,
      )
  
      # Check that all sampled categorical features are one-hot encoded.
      offset = 1 if len(feature_names) > len(category_map) else 0
      for i in range(offset, len(X_ohe_split)):
          assert np.all(np.sum(X_hat_ohe_split[i], axis=1) == 1)
  
      # Check that the immutable features did not change.
      X_hat = inv_preprocessor(np.concatenate(X_hat_ohe_split, axis=1))
      for i, fn in enumerate(feature_names):
          if fn in immutable_attributes:
              assert_allclose(
                  X[:, i].astype(np.float32),
                  X_hat[:, i].astype(np.float32),
              )
  
imports: from typing import Union, List
  import pytest
  from pytest_lazyfixture import lazy_fixture
  import numpy
  from numpy.testing import assert_allclose
  import tensorflow
  import tensorflow.keras
  from alibi.explainers import CounterfactualRLTabular
  from alibi.explainers.backends.cfrl_base import get_hard_distribution
  from alibi.explainers.backends.cfrl_tabular import get_he_preprocessor, split_ohe, get_numerical_conditional_vector, get_categorical_conditional_vector, get_statistics, get_conditional_vector, sample
label_desc: Use image node_id 5 for calling a global function with example usage: test_sample(dataset, seed) without return types