code: def scatter_nd(
      indices: paddle.Tensor,
      updates: paddle.Tensor,
      /,
      shape: Optional[Union[ivy.NativeShape, Sequence[int]]] = None,
      *,
      reduction: str = "sum",
      out: Optional[paddle.Tensor] = None,
  ) -> paddle.Tensor:
      updates = paddle.to_tensor(
          updates,
          dtype=(
              ivy.promote_types(out.dtype, updates.dtype)
              if ivy.exists(out)
              else ivy.default_dtype(item=updates)
          ),
      )
  
      if indices.dtype not in [paddle.int32, paddle.int64]:
          indices = indices.cast(paddle.int32)
  
      expected_shape = (
          list(indices.shape[:-1])
          + list(out.shape[indices.shape[-1] :])
          if ivy.exists(out)
          else list(indices.shape[:-1])
          + list(shape[indices.shape[-1] :])
      )
      updates = _broadcast_to(updates, expected_shape).data
  
      # remove duplicate indices
      # necessary because we will be using scatter_nd_add
      if indices.ndim > 1 and reduction != "sum":
          indices_shape = indices.shape
          indices = paddle.reshape(indices, (-1, indices.shape[-1]))
          num_indices = indices.shape[0]
          # use flip to keep the last occurrence of each value
          indices, unique_idxs = ivy.unique_all(
              ivy.flip(indices, axis=[0]), axis=0, by_value=True
          )[:2]
          indices = indices.data
          if len(unique_idxs) < num_indices:
              updates = paddle.reshape(
                  updates,
                  (-1, *updates.shape[len(indices_shape) - 1 :]),
              )
              updates = ivy.gather(
                  ivy.flip(updates, axis=[0]), unique_idxs, axis=0
              ).data
              expected_shape = (
                  list(indices.shape[:-1])
                  + list(out.shape[indices.shape[-1] :])
                  if ivy.exists(out)
                  else list(indices.shape[:-1])
                  + list(shape[indices.shape[-1] :])
              )
          else:
              indices = paddle.reshape(indices, indices_shape)
  
      # implementation
      target_given = ivy.exists(out)
      if target_given:
          target = out.data
      else:
          shape = list(shape) if ivy.exists(shape) else out.shape
          target = paddle.zeros(shape=shape).astype(updates.dtype)
      if ivy.exists(shape) and target_given:
          ivy.utils.assertions.check_equal(
              ivy.Shape(target.shape), ivy.Shape(shape), as_array=False
          )
      if reduction not in ["sum", "replace", "min", "max"]:
          raise ivy.utils.exceptions.IvyException(
              f'reduction is {reduction}, but it must be one of "sum", "min", "max" or'
              ' "replace"'
          )
      if reduction == "min":
          updates = ivy.minimum(
              ivy.gather_nd(target, indices), updates
          ).data
      elif reduction == "max":
          updates = ivy.maximum(
              ivy.gather_nd(target, indices), updates
          ).data
      elif reduction == "sum":
          updates = ivy.add(
              ivy.gather_nd(target, indices), updates
          ).data
      if indices.ndim <= 1:
          indices = ivy.expand_dims(indices, axis=0).data
          updates = ivy.expand_dims(updates, axis=0).data
      updates_ = _broadcast_to(
          ivy.gather_nd(target, indices), expected_shape
      ).data
      target_dtype = target.dtype
      if target_dtype in [
          paddle.complex64,
          paddle.complex128,
      ]:
          result_real = paddle.scatter_nd_add(
              paddle.scatter_nd_add(
                  target.real(), indices, -updates_.real()
              ),
              indices,
              updates.real(),
          )
          result_imag = paddle.scatter_nd_add(
              paddle.scatter_nd_add(
                  target.imag(), indices, -updates_.imag()
              ),
              indices,
              updates.imag(),
          )
          ret = paddle.complex(result_real, result_imag)
      elif target_dtype in [
          paddle.int8,
          paddle.int16,
          paddle.uint8,
          paddle.float16,
          paddle.bool,
      ]:
          target, updates, updates_ = (
              target.cast("float32"),
              updates.cast("float32"),
              updates_.cast("float32"),
          )
          ret = paddle.scatter_nd_add(
              paddle.scatter_nd_add(target, indices, -updates_),
              indices,
              updates,
          ).cast(target_dtype)
      else:
          ret = paddle.scatter_nd_add(
              paddle.scatter_nd_add(target, indices, -updates_),
              indices,
              updates,
          )
      if ivy.exists(out):
          return ivy.inplace_update(out, ret)
      return ret
  
imports: from numbers import Number
  from typing import Optional, Union, Sequence, Callable, List, Tuple
  import paddle
  import numpy
  import multiprocessing
  import ivy
  import ivy.functional.backends.paddle
  from ivy.func_wrapper import with_unsupported_device_and_dtypes
  from ivy.functional.ivy.general import _broadcast_to
  from ivy.utils.exceptions import _check_inplace_update_support
  from .None import backend_version
label_desc: Use image node_id 21 for calling a global function with example usage: scatter_nd(shape) and returns: ret, ivy