code: def test_dtw_path_from_metric():
      for be in backends:
          for array_type in array_types:
              backend = instantiate_backend(be, array_type)
              rng = np.random.RandomState(0)
              s1 = cast(rng.rand(10, 2), array_type)
              s2 = cast(rng.rand(30, 2), array_type)
  
              # Use dtw_path as a reference
              path_ref, dist_ref = tslearn.metrics.dtw_path(
                  s1, s2, be=be
              )
  
              # Test of using a scipy distance function
              path, dist = tslearn.metrics.dtw_path_from_metric(
                  s1, s2, metric="sqeuclidean", be=be
              )
              np.testing.assert_equal(path, path_ref)
              assert isinstance(path, list)
              np.testing.assert_allclose(backend.sqrt(dist), dist_ref)
              assert backend.belongs_to_backend(dist)
  
              # Test of defining a custom function
              def sqeuclidean(x, y):
                  return backend.sum((x - y) ** 2)
  
              path, dist = tslearn.metrics.dtw_path_from_metric(
                  s1, s2, metric=sqeuclidean, be=be
              )
              np.testing.assert_equal(path, path_ref)
              assert isinstance(path, list)
              np.testing.assert_allclose(backend.sqrt(dist), dist_ref)
              assert backend.belongs_to_backend(dist)
  
              # Test of precomputing the distance matrix
              dist_matrix = cdist(s1, s2, metric="sqeuclidean")
              dist_matrix = cast(dist_matrix, array_type)
              path, dist = tslearn.metrics.dtw_path_from_metric(
                  dist_matrix, metric="precomputed", be=be
              )
              np.testing.assert_equal(path, path_ref)
              assert isinstance(path, list)
              np.testing.assert_allclose(backend.sqrt(dist), dist_ref)
              assert backend.belongs_to_backend(dist)
  
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 15 for calling a global function with example usage: test_dtw_path_from_metric() and returns: backend