code: def test_quantile_execution(setup):
      # test 1 chunk, 1-d
      raw = np.random.rand(20)
      a = tensor(raw, chunk_size=20)
  
      raw2 = raw.copy()
      raw2[np.random.RandomState(0).randint(raw.size, size=3)] = np.nan
      a2 = tensor(raw2, chunk_size=20)
  
      for q in [
          np.random.RandomState(0).rand(),
          np.random.RandomState(0).rand(5),
      ]:
          for interpolation in INTERPOLATION_TYPES:
              for keepdims in [True, False]:
                  r = quantile(
                      a,
                      q,
                      interpolation=interpolation,
                      keepdims=keepdims,
                  )
  
                  result = r.execute().fetch()
                  expected = np.quantile(
                      raw,
                      q,
                      interpolation=interpolation,
                      keepdims=keepdims,
                  )
  
                  np.testing.assert_array_equal(result, expected)
  
                  r2 = quantile(
                      a2,
                      q,
                      interpolation=interpolation,
                      keepdims=keepdims,
                  )
  
                  result = r2.execute().fetch()
                  expected = np.quantile(
                      raw2,
                      q,
                      interpolation=interpolation,
                      keepdims=keepdims,
                  )
  
                  np.testing.assert_array_equal(result, expected)
  
      # test 1 chunk, 2-d
      raw = np.random.rand(20, 10)
      a = tensor(raw, chunk_size=20)
  
      raw2 = raw.copy()
      raw2.flat[
          np.random.RandomState(0).randint(raw.size, size=3)
      ] = np.nan
      a2 = tensor(raw2, chunk_size=20)
  
      for q in [
          np.random.RandomState(0).rand(),
          np.random.RandomState(0).rand(5),
      ]:
          for interpolation in INTERPOLATION_TYPES:
              for keepdims in [True, False]:
                  for axis in [None, 0, 1]:
                      r = quantile(
                          a,
                          q,
                          axis=axis,
                          interpolation=interpolation,
                          keepdims=keepdims,
                      )
  
                      result = r.execute().fetch()
                      expected = np.quantile(
                          raw,
                          q,
                          axis=axis,
                          interpolation=interpolation,
                          keepdims=keepdims,
                      )
  
                      np.testing.assert_array_equal(result, expected)
  
                      r2 = quantile(
                          a2,
                          q,
                          axis=axis,
                          interpolation=interpolation,
                          keepdims=keepdims,
                      )
  
                      result = r2.execute().fetch()
                      expected = np.quantile(
                          raw2,
                          q,
                          axis=axis,
                          interpolation=interpolation,
                          keepdims=keepdims,
                      )
  
                      np.testing.assert_array_equal(result, expected)
  
      # test multi chunks, 1-d
      raw = np.random.rand(20)
      a = tensor(raw, chunk_size=6)
  
      raw2 = raw.copy()
      raw2[np.random.RandomState(0).randint(raw.size, size=3)] = np.nan
      a2 = tensor(raw2, chunk_size=20)
  
      for q in [
          np.random.RandomState(0).rand(),
          np.random.RandomState(0).rand(5),
      ]:
          for interpolation in INTERPOLATION_TYPES:
              for keepdims in [True, False]:
                  r = quantile(
                      a,
                      q,
                      interpolation=interpolation,
                      keepdims=keepdims,
                  )
  
                  result = r.execute().fetch()
                  expected = np.quantile(
                      raw,
                      q,
                      interpolation=interpolation,
                      keepdims=keepdims,
                  )
  
                  np.testing.assert_almost_equal(result, expected)
  
                  r2 = quantile(
                      a2,
                      q,
                      interpolation=interpolation,
                      keepdims=keepdims,
                  )
  
                  result = r2.execute().fetch()
                  expected = np.quantile(
                      raw2,
                      q,
                      interpolation=interpolation,
                      keepdims=keepdims,
                  )
  
                  np.testing.assert_almost_equal(result, expected)
  
      # test multi chunk, 2-d
      raw = np.random.rand(20, 10)
      a = tensor(raw, chunk_size=(12, 6))
  
      raw2 = raw.copy()
      raw2.flat[
          np.random.RandomState(0).randint(raw.size, size=3)
      ] = np.nan
      a2 = tensor(raw2, chunk_size=(12, 6))
  
      for q in [
          np.random.RandomState(0).rand(),
          np.random.RandomState(0).rand(5),
      ]:
          for interpolation in INTERPOLATION_TYPES:
              for keepdims in [True, False]:
                  for axis in [None, 0, 1]:
                      r = quantile(
                          a,
                          q,
                          axis=axis,
                          interpolation=interpolation,
                          keepdims=keepdims,
                      )
  
                      result = r.execute().fetch()
                      expected = np.quantile(
                          raw,
                          q,
                          axis=axis,
                          interpolation=interpolation,
                          keepdims=keepdims,
                      )
  
                      np.testing.assert_almost_equal(result, expected)
  
                      r2 = quantile(
                          a2,
                          q,
                          axis=axis,
                          interpolation=interpolation,
                          keepdims=keepdims,
                      )
  
                      result = r2.execute().fetch()
                      expected = np.quantile(
                          raw2,
                          q,
                          axis=axis,
                          interpolation=interpolation,
                          keepdims=keepdims,
                      )
  
                      np.testing.assert_almost_equal(result, expected)
  
      # test out, 1 chunk
      raw = np.random.rand(20)
      q = np.random.rand(11)
      a = tensor(raw, chunk_size=20)
      out = empty((5, 11))
      quantile(a, q, out=out)
  
      result = out.execute().fetch()
      expected = np.quantile(raw, q, out=np.empty((5, 11)))
      np.testing.assert_array_equal(result, expected)
  
      # test out, multi chunks
      raw = np.random.rand(20)
      q = np.random.rand(11)
      a = tensor(raw, chunk_size=6)
      out = empty((5, 11))
      quantile(a, q, out=out)
  
      result = out.execute().fetch()
      expected = np.quantile(raw, q, out=np.empty((5, 11)))
      np.testing.assert_almost_equal(result, expected)
  
      # test q which is a tensor
      q_raw = np.random.RandomState(0).rand(5)
      q = tensor(q_raw, chunk_size=6)
  
      r = quantile(a, q, axis=None)
  
      result = r.execute().fetch()
      expected = np.quantile(raw, q_raw, axis=None)
  
      np.testing.assert_almost_equal(result, expected)
  
      with pytest.raises(ValueError):
          q[0] = 1.1
          r = quantile(a, q, axis=None)
          _ = r.execute()
  
imports: import numpy
  import scipy.sparse
  import pytest
  from ....utils import ignore_warning
  from ...datasource import arange, tensor, empty
  from ...base import sort
  from ...merge import stack
  from ...reduction import all
  from ..None import average, bincount, cov, corrcoef, ptp, digitize, histogram_bin_edges, histogram, quantile, percentile, median
  from ..quantile import INTERPOLATION_TYPES
label_desc: Use image node_id 8 for calling a global function with example usage: test_quantile_execution(setup) without return types