code: def test_unique_execution(setup):
      rs = np.random.RandomState(0)
      raw = rs.randint(10, size=(10,))
  
      for chunk_size in (10, 3):
          x = tensor(raw, chunk_size=chunk_size)
  
          y = unique(x)
  
          res = y.execute().fetch()
          expected = np.unique(raw)
          np.testing.assert_array_equal(res, expected)
  
          y, indices = unique(x, return_index=True)
  
          res = fetch(execute(y, indices))
          expected = np.unique(raw, return_index=True)
          assert len(res) == 2
          assert len(expected) == 2
          np.testing.assert_array_equal(res[0], expected[0])
          np.testing.assert_array_equal(res[1], expected[1])
  
          y, inverse = unique(x, return_inverse=True)
  
          res = fetch(*execute(y, inverse))
          expected = np.unique(raw, return_inverse=True)
          assert len(res) == 2
          assert len(expected) == 2
          np.testing.assert_array_equal(res[0], expected[0])
          np.testing.assert_array_equal(res[1], expected[1])
  
          y, counts = unique(x, return_counts=True)
  
          res = fetch(*execute(y, counts))
          expected = np.unique(raw, return_counts=True)
          assert len(res) == 2
          assert len(expected) == 2
          np.testing.assert_array_equal(res[0], expected[0])
          np.testing.assert_array_equal(res[1], expected[1])
  
          y, indices, inverse, counts = unique(
              x,
              return_index=True,
              return_inverse=True,
              return_counts=True,
          )
  
          res = fetch(*execute(y, indices, inverse, counts))
          expected = np.unique(
              raw,
              return_index=True,
              return_inverse=True,
              return_counts=True,
          )
          assert len(res) == 4
          assert len(expected) == 4
          np.testing.assert_array_equal(res[0], expected[0])
          np.testing.assert_array_equal(res[1], expected[1])
          np.testing.assert_array_equal(res[2], expected[2])
          np.testing.assert_array_equal(res[3], expected[3])
  
          y, indices, counts = unique(
              x, return_index=True, return_counts=True
          )
  
          res = fetch(*execute(y, indices, counts))
          expected = np.unique(
              raw, return_index=True, return_counts=True
          )
          assert len(res) == 3
          assert len(expected) == 3
          np.testing.assert_array_equal(res[0], expected[0])
          np.testing.assert_array_equal(res[1], expected[1])
          np.testing.assert_array_equal(res[2], expected[2])
  
          raw2 = rs.randint(10, size=(4, 5, 6))
          x2 = tensor(raw2, chunk_size=chunk_size)
  
          y2 = unique(x2)
  
          res = y2.execute().fetch()
          expected = np.unique(raw2)
          np.testing.assert_array_equal(res, expected)
  
          y2 = unique(x2, axis=1)
  
          res = y2.execute().fetch()
          expected = np.unique(raw2, axis=1)
          np.testing.assert_array_equal(res, expected)
  
          y2 = unique(x2, axis=2)
  
          res = y2.execute().fetch()
          expected = np.unique(raw2, axis=2)
          np.testing.assert_array_equal(res, expected)
  
      raw = rs.randint(10, size=(10, 20))
      raw[:, 0] = raw[:, 11] = rs.randint(10, size=(10,))
      x = tensor(raw, chunk_size=2)
      y, ind, inv, counts = unique(
          x,
          aggregate_size=3,
          axis=1,
          return_index=True,
          return_inverse=True,
          return_counts=True,
      )
  
      res_unique, res_ind, res_inv, res_counts = fetch(
          *execute(y, ind, inv, counts)
      )
      exp_unique, exp_ind, exp_counts = np.unique(
          raw, axis=1, return_index=True, return_counts=True
      )
      raw_res_unique = res_unique
      res_unique_df = pd.DataFrame(res_unique)
      res_unique_ind = np.asarray(
          res_unique_df.sort_values(
              list(range(res_unique.shape[0])), axis=1
          ).columns
      )
      res_unique = res_unique[:, res_unique_ind]
      res_ind = res_ind[res_unique_ind]
      res_counts = res_counts[res_unique_ind]
  
      np.testing.assert_array_equal(res_unique, exp_unique)
      np.testing.assert_array_equal(res_ind, exp_ind)
      np.testing.assert_array_equal(raw_res_unique[:, res_inv], raw)
      np.testing.assert_array_equal(res_counts, exp_counts)
  
      x = (
          mt.random.RandomState(0).rand(1000, chunk_size=20) > 0.5
      ).astype(np.int32)
      y = unique(x)
      res = np.sort(y.execute().fetch())
      np.testing.assert_array_equal(res, np.array([0, 1]))
  
      # test sparse
      sparse_raw = sps.random(
          10, 3, density=0.1, format="csr", random_state=rs
      )
      x = tensor(sparse_raw, chunk_size=2)
      y = unique(x)
      res = np.sort(y.execute().fetch())
      np.testing.assert_array_equal(res, np.unique(sparse_raw.data))
  
      # test empty
      x = tensor([])
      y = unique(x)
      res = y.execute().fetch()
      np.testing.assert_array_equal(res, np.unique([]))
  
      x = tensor([[]])
      y = unique(x)
      res = y.execute().fetch()
      np.testing.assert_array_equal(res, np.unique([[]]))
  
imports: import numpy
  import scipy.sparse
  import pandas
  import pytest
  from ....None import dataframe
  from ....None import tensor
  from ....None import execute, fetch
  from ....tests.core import require_cupy
  from ...datasource import tensor, ones, zeros, arange
  from ..None import copyto, transpose, moveaxis, broadcast_to, broadcast_arrays, where, expand_dims, rollaxis, atleast_1d, atleast_2d, atleast_3d, argwhere, array_split, split, hsplit, vsplit, dsplit, roll, squeeze, diff, ediff1d, flip, flipud, fliplr, repeat, tile, isin, searchsorted, unique, sort, argsort, partition, argpartition, topk, argtopk, trapz, shape, to_gpu, to_cpu, swapaxes
label_desc: Use image node_id 29 for calling a global function with example usage: test_unique_execution(setup) without return types