class_docstr: An abstract base class for implementing custom aggregations.
  
  Aggregation can be either performed via an :obj:`index` vector, which
  defines the mapping from input elements to their location in the output:
  
  |
  
  .. image:: https://raw.githubusercontent.com/rusty1s/pytorch_scatter/
          master/docs/source/_figures/add.svg?sanitize=true
      :align: center
      :width: 400px
  
  |
  
  Notably, :obj:`index` does not have to be sorted (for most aggregation
  operators):
  
  .. code-block::
  
     # Feature matrix holding 10 elements with 64 features each:
     x = torch.randn(10, 64)
  
     # Assign each element to one of three sets:
     index = torch.tensor([0, 0, 1, 0, 2, 0, 2, 1, 0, 2])
  
     output = aggr(x, index)  #  Output shape: [3, 64]
  
  Alternatively, aggregation can be achieved via a "compressed" index vector
  called :obj:`ptr`. Here, elements within the same set need to be grouped
  together in the input, and :obj:`ptr` defines their boundaries:
  
  .. code-block::
  
     # Feature matrix holding 10 elements with 64 features each:
     x = torch.randn(10, 64)
  
     # Define the boundary indices for three sets:
     ptr = torch.tensor([0, 4, 7, 10])
  
     output = aggr(x, ptr=ptr)  #  Output shape: [4, 64]
  
  Note that at least one of :obj:`index` or :obj:`ptr` must be defined.
  
  Shapes:
      - **input:**
        node features :math:`(*, |\mathcal{V}|, F_{in})` or edge features
        :math:`(*, |\mathcal{E}|, F_{in})`,
        index vector :math:`(|\mathcal{V}|)` or :math:`(|\mathcal{E}|)`,
      - **output:** graph features :math:`(*, |\mathcal{G}|, F_{out})` or
        node features :math:`(*, |\mathcal{V}|, F_{out})`
class_docstr_tok: ["An","abstract","base","class","for","implementing","custom","aggregations",".","Aggregation","can","be","either","performed","via","an",":","obj",":","`","index","`","vector",",","which","defines","the","mapping","from","input","elements","to","their","location","in","the","output",":","|","..","image",":",":","https",":","\/\/raw.githubusercontent.com\/rusty1s\/pytorch_scatter\/","master\/docs\/source\/_figures\/add.svg","?","sanitize=true",":","align",":","center",":","width",":","400px","|","Notably",",",":","obj",":","`","index","`","does","not","have","to","be","sorted","(","for","most","aggregation","operators",")",":","..","code-block",":",":","#","Feature","matrix","holding","10","elements","with","64","features","each",":","x","=","torch.randn","(","10",",","64",")","#","Assign","each","element","to","one","of","three","sets",":","index","=","torch.tensor","(","[","0",",","0",",","1",",","0",",","2",",","0",",","2",",","1",",","0",",","2","]",")","output","=","aggr","(","x",",","index",")","#","Output","shape",":","[","3",",","64","]","Alternatively",",","aggregation","can","be","achieved","via","a","``","compressed","''","index","vector","called",":","obj",":","`","ptr","`",".","Here",",","elements","within","the","same","set","need","to","be","grouped","together","in","the","input",",","and",":","obj",":","`","ptr","`","defines","their","boundaries",":","..","code-block",":",":","#","Feature","matrix","holding","10","elements","with","64","features","each",":","x","=","torch.randn","(","10",",","64",")","#","Define","the","boundary","indices","for","three","sets",":","ptr","=","torch.tensor","(","[","0",",","4",",","7",",","10","]",")","output","=","aggr","(","x",",","ptr=ptr",")","#","Output","shape",":","[","4",",","64","]","Note","that","at","least","one","of",":","obj",":","`","index","`","or",":","obj",":","`","ptr","`","must","be","defined",".","Shapes",":","-","*","*","input",":","*","*","node","features",":","math",":","`","(","*",",","|\\mathcal","{","V","}","|",",","F_","{","in","}",")","`","or","edge","features",":","math",":","`","(","*",",","|\\mathcal","{","E","}","|",",","F_","{","in","}",")","`",",","index","vector",":","math",":","`","(","|\\mathcal","{","V","}","|",")","`","or",":","math",":","`","(","|\\mathcal","{","E","}","|",")","`",",","-","*","*","output",":","*","*","graph","features",":","math",":","`","(","*",",","|\\mathcal","{","G","}","|",",","F_","{","out","}",")","`","or","node","features",":","math",":","`","(","*",",","|\\mathcal","{","V","}","|",",","F_","{","out","}",")","`"]
code: def __call__(
      self,
      x: Tensor,
      index: Optional[Tensor] = None,
      ptr: Optional[Tensor] = None,
      dim_size: Optional[int] = None,
      dim: int = -2,
      **kwargs,
  ) -> Tensor:
      if dim >= x.dim() or dim < -x.dim():
          raise ValueError(
              f"Encountered invalid dimension '{dim}' of "
              f"source tensor with {x.dim()} dimensions"
          )
  
      if index is None and ptr is None:
          index = x.new_zeros(x.size(dim), dtype=torch.long)
  
      if ptr is not None:
          if dim_size is None:
              dim_size = ptr.numel() - 1
          elif dim_size != ptr.numel() - 1:
              raise ValueError(
                  f"Encountered invalid 'dim_size' (got "
                  f"'{dim_size}' but expected "
                  f"'{ptr.numel() - 1}')"
              )
  
      if index is not None and dim_size is None:
          dim_size = int(index.max()) + 1 if index.numel() > 0 else 0
  
      try:
          return super().__call__(
              x,
              index=index,
              ptr=ptr,
              dim_size=dim_size,
              dim=dim,
              **kwargs,
          )
      except (IndexError, RuntimeError) as e:
          if index is not None:
              if index.numel() > 0 and dim_size <= int(index.max()):
                  raise ValueError(
                      f"Encountered invalid 'dim_size' (got "
                      f"'{dim_size}' but expected "
                      f">= '{int(index.max()) + 1}')"
                  )
          raise e
  
file_path: pytorch_geometric/torch_geometric/nn/aggr/base.py
imports: from typing import Optional, Tuple
  import torch
  from torch import Tensor
  import torch_geometric.typing
  from torch_geometric import is_compiling
  from torch_geometric.experimental import disable_dynamic_shapes
  from torch_geometric.utils import scatter, segment, to_dense_batch
label_desc: Use image node_id 3 for calling the Aggregation obj's underlying member method code with example usage: obj.__call__(x, index, ptr, dim_size, dim) and returns: super