code: def test_dtw():
      for be in backends:
          for array_type in array_types:
              backend = instantiate_backend(be, array_type)
              # dtw_path
              path, dist = tslearn.metrics.dtw_path(
                  cast([1, 2, 3], array_type),
                  cast([1.0, 2.0, 2.0, 3.0], array_type),
                  be=be,
              )
              np.testing.assert_equal(
                  path, [(0, 0), (1, 1), (1, 2), (2, 3)]
              )
              np.testing.assert_allclose(dist, [0.0])
              assert backend.belongs_to_backend(dist)
  
              path, dist = tslearn.metrics.dtw_path(
                  cast([1, 2, 3], array_type),
                  cast([1.0, 2.0, 2.0, 3.0, 4.0], array_type),
                  be=be,
              )
              np.testing.assert_allclose(dist, [1.0])
              assert backend.belongs_to_backend(dist)
  
              # dtw
              n1, n2, d = 15, 10, 3
              rng = np.random.RandomState(0)
              x = cast(rng.randn(n1, d), array_type)
              y = cast(rng.randn(n2, d), array_type)
  
              np.testing.assert_allclose(
                  tslearn.metrics.dtw(x, y, be=be),
                  tslearn.metrics.dtw_path(x, y, be=be)[1],
              )
  
              # cdist_dtw
              dists = tslearn.metrics.cdist_dtw(
                  cast(
                      [[1, 2, 2, 3], [1.0, 2.0, 3.0, 4.0]], array_type
                  ),
                  be=be,
              )
              np.testing.assert_allclose(
                  dists, cast([[0.0, 1.0], [1.0, 0.0]], array_type)
              )
              dists = tslearn.metrics.cdist_dtw(
                  cast(
                      [[1, 2, 2, 3], [1.0, 2.0, 3.0, 4.0]], array_type
                  ),
                  [
                      [1, 2, 3],
                      [2, 3, 4, 5],
                  ],  # The second dataset can not be cast to array because of its shape
                  be=be,
              )
              np.testing.assert_allclose(
                  dists, [[0.0, 2.44949], [1.0, 1.414214]], atol=1e-5
              )
              assert backend.belongs_to_backend(dists)
  
imports: import platform
  import sys
  import numpy
  import pytest
  import tslearn.clustering
  import tslearn.metrics
  from scipy.spatial.distance import cdist
  from tslearn.backend.backend import Backend, cast, instantiate_backend
  from tslearn.metrics.dtw_variants import dtw_path
  from tslearn.utils import to_time_series
label_desc: Use image node_id 1 for calling a global function with example usage: test_dtw() without return types