code: def funsor_to_tensor(funsor_, ndims, event_inputs=()):
      """
      Convert a :class:`funsor.tensor.Tensor` to a :class:`torch.Tensor` .
  
      Note this should not touch data, but may trigger a
      :meth:`torch.Tensor.reshape` op.
  
      :param funsor.tensor.Tensor funsor_: A funsor.
      :param int ndims: The number of result dims, ``== result.dim()``.
      :param tuple event_inputs: Names assigned to rightmost dimensions.
      :return: A PyTorch tensor.
      :rtype: torch.Tensor
      """
      assert isinstance(funsor_, Tensor)
      assert all(
          k.startswith("_pyro_dim_") or k in event_inputs
          for k in funsor_.inputs
      )
  
      tensor = to_data(funsor_, default_name_to_dim(event_inputs))
  
      if ndims != tensor.dim():
          tensor = tensor.reshape(
              (1,) * (ndims - tensor.dim()) + tensor.shape
          )
      assert tensor.dim() == ndims
      return tensor
  
imports: import math
  from collections import OrderedDict
  import torch
  import funsor.ops
  from funsor.cnf import Contraction
  from funsor.delta import Delta
  from funsor.domains import Array, Bint, Real, Reals
  from funsor.gaussian import Gaussian
  from funsor.interpreter import gensym
  from funsor.tensor import Tensor
  from funsor.terms import Independent, Variable, to_data, to_funsor
label_desc: Use image node_id 4 for calling a global function with example usage: funsor_to_tensor(funsor_, ndims, event_inputs) and returns: tensor