code: def slidingDotProduct(query, ts):
      """
      Calculate the dot product between a query and all subsequences of length(query) in the timeseries ts. Note that we use Numpy's rfft method instead of fft.
  
      Parameters
      ----------
      query: Specific time series query to evaluate.
      ts: Time series to calculate the query's sliding dot product against.
      """
  
      m = len(query)
      n = len(ts)
  
      # If length is odd, zero-pad time time series
      ts_add = 0
      if n % 2 == 1:
          ts = np.insert(ts, 0, 0)
          ts_add = 1
  
      q_add = 0
      # If length is odd, zero-pad query
      if m % 2 == 1:
          query = np.insert(query, 0, 0)
          q_add = 1
  
      # This reverses the array
      query = query[::-1]
  
      query = np.pad(query, (0, n - m + ts_add - q_add), "constant")
  
      # Determine trim length for dot product. Note that zero-padding of the query has no effect on array length, which is solely determined by the longest vector
      trim = m - 1 + ts_add
  
      dot_product = fft.irfft(fft.rfft(ts) * fft.rfft(query))
  
      # Note that we only care about the dot product results from index m-1 onwards, as the first few values aren't true dot products (due to the way the FFT works for dot products)
      return dot_product[trim:]
  
file_path: matrixprofile-ts/matrixprofile/utils.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from __future__ import unicode_literals
  import numpy
  import numpy.fft
label_desc: Use image node_id 5 for calling a global function with example usage: slidingDotProduct(query, ts) and returns: dot_product