code: def _compute_distances_iterative(X, m, k):
      """Compute kNN indices with dot-product.
  
      No-loops implementation for a time series, given
      a window size and k neighbours.
  
      Parameters
      ----------
      X : array-like, shape [n]
          A single univariate time series of length n
      m : int
          The window size to generate sliding windows
      k : int
          The number of nearest neighbors
  
      Returns
      -------
      knns : array-like, shape = [n-m+1, k], dtype=int
          The knns (offsets!) for each subsequence in X
      """
      length = len(X) - m + 1
      knns = np.zeros(shape=(length, k), dtype=np.int64)
  
      dot_prev = None
      means, stds = _sliding_mean_std(X, m)
  
      for order in range(0, length):
          # first iteration O(n log n)
          if order == 0:
              # dot_first = _sliding_dot_product(X[:m], X)
              dot_first = _sliding_dot_products(
                  X[:m], X, len(X[:m]), len(X)
              )
              dot_rolled = dot_first
          # O(1) further operations
          else:
              dot_rolled = (
                  np.roll(dot_prev, 1)
                  + X[order + m - 1] * X[m - 1 : length + m]
                  - X[order - 1] * np.roll(X[:length], 1)
              )
              dot_rolled[0] = dot_first[order]
  
          x_mean = means[order]
          x_std = stds[order]
  
          dist = (
              2
              * m
              * (
                  1
                  - (dot_rolled - m * means * x_mean)
                  / (m * stds * x_std)
              )
          )
  
          # self-join: exclusion zone
          trivialMatchRange = (
              int(max(0, order - np.round(m / 2, 0))),
              int(min(order + np.round(m / 2 + 1, 0), length)),
          )
          dist[trivialMatchRange[0] : trivialMatchRange[1]] = np.inf
  
          _k = min(k, len(dist) - 1)
          idx = np.argpartition(dist, _k)
  
          knns[order, :] = idx[:k]
          dot_prev = dot_rolled
  
      return knns
  
file_path: sktime/sktime/transformations/series/_clasp_numba.py
imports: import numpy
  import pandas
  from sktime.transformations.panel.matrix_profile import _sliding_dot_products
  from sktime.utils.numba.njit import njit
label_desc: Use image node_id 3 for calling a global function with example usage: _compute_distances_iterative(X, m, k) and returns: knns