code: def neg_sample(
      seed: Tensor,
      neg_sampling: NegativeSampling,
      num_nodes: int,
      seed_time: Optional[Tensor],
      node_time: Optional[Tensor],
  ) -> Tensor:
      num_neg = math.ceil(seed.numel() * neg_sampling.amount)
  
      # TODO: Do not sample false negatives.
      if node_time is None:
          return neg_sampling.sample(num_neg, num_nodes)
  
      # If we are in a temporal-sampling scenario, we need to respect the
      # timestamp of the given nodes we can use as negative examples.
      # That is, we can only sample nodes for which `node_time <= seed_time`.
      # For now, we use a greedy algorithm which randomly samples negative
      # nodes and discard any which do not respect the temporal constraint.
      # We iteratively repeat this process until we have sampled a valid node for
      # each seed.
      # TODO See if this greedy algorithm here can be improved.
      assert seed_time is not None
      num_samples = math.ceil(neg_sampling.amount)
      seed_time = seed_time.view(1, -1).expand(num_samples, -1)
  
      out = neg_sampling.sample(num_samples * seed.numel(), num_nodes)
      out = out.view(num_samples, seed.numel())
      mask = node_time[out] > seed_time  # holds all invalid samples.
      neg_sampling_complete = False
      for i in range(5):  # pragma: no cover
          num_invalid = int(mask.sum())
          if num_invalid == 0:
              neg_sampling_complete = True
              break
  
          # Greedily search for alternative negatives.
          out[mask] = tmp = neg_sampling.sample(num_invalid, num_nodes)
          mask[mask.clone()] = node_time[tmp] >= seed_time[mask]
  
      if not neg_sampling_complete:  # pragma: no cover
          # Not much options left. In that case, we set remaining negatives
          # to the node with minimum timestamp.
          out[mask] = node_time.argmin()
  
      return out.view(-1)[:num_neg]
  
imports: import copy
  import math
  import sys
  import warnings
  from typing import Callable, Dict, List, Optional, Tuple, Union
  import torch
  from torch import Tensor
  import torch_geometric.typing
  from torch_geometric.data import Data, FeatureStore, GraphStore, HeteroData, remote_backend_utils
  from torch_geometric.data.graph_store import EdgeLayout
  from torch_geometric.sampler import BaseSampler, EdgeSamplerInput, HeteroSamplerOutput, NegativeSampling, NodeSamplerInput, SamplerOutput
  from torch_geometric.sampler.base import DataType, NumNeighbors, SubgraphType
  from torch_geometric.sampler.utils import remap_keys, to_csc, to_hetero_csc
  from torch_geometric.typing import EdgeType, NodeType, OptTensor
label_desc: Use image node_id 3 for calling a global function with example usage: neg_sample(seed, neg_sampling, num_nodes, seed_time, node_time) and returns: out, neg_sampling