code: def cdist_gak(
      dataset1,
      dataset2=None,
      sigma=1.0,
      n_jobs=None,
      verbose=0,
      be=None,
  ):
      r"""Compute cross-similarity matrix using Global Alignment kernel (GAK).
  
      GAK was originally presented in [1]_.
  
      Parameters
      ----------
      dataset1 : array-like, shape=(n_ts1, sz1, d) or (n_ts1, sz1) or (sz1,)
          A dataset of time series.
          If shape is (n_ts1, sz1), the dataset is composed of univariate time series.
          If shape is (sz1,), the dataset is composed of a unique univariate time series.
      dataset2 : None or array-like, shape=(n_ts2, sz2, d) or (n_ts2, sz2) or (sz2,) (default: None)
          Another dataset of time series.
          If `None`, self-similarity of `dataset1` is returned.
          If shape is (n_ts2, sz2), the dataset is composed of univariate time series.
          If shape is (sz2,), the dataset is composed of a unique univariate time series.
      sigma : float (default 1.)
          Bandwidth of the internal gaussian kernel used for GAK
      n_jobs : int or None, optional (default=None)
          The number of jobs to run in parallel.
          ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.
          ``-1`` means using all processors. See scikit-learns'
          `Glossary <https://scikit-learn.org/stable/glossary.html#term-n-jobs>`__
          for more details.
      verbose : int, optional (default=0)
          The verbosity level: if non zero, progress messages are printed.
          Above 50, the output is sent to stdout.
          The frequency of the messages increases with the verbosity level.
          If it more than 10, all iterations are reported.
          `Glossary <https://joblib.readthedocs.io/en/latest/parallel.html#parallel-reference-documentation>`__
          for more details.
      be : Backend object or string or None
          Backend. If `be` is an instance of the class `NumPyBackend` or the string `"numpy"`,
          the NumPy backend is used.
          If `be` is an instance of the class `PyTorchBackend` or the string `"pytorch"`,
          the PyTorch backend is used.
          If `be` is `None`, the backend is determined by the input arrays.
          See our :ref:`dedicated user-guide page <backend>` for more information.
  
      Returns
      -------
      array-like, shape=(n_ts1, n_ts2)
          Cross-similarity matrix.
  
      Examples
      --------
      >>> cdist_gak([[1, 2, 2, 3], [1., 2., 3., 4.]], sigma=2.)
      array([[1.        , 0.65629661],
             [0.65629661, 1.        ]])
      >>> cdist_gak([[1, 2, 2], [1., 2., 3., 4.]],
      ...           [[1, 2, 2, 3], [1., 2., 3., 4.], [1, 2, 2, 3]],
      ...           sigma=2.)
      array([[0.71059484, 0.29722877, 0.71059484],
             [0.65629661, 1.        , 0.65629661]])
  
      See Also
      --------
      gak : Compute Global Alignment kernel
  
      References
      ----------
      .. [1] M. Cuturi, "Fast global alignment kernels," ICML 2011.
      """  # noqa: E501
      be = instantiate_backend(be, dataset1, dataset2)
  
      unnormalized_matrix = _cdist_generic(
          dist_fun=unnormalized_gak,
          dataset1=dataset1,
          dataset2=dataset2,
          n_jobs=n_jobs,
          verbose=verbose,
          sigma=sigma,
          compute_diagonal=True,
          be=be,
      )
      dataset1 = to_time_series_dataset(dataset1, be=be)
      if dataset2 is None:
          diagonal = be.diag(
              be.sqrt(1.0 / be.diag(unnormalized_matrix))
          )
          diagonal_left = diagonal_right = diagonal
      else:
          dataset2 = to_time_series_dataset(dataset2, be=be)
          diagonal_left = Parallel(
              n_jobs=n_jobs, prefer="threads", verbose=verbose
          )(
              delayed(unnormalized_gak)(
                  dataset1[i], dataset1[i], sigma=sigma, be=be
              )
              for i in range(len(dataset1))
          )
          diagonal_right = Parallel(
              n_jobs=n_jobs, prefer="threads", verbose=verbose
          )(
              delayed(unnormalized_gak)(
                  dataset2[j], dataset2[j], sigma=sigma, be=be
              )
              for j in range(len(dataset2))
          )
          diagonal_left = be.diag(
              1.0 / be.sqrt(be.array(diagonal_left))
          )
          diagonal_right = be.diag(
              1.0 / be.sqrt(be.array(diagonal_right))
          )
      return diagonal_left @ unnormalized_matrix @ diagonal_right
  
imports: import numpy
  from joblib import Parallel, delayed
  from numba import njit
  from sklearn.utils import check_random_state
  from tslearn.backend import instantiate_backend
  from tslearn.utils import check_equal_size, to_time_series, to_time_series_dataset, ts_size
  from .dtw_variants import dtw, dtw_path
  from .soft_dtw_fast import _jacobian_product_sq_euc, _njit_jacobian_product_sq_euc, _njit_soft_dtw, _njit_soft_dtw_grad, _soft_dtw, _soft_dtw_grad
  from .utils import _cdist_generic
label_desc: Use image node_id 6 for calling a global function with example usage: cdist_gak(dataset1, dataset2, sigma, n_jobs, verbose, be) and returns: unknown