class_docstr: A block applying global pooling with optional masking.
  Pooling is applied w.r.t. the selected pooling function, the pooling dimension and the optional mask (in_keys[1]).
  
  :param in_keys: One key identifying the input tensor, and an optional second one identifying the mask tensor.
  :param out_keys: One key identifying the output tensors.
  :param in_shapes: List of input shapes.
  :param pooling_func: Options: {'mean', 'sum', 'max'}.
  :param pooling_dim: The dimension(s) along which the pooling functions get applied.
class_docstr_tok: ["A","block","applying","global","pooling","with","optional","masking",".","Pooling","is","applied","w.r.t",".","the","selected","pooling","function",",","the","pooling","dimension","and","the","optional","mask","(","in_keys","[","1","]",")",".",":","param","in_keys",":","One","key","identifying","the","input","tensor",",","and","an","optional","second","one","identifying","the","mask","tensor",".",":","param","out_keys",":","One","key","identifying","the","output","tensors",".",":","param","in_shapes",":","List","of","input","shapes",".",":","param","pooling_func",":","Options",":","{","'mean","'",",","'sum","'",",","'max","'","}",".",":","param","pooling_dim",":","The","dimension","(","s",")","along","which","the","pooling","functions","get","applied","."]
code: def __init__(
      self,
      in_keys: Union[str, List[str]],
      out_keys: Union[str, List[str]],
      in_shapes: Union[Sequence[int], List[Sequence[int]]],
      pooling_func: str,
      pooling_dim: Union[int, Sequence[int]],
  ):
      super().__init__(
          in_keys=in_keys, out_keys=out_keys, in_shapes=in_shapes
      )
  
      self._use_masking = len(self.in_keys) > 1
  
      assert len(self.in_shapes[0]) >= 2, (
          "The first shape given to the block should be at least of dim 2, "
          f"but got {in_shapes[0]}"
      )
  
      if self._use_masking:
          assert len(self.in_shapes[1]) >= 1, (
              "The second shape given to the block should be at least of dim 1 "
              f"but got {in_shapes[1]}"
          )
          assert all(
              [
                  self.in_shapes[0][idx] == self.in_shapes[1][idx]
                  for idx in range(len(self.in_shapes[1]))
              ]
          )
  
      self._pooling_func_name = pooling_func
      # select appropriate pooling function
      if self._pooling_func_name == "mean":
          self.pooling_func = self._masked_mean
      elif self._pooling_func_name == "sum":
          self.pooling_func = self._masked_sum
      elif self._pooling_func_name == "max":
          self.pooling_func = self._masked_max
      else:
          raise ValueError(
              f"Pooling function {self._pooling_func_name} is not yet supported!"
          )
  
      self.pooling_dim = pooling_dim
  
file_path: maze/maze/perception/blocks/general/masked_global_pooling.py
imports: from typing import Union, List, Sequence, Dict
  import torch
  from maze.core.annotations import override
  from maze.perception.blocks.base import PerceptionBlock
label_desc: Use image node_id 4 to create a new MaskedGlobalPoolingBlock object from inherited base classes: PerceptionBlock with example: obj = MaskedGlobalPoolingBlock(in_keys, out_keys, in_shapes, pooling_func, pooling_dim)