class_docstr: A base class for merging patches.
  Extend this class to support operations for `PatchInference`.
  There are two methods that must be implemented in the concrete classes:
  
      - aggregate: aggregate the values at their corresponding locations
      - finalize: perform any final process and return the merged output
  
  Args:
      merged_shape: the shape of the tensor required to merge the patches.
      cropped_shape: the shape of the final merged output tensor.
          If not provided, it will be the same as `merged_shape`.
      device: the device where Merger tensors should reside.
docstr: Perform final operations for merging patches and return the final merged output.
  
  Returns:
      The results of merged patches, which is commonly a torch.Tensor representing the merged result, or
          a string representing the filepath to the merged results on disk.
  
  Raises:
      NotImplementedError: When the subclass does not override this method.
docstr_tok: ["Perform","final","operations","for","merging","patches","and","return","the","final","merged","output",".","Returns",":","The","results","of","merged","patches",",","which","is","commonly","a","torch.Tensor","representing","the","merged","result",",","or","a","string","representing","the","filepath","to","the","merged","results","on","disk",".","Raises",":","NotImplementedError",":","When","the","subclass","does","not","override","this","method","."]
code: def finalize(self) -> Any:
      """
      Perform final operations for merging patches and return the final merged output.
  
      Returns:
          The results of merged patches, which is commonly a torch.Tensor representing the merged result, or
              a string representing the filepath to the merged results on disk.
  
      Raises:
          NotImplementedError: When the subclass does not override this method.
  
      """
      raise NotImplementedError(
          f"Subclass {self.__class__.__name__} must implement this method."
      )
  
imports: from __future__ import annotations
  import threading
  from abc import ABC, abstractmethod
  from collections.abc import Sequence
  from contextlib import nullcontext
  from typing import TYPE_CHECKING, Any
  import numpy
  import torch
  from monai.utils import ensure_tuple_size, optional_import, require_pkg
label_desc: Use image node_id 3 for calling the Merger obj's underlying member method code with example usage: obj.finalize() without return types