_pickle.py 954 B

123456789101112131415161718192021222324252627282930313233343536
  1. # These functions are referenced from the pickle archives produced by
  2. # ScriptModule.save()
  3. # These (`build_*`) functions used to be used by `pickler.cpp` to specify
  4. # the type of the list for certain special types, but now all lists get
  5. # a type attached and restored via `restore_type_tag` below. The legacy
  6. # functions should stick around for backwards-compatibility.
  7. def build_intlist(data):
  8. return data
  9. def build_tensorlist(data):
  10. return data
  11. def build_doublelist(data):
  12. return data
  13. def build_boollist(data):
  14. return data
  15. def build_tensor_from_id(data):
  16. if isinstance(data, int):
  17. # just the id, can't really do anything
  18. return data
  19. def restore_type_tag(value, type_str):
  20. # The type_ptr is used by the jit unpickler to restore the full static type
  21. # to container types like list when they are re-loaded, but this doesn't
  22. # matter for Python, so just return the plain value
  23. return value