code: def test_cdist():
      raw_a = np.random.rand(100, 10)
      raw_b = np.random.rand(90, 10)
  
      # test 1 chunk
      a = tensor(raw_a, chunk_size=100)
      b = tensor(raw_b, chunk_size=100)
      dist = distance.cdist(a, b)
      assert dist.shape == (100, 90)
  
      dist = tile(dist)
      assert len(dist.chunks) == 1
      for c in dist.chunks:
          assert c.shape == dist.shape
  
      # test multiple chunks
      a = tensor(raw_a, chunk_size=15)
      b = tensor(raw_b, chunk_size=16)
      dist = distance.cdist(a, b)
      assert dist.shape == (100, 90)
  
      ta, tb, dist = tile(a, b, dist)
      assert len(dist.chunks) == (100 // 15 + 1) * (90 // 16 + 1)
      assert dist.nsplits == (ta.nsplits[0], tb.nsplits[0])
      for c in dist.chunks:
          assert c.shape == (
              ta.cix[c.index[0], 0].shape[0],
              tb.cix[c.index[1], 0].shape[0],
          )
  
      # XA can only be 2-d
      with pytest.raises(ValueError):
          distance.cdist(np.random.rand(3, 3, 3), np.random.rand(3, 3))
  
      # XB can only be 2-d
      with pytest.raises(ValueError):
          distance.cdist(np.random.rand(3, 3), np.random.rand(3, 3, 3))
  
      # XA cannot be sparse
      raw = sps.csr_matrix(np.zeros((4, 3)))
      a = tensor(raw)
      with pytest.raises(ValueError):
          distance.cdist(a, np.random.rand(10, 3))
  
      # XB cannot be sparse
      raw = sps.csr_matrix(np.zeros((4, 3)))
      b = tensor(raw)
      with pytest.raises(ValueError):
          distance.cdist(np.random.rand(10, 3), b)
  
      # out type wrong
      with pytest.raises(TypeError):
          distance.cdist(raw_a, raw_b, out=2)
  
      # out shape wrong
      with pytest.raises(ValueError):
          distance.cdist(
              raw_a, raw_b, out=tensor(np.random.rand(100, 91))
          )
  
      # out dtype wrong
      with pytest.raises(ValueError):
          distance.cdist(
              raw_a,
              raw_b,
              out=tensor(np.random.randint(2, size=(100, 90))),
          )
  
      # test extra param
      with pytest.raises(TypeError):
          distance.cdist(raw_a, raw_b, unknown_kw="unknown_kw")
  
file_path: mars/mars/tensor/spatial/distance/tests/test_distance.py
imports: import numpy
  import pytest
  import scipy.sparse
  from .....core import tile
  from ....datasource import tensor
  from ...None import distance
label_desc: Use image node_id 2 for calling a global function with example usage: test_cdist() without return types