code: def test_softdtw():
      for be in backends:
          for array_type in array_types:
              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
              )
              assert isinstance(path_ref, list)
              backend = instantiate_backend(be, array_type)
              assert backend.belongs_to_backend(dist_ref)
              mat_path_ref = np.zeros((10, 30))
              for i, j in path_ref:
                  mat_path_ref[i, j] = 1.0
  
              # Test of using a scipy distance function
              matrix_path, dist = tslearn.metrics.soft_dtw_alignment(
                  s1, s2, gamma=0.0, be=be
              )
              assert backend.belongs_to_backend(matrix_path)
              assert backend.belongs_to_backend(dist)
  
              np.testing.assert_equal(dist, dist_ref**2)
              np.testing.assert_allclose(matrix_path, mat_path_ref)
  
              ts1 = cast([[0.0]], array_type)
              ts2 = cast([[1.0]], array_type)
              sim = tslearn.metrics.soft_dtw(
                  ts1=ts1,
                  ts2=ts2,
                  gamma=1.0,
                  be=be,
                  compute_with_backend=True,
              )
              assert sim == 1.0
  
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 16 for calling a global function with example usage: test_softdtw() without return types