code: def test_masks():
      for be in backends:
          for array_type in array_types:
              backend = instantiate_backend(be)
              sk_mask = tslearn.metrics.sakoe_chiba_mask(4, 4, 1, be=be)
              reference_mask = np.array(
                  [
                      [0.0, 0.0, np.inf, np.inf],
                      [0.0, 0.0, 0.0, np.inf],
                      [np.inf, 0.0, 0.0, 0.0],
                      [np.inf, np.inf, 0.0, 0.0],
                  ]
              )
              np.testing.assert_allclose(sk_mask, reference_mask)
              assert backend.belongs_to_backend(sk_mask)
  
              sk_mask = tslearn.metrics.sakoe_chiba_mask(7, 3, 1, be=be)
              reference_mask = np.array(
                  [
                      [0.0, 0.0, np.inf],
                      [0.0, 0.0, 0.0],
                      [0.0, 0.0, 0.0],
                      [0.0, 0.0, 0.0],
                      [0.0, 0.0, 0.0],
                      [0.0, 0.0, 0.0],
                      [np.inf, 0.0, 0.0],
                  ]
              )
              np.testing.assert_allclose(sk_mask, reference_mask)
              assert backend.belongs_to_backend(sk_mask)
  
              i_mask = tslearn.metrics.itakura_mask(6, 6, be=be)
              reference_mask = np.array(
                  [
                      [0.0, np.inf, np.inf, np.inf, np.inf, np.inf],
                      [np.inf, 0.0, 0.0, np.inf, np.inf, np.inf],
                      [np.inf, 0.0, 0.0, 0.0, np.inf, np.inf],
                      [np.inf, np.inf, 0.0, 0.0, 0.0, np.inf],
                      [np.inf, np.inf, np.inf, 0.0, 0.0, np.inf],
                      [np.inf, np.inf, np.inf, np.inf, np.inf, 0.0],
                  ]
              )
              np.testing.assert_allclose(i_mask, reference_mask)
              assert backend.belongs_to_backend(i_mask)
  
              # Test masks for different combinations of global_constraints /
              # sakoe_chiba_radius / itakura_max_slope
              sz = 10
              ts0 = cast(np.empty((sz, 1)), array_type)
              ts1 = cast(np.empty((sz, 1)), array_type)
              mask_no_constraint = (
                  tslearn.metrics.dtw_variants.compute_mask(
                      ts0, ts1, global_constraint=0, be=be
                  )
              )
              np.testing.assert_allclose(
                  mask_no_constraint, np.zeros((sz, sz))
              )
              backend = instantiate_backend(be, array_type)
              assert backend.belongs_to_backend(mask_no_constraint)
  
              mask_itakura = tslearn.metrics.dtw_variants.compute_mask(
                  ts0, ts1, global_constraint=1, be=be
              )
              mask_itakura_bis = (
                  tslearn.metrics.dtw_variants.compute_mask(
                      ts0, ts1, itakura_max_slope=2.0, be=be
                  )
              )
              np.testing.assert_allclose(mask_itakura, mask_itakura_bis)
              assert backend.belongs_to_backend(mask_itakura)
  
              mask_sakoe = tslearn.metrics.dtw_variants.compute_mask(
                  ts0, ts1, global_constraint=2, be=be
              )
  
              mask_sakoe_bis = (
                  tslearn.metrics.dtw_variants.compute_mask(
                      ts0, ts1, sakoe_chiba_radius=1, be=be
                  )
              )
              np.testing.assert_allclose(mask_sakoe, mask_sakoe_bis)
              assert backend.belongs_to_backend(mask_sakoe)
  
              np.testing.assert_raises(
                  RuntimeWarning,
                  tslearn.metrics.dtw_variants.compute_mask,
                  ts0,
                  ts1,
                  sakoe_chiba_radius=1,
                  itakura_max_slope=2.0,
                  be=be,
              )
  
              # Tests for estimators that can set masks through metric_params
              n, sz, d = 15, 10, 3
              rng = np.random.RandomState(0)
              time_series = rng.randn(n, sz, d)
              time_series = cast(time_series, array_type)
              estimator1 = tslearn.clustering.TimeSeriesKMeans(
                  metric="dtw",
                  metric_params={"itakura_max_slope": 1.0},
                  max_iter=5,
                  random_state=0,
              )
              estimator2 = tslearn.clustering.TimeSeriesKMeans(
                  metric="euclidean", max_iter=5, random_state=0
              )
              estimator3 = tslearn.clustering.TimeSeriesKMeans(
                  metric="dtw",
                  metric_params={"sakoe_chiba_radius": 0},
                  max_iter=5,
                  random_state=0,
              )
              np.testing.assert_allclose(
                  estimator1.fit(time_series).labels_,
                  estimator2.fit(time_series).labels_,
              )
              np.testing.assert_allclose(
                  estimator1.fit(time_series).labels_,
                  estimator3.fit(time_series).labels_,
              )
  
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 10 for calling a global function with example usage: test_masks() without return types