code: def test_setitem_extended_API_2d_rhs_func_of_lhs():
      # Cases:
      # * RHS and/or indices are a function of the LHS
      # * Indices have unknown chunk sizes
      # * RHS has extra leading size 1 dimensions compared to LHS
      x = cupy.arange(60).reshape((6, 10))
      chunks = (2, 3)
  
      dx = da.from_array(x, chunks=chunks)
      dx[2:4, dx[0] > 3] = -5
      x[2:4, x[0] > 3] = -5
      assert_eq(x, dx.compute())
  
      dx = da.from_array(x, chunks=chunks)
      dx[2, dx[0] < -2] = -7
      x[2, x[0] < -2] = -7
      assert_eq(x, dx.compute())
  
      dx = da.from_array(x, chunks=chunks)
      dx[dx % 2 == 0] = -8
      x[x % 2 == 0] = -8
      assert_eq(x, dx.compute())
  
      dx = da.from_array(x, chunks=chunks)
      dx[dx % 2 == 0] = -8
      x[x % 2 == 0] = -8
      assert_eq(x, dx.compute())
  
      dx = da.from_array(x, chunks=chunks)
      dx[3:5, 5:1:-2] = -dx[:2, 4:1:-2]
      x[3:5, 5:1:-2] = -x[:2, 4:1:-2]
      assert_eq(x, dx.compute())
  
      dx = da.from_array(x, chunks=chunks)
      dx[0, 1:3] = -dx[0, 4:2:-1]
      x[0, 1:3] = -x[0, 4:2:-1]
      assert_eq(x, dx.compute())
  
      dx = da.from_array(x, chunks=chunks)
      dx[...] = dx
      x[...] = x
      assert_eq(x, dx.compute())
  
      dx = da.from_array(x, chunks=chunks)
      dx[...] = dx[...]
      x[...] = x[...]
      assert_eq(x, dx.compute())
  
      dx = da.from_array(x, chunks=chunks)
      dx[0] = dx[-1]
      x[0] = x[-1]
      assert_eq(x, dx.compute())
  
      dx = da.from_array(x, chunks=chunks)
      dx[0, :] = dx[-2, :]
      x[0, :] = x[-2, :]
      assert_eq(x, dx.compute())
  
      dx = da.from_array(x, chunks=chunks)
      dx[:, 1] = dx[:, -3]
      x[:, 1] = x[:, -3]
      assert_eq(x, dx.compute())
  
      index = da.from_array([0, 2], chunks=(2,))
      dx = da.from_array(x, chunks=chunks)
      dx[index, 8] = [99, 88]
      x[[0, 2], 8] = [99, 88]
      assert_eq(x, dx.compute())
  
      dx = da.from_array(x, chunks=chunks)
      dx[:, index] = dx[:, :2]
      x[:, [0, 2]] = x[:, :2]
      assert_eq(x, dx.compute())
  
      index = da.where(da.arange(3, chunks=(1,)) < 2)[0]
      dx = da.from_array(x, chunks=chunks)
      dx[index, 7] = [-23, -33]
      x[index.compute(), 7] = [-23, -33]
      assert_eq(x, dx.compute())
  
      index = da.where(da.arange(3, chunks=(1,)) < 2)[0]
      dx = da.from_array(x, chunks=chunks)
      dx[(index,)] = -34
      x[(index.compute(),)] = -34
      assert_eq(x, dx.compute())
  
      index = index - 4
      dx = da.from_array(x, chunks=chunks)
      dx[index, 7] = [-43, -53]
      x[index.compute(), 7] = [-43, -53]
      assert_eq(x, dx.compute())
  
      index = da.from_array([0, -1], chunks=(1,))
      x[[0, -1]] = 9999
      dx[(index,)] = 9999
      assert_eq(x, dx.compute())
  
      dx = da.from_array(x, chunks=(-1, -1))
      dx[...] = da.from_array(x, chunks=chunks)
      assert_eq(x, dx.compute())
  
      # Both tests below fail in CuPy due to leading singular dimensions
      if False:
          # RHS has extra leading size 1 dimensions compared to LHS
          dx = da.from_array(x.copy(), chunks=(2, 3))
          v = x.reshape((1, 1) + x.shape)
          x[...] = v
          dx[...] = v
          assert_eq(x, dx.compute())
  
          index = da.where(da.arange(3, chunks=(1,)) < 2)[0]
          v = -cupy.arange(12).reshape(1, 1, 6, 2)
          x[:, [0, 1]] = v
          dx[:, index] = v
          assert_eq(x, dx.compute())
  
imports: from __future__ import annotations
  import numpy
  import pytest
  from packaging.version import parse
  import dask
  import dask.array
  from dask.array.utils import assert_eq
  from dask.sizeof import sizeof
label_desc: Use image node_id 14 for calling a global function with example usage: test_setitem_extended_API_2d_rhs_func_of_lhs() without return types