code: def test_sample_differentiable(dataset, backend):
      SIZE = 100
      feature_names = dataset["metadata"]["feature_names"]
      category_map = dataset["metadata"].get("category_map", {})
  
      # define number of numerical
      num_features = len(feature_names) - len(category_map)
  
      # define random autoencoder reconstruction
      X_hat_split = []
  
      # generate numerical feature reconstruction
      X_hat_split.append(
          np.random.randn(SIZE, num_features).astype(np.float32)
      )
  
      # for each categorical feature generate random reconstruction
      for cat_col in category_map:
          X_hat_split.append(
              np.random.rand(SIZE, len(category_map[cat_col])).astype(
                  np.float32
              )
          )
  
      if backend == "tensorflow":
          from alibi.explainers.backends.tensorflow.cfrl_base import (
              to_tensor,
              to_numpy,
          )
          from alibi.explainers.backends.tensorflow.cfrl_tabular import (
              sample_differentiable,
          )
  
          device = None
      else:
          import torch
          from alibi.explainers.backends.pytorch.cfrl_base import (
              to_tensor,
              to_numpy,
          )
          from alibi.explainers.backends.pytorch.cfrl_tabular import (
              sample_differentiable,
          )
  
          device = torch.device("cpu")
  
      for i in range(len(X_hat_split)):
          X_hat_split[i] = to_tensor(X_hat_split[i], device=device)
  
      # sample output differentiable
      X_ohe_split = sample_differentiable(X_hat_split, category_map)
  
      # convert back to numpy arrays
      X_ohe_split = to_numpy(X_ohe_split)
      X_hat_split = to_numpy(X_hat_split)
  
      # check if the numerical feature are unchanged
      assert_allclose(X_ohe_split[0], X_hat_split[0])
  
      # check the categorical ones
      for i in range(1, len(X_ohe_split)):
          assert np.all(
              np.argmax(X_ohe_split[i], axis=1)
              == np.argmax(X_hat_split[i], axis=1)
          )
          assert np.all(
              X_ohe_split[i][
                  np.arange(SIZE), np.argmax(X_ohe_split[i], axis=1)
              ]
              == 1
          )
          assert np.all(np.sum(X_ohe_split[i], axis=1) == 1)
  
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 9 for calling a global function with example usage: test_sample_differentiable(dataset, backend) without return types