import torch


def softor(rasters: torch.Tensor, dim=1, keepdim=False) -> torch.Tensor:
    """Batched soft-or operation to combine rasters.

    Args:
      rasters: torch.Tensor of size [batch, *, nrasters, D*] representing stacks of nrasters images that will
               be composited into a single image
      dim: dimension over which to apply the composition
      keepdim: should the dimension be retained

    Returns:
      a torch.Tensor of size [batch, *, D*] representing the batch of composited images

    """
    rasters = 1 - rasters
    rasters = rasters.prod(dim=dim, keepdim=keepdim)  # product over nrasters dim
    return 1 - rasters