code: def wrapped_transform(x, fn, *, validate_args=True):
      """
      Wrapper for a backend ``Transform`` object that provides ``.inv`` and
      ``.log_abs_det_jacobian``. This additionally validates shapes on the first
      :meth:`__call__`.
      """
      if not validate_args:
          return fn(x)
  
      try:
          # Check for shape metadata available after
          # https://github.com/pytorch/pytorch/pull/50547
          # https://github.com/pytorch/pytorch/pull/50581
          # https://github.com/pyro-ppl/pyro/pull/2739
          # https://github.com/pyro-ppl/numpyro/pull/876
          fn.domain.event_dim
          fn.codomain.event_dim
          fn.forward_shape
      except AttributeError:
          backend = fn.__module__.split(".")[0]
          raise NotImplementedError(
              f"{fn} is missing shape metadata; try upgrading backend {backend}"
          )
  
      if len(x.shape) < fn.domain.event_dim:
          raise ValueError(
              f"Too few dimensions for input, in {fn.__name_}"
          )
      event_shape = x.shape[len(x.shape) - fn.domain.event_dim :]
      shape = fn.forward_shape(event_shape)
      if len(shape) > fn.codomain.event_dim:
          raise ValueError(
              f"Cannot treat transform {_get_name(fn)} as an Op because it is batched"
          )
  
      return fn(x)
  
imports: import contextlib
  import functools
  import inspect
  import weakref
  from collections import OrderedDict
  from funsor.registry import PartialDispatcher
  from funsor.util import methodof
label_desc: Use image node_id 8 for calling a global function with example usage: wrapped_transform(x, fn) and returns: fn, fn