code: def ensure_num_entities(
      edge_index: numpy.ndarray, num_entities: Optional[int] = None
  ) -> int:
      """Calculate the number of entities from the edge index if not given."""
      if num_entities is not None:
          return num_entities
      return edge_index.max().item() + 1
  
file_path: pykeen/src/pykeen/nn/node_piece/utils.py
imports: import logging
  from typing import Collection, Mapping, Optional
  import numpy
  import torch
  from tqdm.auto import tqdm
label_desc: Use image node_id 2 for calling a global function with example usage: ensure_num_entities(edge_index, num_entities) and returns: unknown, num_entities