code: def _is_non_dominated_loop(
      Y: Tensor, maximize: bool = True
  ) -> Tensor:
      r"""Determine which points are non-dominated.
  
      Compared to `is_non_dominated`, this method is significantly
      faster for large `n` on a CPU and will significant reduce memory
      overhead. However, `is_non_dominated` is faster for smaller problems.
  
      Args:
          Y: A `(batch_shape) x n x m` Tensor of outcomes.
          maximize: A boolean indicating if the goal is maximization.
  
      Returns:
          A `(batch_shape) x n`-dim Tensor of booleans indicating whether each point is
              non-dominated.
      """
      is_efficient = torch.ones(
          *Y.shape[:-1], dtype=bool, device=Y.device
      )
      for i in range(Y.shape[-2]):
          i_is_efficient = is_efficient[..., i]
          if i_is_efficient.any():
              vals = Y[..., i : i + 1, :]
              if maximize:
                  update = (Y > vals).any(dim=-1)
              else:
                  update = (Y < vals).any(dim=-1)
              # If an element in Y[..., i, :] is efficient, mark it as efficient
              update[..., i] = i_is_efficient.clone()
              # Only include batches where  Y[..., i, :] is efficient
              # Create a copy
              is_efficient2 = is_efficient.clone()
              if Y.ndim > 2:
                  # Set all elements in all batches where Y[..., i, :] is not
                  # efficient to False
                  is_efficient2[~i_is_efficient] = False
              # Only include elements from in_efficient from the batches
              # where Y[..., i, :] is efficient
              is_efficient[is_efficient2] = update[is_efficient2]
      return is_efficient
  
imports: from __future__ import annotations
  import torch
  from torch import Tensor
label_desc: Use image node_id 2 for calling a global function with example usage: _is_non_dominated_loop(Y, maximize) and returns: is_efficient