code: def test_ldtw():
      for be in backends:
          for array_type in array_types:
              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)
  
              ldtw_n1_plus_2 = (
                  tslearn.metrics.dtw_limited_warping_length(
                      x, y, n1 + 2, be=be
                  )
              )
  
              # LDTW >= DTW
              np.testing.assert_allclose(
                  tslearn.metrics.dtw(x, y, be=be),
                  ldtw_n1_plus_2,
              )
              backend = instantiate_backend(be, array_type)
              assert backend.belongs_to_backend(ldtw_n1_plus_2)
  
              # if path is too short, LDTW raises a ValueError
              np.testing.assert_raises(
                  ValueError,
                  tslearn.metrics.dtw_limited_warping_length,
                  x,
                  y,
                  max(n1, n2) - 1,
                  be,
              )
  
              # if max_length is smaller than length of optimal DTW path, LDTW > DTW
              path, cost = tslearn.metrics.dtw_path(x, y, be=be)
              np.testing.assert_array_less(
                  cost,
                  tslearn.metrics.dtw_limited_warping_length(
                      x, y, len(path) - 1, be=be
                  ),
              )
  
              # if max_length is geq than length of optimal DTW path, LDTW = DTW
              np.testing.assert_allclose(
                  cost,
                  tslearn.metrics.dtw_limited_warping_length(
                      x, y, len(path)
                  ),
              )
              np.testing.assert_allclose(
                  cost,
                  tslearn.metrics.dtw_limited_warping_length(
                      x, y, len(path) + 1, be=be
                  ),
              )
              (
                  path,
                  cost,
              ) = tslearn.metrics.dtw_path_limited_warping_length(
                  x, y, n1 + 2, be=be
              )
              np.testing.assert_allclose(cost, ldtw_n1_plus_2)
              assert len(path) <= n1 + 2
  
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 3 for calling a global function with example usage: test_ldtw() without return types