code: def test_choice_execution(setup):
      # test 1 chunk, get integer
      a = tensor.random.RandomState(0).choice(10)
      res = a.execute().fetch()
      np.testing.assert_array_less(res, 10)
      np.testing.assert_array_less(0, res)
  
      a = tensor.random.RandomState(0).choice(10)
      seed = tile(a).chunks[0].op.seed
      expected = np.random.RandomState(seed).choice(10)
      np.testing.assert_array_equal(res, expected)
  
      # test 1 chunk, integer
      a = tensor.random.RandomState(0).choice(10, (4, 3))
      res = a.execute().fetch()
      np.testing.assert_array_less(res, 10)
      np.testing.assert_array_less(-1, res)
      b = tensor.random.RandomState(0).choice(10, (4, 3))
      res2 = b.execute().fetch()
      np.testing.assert_array_equal(res, res2)
  
      # test 1 chunk, ndarray
      raw = np.random.RandomState(0).rand(10)
      a = tensor.random.RandomState(0).choice(raw, (4, 3))
      res = a.execute().fetch()
      seed = tile(a).chunks[0].op.seed
      expected = np.random.RandomState(seed).choice(raw, (4, 3))
      np.testing.assert_array_equal(res, expected)
  
      # test with replacement, integer
      a = tensor.random.RandomState(0).choice(20, (7, 4), chunk_size=4)
      res = a.execute().fetch()
      np.testing.assert_array_less(res, 20)
      np.testing.assert_array_less(-1, res)
      b = tensor.random.RandomState(0).choice(20, (7, 4), chunk_size=4)
      res2 = b.execute().fetch()
      np.testing.assert_array_equal(res, res2)
  
      # test with replacement, ndarray
      raw = np.random.RandomState(0).rand(20)
      t = tensor.array(raw, chunk_size=8)
      a = tensor.random.RandomState(0).choice(t, (7, 4), chunk_size=4)
      res = a.execute().fetch()
      np.testing.assert_array_less(res, 20)
      np.testing.assert_array_less(-1, res)
      b = tensor.random.RandomState(0).choice(t, (7, 4), chunk_size=4)
      res2 = b.execute().fetch()
      np.testing.assert_array_equal(res, res2)
  
      # test without replacement, integer
      a = tensor.random.RandomState(0).choice(
          100, (7, 2), chunk_size=2, replace=False
      )
      res = a.execute().fetch()
      np.testing.assert_array_less(res, 100)
      np.testing.assert_array_less(-1, res)
      assert len(np.unique(res))
      b = tensor.random.RandomState(0).choice(
          100, (7, 2), chunk_size=2, replace=False
      )
      res2 = b.execute().fetch()
      np.testing.assert_array_equal(res, res2)
  
      # test without replacement, ndarray
      raw = np.random.RandomState(0).rand(100)
      t = tensor.array(raw, chunk_size=47)
      a = tensor.random.RandomState(0).choice(
          t, (7, 2), chunk_size=2, replace=False
      )
      res = a.execute().fetch()
      np.testing.assert_array_less(res, 100)
      np.testing.assert_array_less(-1, res)
      assert len(np.unique(res))
      b = tensor.random.RandomState(0).choice(
          t, (7, 2), chunk_size=2, replace=False
      )
      res2 = b.execute().fetch()
      np.testing.assert_array_equal(res, res2)
  
      # test p
      raw = np.random.RandomState(0).rand(5)
      p = [0.3, 0.2, 0.1, 0.3, 0.1]
      a = tensor.random.RandomState(0).choice(raw, 3, p=p)
      res = a.execute().fetch()
      expected = np.random.RandomState(
          tile(a).chunks[0].op.seed
      ).choice(raw, 3, p=p)
      np.testing.assert_array_equal(res, expected)
  
file_path: mars/mars/tensor/random/tests/test_random_execution.py
imports: from collections import namedtuple
  import numpy
  import pytest
  from ....None import tensor
  from ....core import tile
  from ....lib.sparse.core import issparse
  from ...datasource import tensor
label_desc: Use image node_id 4 for calling a global function with example usage: test_choice_execution(setup) without return types