code: def test_ndarray_slice():
      np_rect_prism = np.arange(24).reshape((2, 3, 4))
      rect_prism = hl.nd.array(np_rect_prism)
      np_mat = np.arange(8).reshape((2, 4))
      mat = hl.nd.array(np_mat)
      np_flat = np.arange(20)
      flat = hl.nd.array(np_flat)
      a = [0, 1]
      an = np.array(a)
      ah = hl.nd.array(a)
      ae_np = np.arange(4 * 4 * 5 * 6 * 5 * 4).reshape(
          (4, 4, 5, 6, 5, 4)
      )
      ae = hl.nd.array(ae_np)
      assert_ndarrays_eq(
          (rect_prism[:, :, :], np_rect_prism[:, :, :]),
          (rect_prism[:, :, 1], np_rect_prism[:, :, 1]),
          (rect_prism[0:1, 1:3, 0:2], np_rect_prism[0:1, 1:3, 0:2]),
          (rect_prism[:, :, 1:4:2], np_rect_prism[:, :, 1:4:2]),
          (rect_prism[:, 2, 1:4:2], np_rect_prism[:, 2, 1:4:2]),
          (rect_prism[0, 2, 1:4:2], np_rect_prism[0, 2, 1:4:2]),
          (
              rect_prism[0, :, 1:4:2] + rect_prism[:, :1, 1:4:2],
              np_rect_prism[0, :, 1:4:2] + np_rect_prism[:, :1, 1:4:2],
          ),
          (
              rect_prism[0:, :, 1:4:2] + rect_prism[:, :1, 1:4:2],
              np_rect_prism[0:, :, 1:4:2] + np_rect_prism[:, :1, 1:4:2],
          ),
          (rect_prism[0, 0, -3:-1], np_rect_prism[0, 0, -3:-1]),
          (rect_prism[-1, 0:1, 3:0:-1], np_rect_prism[-1, 0:1, 3:0:-1]),
          # partial indexing
          (rect_prism[1], np_rect_prism[1]),
          (rect_prism[1:2], np_rect_prism[1:2]),
          (rect_prism[1:2:2], np_rect_prism[1:2:2]),
          (rect_prism[1, 2], np_rect_prism[1, 2]),
          (rect_prism[-1, 1:2:2], np_rect_prism[-1, 1:2:2]),
          # ellipses inclusion
          (rect_prism[...], np_rect_prism[...]),
          (rect_prism[1, ...], np_rect_prism[1, ...]),
          (rect_prism[..., 1], np_rect_prism[..., 1]),
          # np.newaxis inclusion
          (
              rect_prism[hl.nd.newaxis, :, :],
              np_rect_prism[np.newaxis, :, :],
          ),
          (rect_prism[hl.nd.newaxis], np_rect_prism[np.newaxis]),
          (
              rect_prism[hl.nd.newaxis, np.newaxis, np.newaxis],
              np_rect_prism[np.newaxis, np.newaxis, np.newaxis],
          ),
          (
              rect_prism[hl.nd.newaxis, np.newaxis, 1:4:2],
              np_rect_prism[np.newaxis, np.newaxis, 1:4:2],
          ),
          (
              rect_prism[1, :, hl.nd.newaxis],
              np_rect_prism[1, :, np.newaxis],
          ),
          (
              rect_prism[1, hl.nd.newaxis, 1],
              np_rect_prism[1, np.newaxis, 1],
          ),
          (
              rect_prism[..., hl.nd.newaxis, 1],
              np_rect_prism[..., np.newaxis, 1],
          ),
      )
      assert_ndarrays_eq(
          (flat[15:5:-1], np_flat[15:5:-1]),
          (flat[::-1], np_flat[::-1]),
          (flat[::22], np_flat[::22]),
          (flat[::-22], np_flat[::-22]),
          (flat[15:5], np_flat[15:5]),
          (flat[3:12:-1], np_flat[3:12:-1]),
          (flat[12:3:1], np_flat[12:3:1]),
          (flat[4:1:-2], np_flat[4:1:-2]),
          (flat[0:0:1], np_flat[0:0:1]),
          (flat[-4:-1:2], np_flat[-4:-1:2]),
          # ellipses inclusion
          (flat[...], np_flat[...]),
          (mat[::-1, :], np_mat[::-1, :]),
          (
              mat[0, 1:4:2] + mat[:, 1:4:2],
              np_mat[0, 1:4:2] + np_mat[:, 1:4:2],
          ),
          (mat[-1:4:1, 0], np_mat[-1:4:1, 0]),
          (mat[-1:4:-1, 0], np_mat[-1:4:-1, 0]),
          # out of bounds on start
          (mat[9:2:-1, 1:4], np_mat[9:2:-1, 1:4]),
          (mat[9:-1:-1, 1:4], np_mat[9:-1:-1, 1:4]),
          (mat[-5::, 0], np_mat[-5::, 0]),
          (mat[-5::-1, 0], np_mat[-5::-1, 0]),
          (mat[-5:-1:-1, 0], np_mat[-5:-1:-1, 0]),
          (mat[-5:-5:-1, 0], np_mat[-5:-5:-1, 0]),
          (mat[4::, 0], np_mat[4::, 0]),
          (mat[4:-1:, 0], np_mat[4:-1:, 0]),
          (mat[4:-1:-1, 0], np_mat[4:-1:-1, 0]),
          (mat[5::, 0], np_mat[5::, 0]),
          (mat[5::-1, 0], np_mat[5::-1, 0]),
          (mat[-5::-1, 0], np_mat[-5::-1, 0]),
          (mat[-5::1, 0], np_mat[-5::1, 0]),
          (mat[5:-1:-1, 0], np_mat[5:-1:-1, 0]),
          (mat[5:-5:-1, 0], np_mat[5:-5:-1, 0]),
          # out of bounds on stop
          (mat[0:20, 0:17], np_mat[0:20, 0:17]),
          (mat[0:20, 2:17], np_mat[0:20, 2:17]),
          (mat[:4, 0], np_mat[:4, 0]),
          (mat[:4:-1, 0], np_mat[:4:-1, 0]),
          (mat[:-5, 0], np_mat[:-5, 0]),
          (mat[:-5:-1, 0], np_mat[:-5:-1, 0]),
          (mat[0:-5, 0], np_mat[0:-5, 0]),
          (mat[0:-5:-1, 0], np_mat[0:-5:-1, 0]),
          # partial indexing
          (mat[1], np_mat[1]),
          (mat[0:1], np_mat[0:1]),
          # ellipses inclusion
          (mat[...], np_mat[...]),
          (ah[:-3:1], an[:-3:1]),
          (ah[:-3:-1], an[:-3:-1]),
          (ah[-3::-1], an[-3::-1]),
          (ah[-3::1], an[-3::1]),
          # ellipses inclusion
          (ae[..., 3], ae_np[..., 3]),
          (ae[3, ...], ae_np[3, ...]),
          (ae[2, 3, 1:2:2, ...], ae_np[2, 3, 1:2:2, ...]),
          (ae[3, 2, 3, ..., 2], ae_np[3, 2, 3, ..., 2]),
          (ae[3, 2, 2, ..., 2, 1:2:2], ae_np[3, 2, 2, ..., 2, 1:2:2]),
          (
              ae[3, :, hl.nd.newaxis, ..., :, hl.nd.newaxis, 2],
              ae_np[3, :, np.newaxis, ..., :, np.newaxis, 2],
          ),
      )
  
      assert hl.eval(flat[hl.missing(hl.tint32) : 4 : 1]) is None
      assert hl.eval(flat[4 : hl.missing(hl.tint32)]) is None
      assert hl.eval(flat[4 : 10 : hl.missing(hl.tint32)]) is None
      assert (
          hl.eval(rect_prism[:, :, 0 : hl.missing(hl.tint32) : 1])
          is None
      )
      assert hl.eval(rect_prism[hl.missing(hl.tint32), :, :]) is None
  
      with pytest.raises(
          HailUserError, match="Slice step cannot be zero"
      ):
          hl.eval(flat[::0])
  
      with pytest.raises(
          HailUserError,
          match="Index 3 is out of bounds for axis 0 with size 2",
      ):
          hl.eval(mat[3, 1:3])
  
      with pytest.raises(
          HailUserError,
          match="Index -4 is out of bounds for axis 0 with size 2",
      ):
          hl.eval(mat[-4, 0:3])
  
      with pytest.raises(
          IndexError, match="an index can only have a single ellipsis"
      ):
          hl.eval(rect_prism[..., ...])
  
      with pytest.raises(
          IndexError,
          match="too many indices for array: array is 3-dimensional, but 4 were indexed",
      ):
          hl.eval(rect_prism[1, 1, 1, 1])
  
imports: import math
  import numpy
  import re
  from ..helpers import *
  import pytest
  from hail.utils.java import FatalError, HailUserError
label_desc: Use image node_id 6 for calling a global function with example usage: test_ndarray_slice() without return types