code: def _find_domain_reduction(op, domain):
      # Canonicalize dim.
      dim = op.defaults.get("dim", None)
      ndims = len(domain.shape)
      if dim is None:
          dims = set(range(ndims))
      elif isinstance(dim, int):
          dims = {dim % ndims}
      else:
          dims = {i % ndims for i in dim}
  
      # Compute shape.
      if op.defaults.get("keepdims", False):
          shape = tuple(
              1 if i in dims else domain.shape[i] for i in range(ndims)
          )
      else:
          shape = tuple(
              domain.shape[i] for i in range(ndims) if i not in dims
          )
  
      # Compute domain.
      if op.name in ("all", "any"):
          dtype = 2
      elif domain.dtype == "real":
          dtype = "real"
      else:
          raise NotImplementedError("TODO")
  
      return Array[dtype, shape]
  
imports: import copyreg
  import functools
  import inspect
  import operator
  import warnings
  from functools import reduce
  from weakref import WeakValueDictionary
  import funsor.ops
  from funsor.ops.builtin import parse_ellipsis, parse_slice
  from funsor.util import broadcast_shape, get_backend, get_tracing_state, quote
label_desc: Use image node_id 8 for calling a global function with example usage: _find_domain_reduction(op, domain) and returns: Array