class_docstr: Provenance tracking implementation in Pytorch.
  
  Provenance of the output tensor is the union of provenances of input tensors.
class_docstr_tok: ["Provenance","tracking","implementation","in","Pytorch",".","Provenance","of","the","output","tensor","is","the","union","of","provenances","of","input","tensors","."]
code: def __torch_function__(cls, func, types, args=(), kwargs=None):
      if kwargs is None:
          kwargs = {}
      # collect provenance information from args
      provenance = frozenset()
      # extract ProvenanceTensor._t data from args
      _args = []
      for arg in args:
          if isinstance(arg, ProvenanceTensor):
              provenance |= arg._provenance
              _args.append(arg._t)
          elif isinstance(arg, (tuple, list)):
              _arg = []
              for a in arg:
                  if isinstance(a, ProvenanceTensor):
                      provenance |= a._provenance
                      _arg.append(a._t)
                  else:
                      _arg.append(a)
              _args.append(tuple(_arg))
          else:
              _args.append(arg)
      ret = func(*_args, **kwargs)
      if isinstance(ret, torch.Tensor):
          return ProvenanceTensor(ret, provenance=provenance)
      if isinstance(ret, (tuple, list)):
          _ret = []
          for r in ret:
              if isinstance(r, torch.Tensor):
                  _ret.append(
                      ProvenanceTensor(r, provenance=provenance)
                  )
              else:
                  _ret.append(r)
          return type(ret)(_ret)
      return ret
  
imports: import torch
label_desc: Use image node_id 4 for calling the ProvenanceTensor obj's underlying member method code with example usage: obj.__torch_function__(cls, func, types, args, kwargs) and returns: ret, ProvenanceTensor, type