code: def _systematic_sample(probs):
      # Systematic sampling preserves diversity better than multinomial sampling
      # via Categorical(probs).sample().
      batch_shape, size = probs.shape[:-1], probs.size(-1)
      n = (
          probs.cumsum(-1)
          .mul_(size)
          .add_(torch.rand(batch_shape + (1,)))
      )
      n = n.floor_().clamp_(min=0, max=size).long()
      diff = probs.new_zeros(batch_shape + (size + 1,))
      diff.scatter_add_(-1, n, torch.ones_like(probs))
      index = diff[..., :-1].cumsum(-1).long()
      return index
  
imports: import contextlib
  import math
  import torch
  import pyro
  import pyro.distributions
  import pyro.poutine
  from pyro.infer.util import is_validation_enabled
  from pyro.poutine.util import prune_subsample_sites
label_desc: Use image node_id 1 for calling a global function with example usage: _systematic_sample(probs) and returns: index