code: def _make_phylogeny(leaf_times, coal_times):
      assert leaf_times.size(-1) == 1 + coal_times.size(-1)
  
      # Expand shapes to match.
      N = leaf_times.size(-1)
      batch_shape = broadcast_shape(
          leaf_times.shape[:-1], coal_times.shape[:-1]
      )
      if leaf_times.shape[:-1] != batch_shape:
          leaf_times = leaf_times.expand(batch_shape + (N,))
      if coal_times.shape[:-1] != batch_shape:
          coal_times = coal_times.expand(batch_shape + (N - 1,))
  
      # Combine N sampling events (leaf_times) plus N-1 coalescent events
      # (coal_times) into a pair (times, signs) of arrays of length 2N-1, where
      # leaf sample sign is +1 and coalescent sign is -1.
      times = torch.cat([coal_times, leaf_times], dim=-1)
      signs = torch.linspace(
          1.5 - N, N - 0.5, 2 * N - 1
      ).sign()  # e.g. [-1, -1, +1, +1, +1]
  
      # Sort the events reverse-ordered in time, i.e. latest to earliest.
      times, index = times.sort(dim=-1, descending=True)
      signs = signs[index]
      inv_index = index.new_empty(index.shape)
      inv_index.scatter_(
          -1, index, torch.arange(2 * N - 1).expand_as(index)
      )
  
      # Compute the number n of lineages preceding each event, then the binomial
      # coefficients that will multiply the base coalescence rate.
      lineages = signs.cumsum(-1)
      binomial = lineages * (lineages - 1) / 2
  
      # Compute the binomial coefficient following each coalescent event.
      coal_index = inv_index[..., : N - 1]
      coal_binomial = binomial.gather(-1, coal_index - 1)
  
      return _Phylogeny(times, signs, lineages, binomial, coal_binomial)
  
imports: import functools
  import weakref
  from collections import namedtuple
  import torch
  from torch.distributions import constraints
  from pyro.distributions.util import broadcast_shape, is_validation_enabled
  from pyro.ops.special import safe_log
  from .torch_distribution import TorchDistribution
label_desc: Use image node_id 6 for calling a global function with example usage: _make_phylogeny(leaf_times, coal_times) and returns: _Phylogeny