code: def _dtw_cost_matrix(
      x: np.ndarray, y: np.ndarray, dist: DistanceFunc, window: Window
  ) -> CostMatrix:
      dtw = CostMatrix._from_window(window)
  
      dtw.fill(np.inf)
      dtw[0, 0] = 0
  
      for i, j in window:
          cost = dist(x[i - 1], y[j - 1])
          min_cost_prev = min(
              dtw[i - 1, j], dtw[i, j - 1], dtw[i - 1, j - 1]
          )
          dtw[i, j] = cost + min_cost_prev
  
      return dtw
  
imports: import copy
  from typing import Callable, Optional, Union
  import numpy
  import pandas
  import xarray
  from darts import TimeSeries
  from darts.logging import get_logger, raise_if, raise_if_not
  from darts.timeseries import DIMS
  from .cost_matrix import CostMatrix
  from .window import CRWindow, NoWindow, Window
label_desc: Use image node_id 1 for calling a global function with example usage: _dtw_cost_matrix(x, y, dist, window) and returns: dtw