code: def test_gaussian_kernel(gaussian_kernel_params):
      (
          sigma,
          n_features,
          n_instances,
          batch_size,
          trainable,
      ) = gaussian_kernel_params
  
      xshape, yshape = (n_instances[0], n_features), (
          n_instances[1],
          n_features,
      )
      if batch_size:
          xshape = (batch_size,) + xshape
          yshape = (batch_size,) + yshape
      sigma = (
          sigma if sigma is None else torch.from_numpy(sigma).float()
      )
      x = torch.from_numpy(np.random.random(xshape)).float()
      y = torch.from_numpy(np.random.random(yshape)).float()
      if batch_size:
          x_lazy, y_lazy = LazyTensor(x[:, :, None, :]), LazyTensor(
              y[:, None, :, :]
          )
          x_lazy2 = LazyTensor(x[:, None, :, :])
      else:
          x_lazy, y_lazy = LazyTensor(x[:, None, :]), LazyTensor(
              y[None, :, :]
          )
          x_lazy2 = LazyTensor(x[None, :, :])
  
      kernel = GaussianRBF(sigma=sigma, trainable=trainable)
      infer_sigma = True if sigma is None else False
      if trainable and infer_sigma:
          with pytest.raises(ValueError):
              kernel(x_lazy, y_lazy, infer_sigma=infer_sigma)
      else:
          k_xy = kernel(x_lazy, y_lazy, infer_sigma=infer_sigma)
          k_xx = kernel(x_lazy, x_lazy2, infer_sigma=infer_sigma)
          k_xy_shape = n_instances
          k_xx_shape = (n_instances[0], n_instances[0])
          axis = 1
          if batch_size:
              k_xy_shape = (batch_size,) + k_xy_shape
              k_xx_shape = (batch_size,) + k_xx_shape
              axis = 2
          assert k_xy.shape == k_xy_shape and k_xx.shape == k_xx_shape
          k_xx_argmax = k_xx.argmax(axis=axis)
          k_xx_min, k_xy_min = k_xx.min(axis=axis), k_xy.min(axis=axis)
          if batch_size:
              k_xx_argmax, k_xx_min, k_xy_min = (
                  k_xx_argmax[0],
                  k_xx_min[0],
                  k_xy_min[0],
              )
          assert (
              torch.arange(n_instances[0]) == k_xx_argmax.cpu().view(-1)
          ).all()
          assert (k_xx_min >= 0.0).all() and (k_xy_min >= 0.0).all()
  
file_path: alibi-detect/alibi_detect/utils/keops/tests/test_kernels_keops.py
imports: from itertools import product
  import numpy
  from alibi_detect.utils.frameworks import has_keops
  import pytest
  import torch
  import torch.nn
label_desc: Use image node_id 2 for calling a global function with example usage: test_gaussian_kernel(gaussian_kernel_params) without return types