def insert_pyfunc(func, Tout, stateful, name, *args):  # pylint: disable=invalid-name
  """Calls tf.py_func and inserts the `func` in the internal registry."""
  result = tf.compat.v1.py_func(
      func, inp=list(args), Tout=Tout, stateful=stateful, name=name)
  # A py_func can either return a tensor or a list. Since we care only about the
  # op, it doesn't matter which result we take.
  if isinstance(result, list):
    first_result = result[0] if result else None
  else:
    first_result = result
  if first_result is None:
    raise ValueError('func must return a tensor or list of tensors')
  token = first_result.op.node_def.attr['token'].s
  tf.compat.v1.add_to_collection(_PYFUNC_COLLECTION_KEY,
                                 _PyFuncDef(token, func))
  return result
Calls tf.py_func and inserts the `func` in the internal registry.
tensorflow_transform/py_func/pyfunc_helper.py