code: def test_diagonal():
      v = cupy.arange(11)
      with pytest.raises(ValueError):
          da.diagonal(v)
  
      v = cupy.arange(4).reshape((2, 2))
      with pytest.raises(ValueError):
          da.diagonal(v, axis1=0, axis2=0)
  
      with pytest.raises(AxisError):
          da.diagonal(v, axis1=-4)
  
      with pytest.raises(AxisError):
          da.diagonal(v, axis2=-4)
  
      v = cupy.arange(4 * 5 * 6).reshape((4, 5, 6))
      v = da.from_array(v, chunks=2, asarray=False)
      assert_eq(da.diagonal(v), np.diagonal(v))
      # Empty diagonal.
      assert_eq(da.diagonal(v, offset=10), np.diagonal(v, offset=10))
      assert_eq(da.diagonal(v, offset=-10), np.diagonal(v, offset=-10))
      assert isinstance(da.diagonal(v).compute(), cupy.ndarray)
  
      with pytest.raises(ValueError):
          da.diagonal(v, axis1=-2)
  
      # Negative axis.
      assert_eq(da.diagonal(v, axis1=-1), np.diagonal(v, axis1=-1))
      assert_eq(
          da.diagonal(v, offset=1, axis1=-1),
          np.diagonal(v, offset=1, axis1=-1),
      )
  
      # Heterogeneous chunks.
      v = cupy.arange(2 * 3 * 4 * 5 * 6).reshape((2, 3, 4, 5, 6))
      v = da.from_array(
          v,
          chunks=(1, (1, 2), (1, 2, 1), (2, 1, 2), (5, 1)),
          asarray=False,
      )
  
      assert_eq(da.diagonal(v), np.diagonal(v))
      assert_eq(
          da.diagonal(v, offset=2, axis1=3, axis2=1),
          np.diagonal(v, offset=2, axis1=3, axis2=1),
      )
  
      assert_eq(
          da.diagonal(v, offset=-2, axis1=3, axis2=1),
          np.diagonal(v, offset=-2, axis1=3, axis2=1),
      )
  
      assert_eq(
          da.diagonal(v, offset=-2, axis1=3, axis2=4),
          np.diagonal(v, offset=-2, axis1=3, axis2=4),
      )
  
      assert_eq(da.diagonal(v, 1), np.diagonal(v, 1))
      assert_eq(da.diagonal(v, -1), np.diagonal(v, -1))
      # Positional arguments
      assert_eq(da.diagonal(v, 1, 2, 1), np.diagonal(v, 1, 2, 1))
  
file_path: dask/dask/array/tests/test_cupy_creation.py
imports: from __future__ import annotations
  import numpy
  import pytest
  import dask.array
  from dask import config
  from dask.array.numpy_compat import AxisError
  from dask.array.utils import assert_eq
label_desc: Use image node_id 2 for calling a global function with example usage: test_diagonal() without return types