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","."]
docstr: Compute mean of tensor along certain dimensions considering a given masking tensor.
  
  :param input_tensor: The input tensor.
  :param mask_tensor: The masking tensor.
  :param dim: The dimension(s) along which to compute the mean.
  :return: The masked mean tensor.
docstr_tok: ["Compute","mean","of","tensor","along","certain","dimensions","considering","a","given","masking","tensor",".",":","param","input_tensor",":","The","input","tensor",".",":","param","mask_tensor",":","The","masking","tensor",".",":","param","dim",":","The","dimension","(","s",")","along","which","to","compute","the","mean",".",":","return",":","The","masked","mean","tensor","."]
code: def _masked_mean(
      cls,
      input_tensor: torch.Tensor,
      mask_tensor: torch.Tensor,
      dim: Union[int, Sequence[int]],
  ) -> torch.Tensor:
      """Compute mean of tensor along certain dimensions considering a given masking tensor.
  
      :param input_tensor: The input tensor.
      :param mask_tensor: The masking tensor.
      :param dim: The dimension(s) along which to compute the mean.
      :return: The masked mean tensor.
      """
  
      # expand dimensions of tensor if required
      while mask_tensor.ndimension() < input_tensor.ndimension():
          mask_tensor = mask_tensor.unsqueeze(-1)
  
      # zero out masked values
      zero_input_tensor = input_tensor * mask_tensor
  
      # compute masked average
      tot = torch.sum(zero_input_tensor, dim=dim)
      cnt = torch.sum(mask_tensor, dim=dim)
      masked_mean = torch.div(tot, cnt)
      return masked_mean
  
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 2 for calling the MaskedGlobalPoolingBlock obj's underlying member method code with example usage: obj._masked_mean(cls, input_tensor, mask_tensor, dim) and returns: masked_mean