MCPcopy Index your code
hub / github.com/apache/tvm / get

Method get

python/tvm/testing/utils.py:975–1019  ·  view source on GitHub ↗

Overrides behavior of copy.deepcopy to avoid implicit copy. By default, copy.deepcopy uses a dict of id->object to track all objects that it has seen, which is passed as the second argument to all recursive calls. This class is intended to be passed in instead, and

(self, key, *args, **kwargs)

Source from the content-addressed store, hash-verified

973 super().__init__()
974
975 def get(self, key, *args, **kwargs):
976 """Overrides behavior of copy.deepcopy to avoid implicit copy.
977
978 By default, copy.deepcopy uses a dict of id->object to track
979 all objects that it has seen, which is passed as the second
980 argument to all recursive calls. This class is intended to be
981 passed in instead, and inspects the type of all objects being
982 copied.
983
984 Where copy.deepcopy does a best-effort attempt at copying an
985 object, for unit tests we would rather have all objects either
986 be copied correctly, or to throw an error. Classes that
987 define an explicit method to perform a copy are allowed, as
988 are any explicitly listed classes. Classes that would fall
989 back to using object.__reduce__, and are not explicitly listed
990 as safe, will throw an exception.
991
992 """
993 obj = ctypes.cast(key, ctypes.py_object).value
994 cls = type(obj)
995 if (
996 cls in copy._deepcopy_dispatch
997 or issubclass(cls, type)
998 or getattr(obj, "__deepcopy__", None)
999 or copyreg.dispatch_table.get(cls)
1000 or cls.__reduce__ is not object.__reduce__
1001 or cls.__reduce_ex__ is not object.__reduce_ex__
1002 or cls in self.allowed_class_list
1003 ):
1004 return super().get(key, *args, **kwargs)
1005
1006 rfc_url = (
1007 "https://github.com/apache/tvm-rfcs/blob/main/rfcs/0007-parametrized-unit-tests.md"
1008 )
1009 raise TypeError(
1010 f"Cannot copy fixture of type {cls.__name__}. TVM fixture caching "
1011 "is limited to objects that explicitly provide the ability "
1012 "to be copied (e.g. through __deepcopy__, __getstate__, or __setstate__),"
1013 "and forbids the use of the default `object.__reduce__` and "
1014 "`object.__reduce_ex__`. For third-party classes that are "
1015 "safe to use with copy.deepcopy, please add the class to "
1016 "the arguments of _DeepCopyAllowedClasses in tvm.testing._fixture_cache.\n"
1017 "\n"
1018 f"For discussion on this restriction, please see {rfc_url}."
1019 )
1020
1021
1022def _fixture_cache(func):

Callers 6

_get_targetsFunction · 0.45
_tvm_test_targetsFunction · 0.45
fixtureFunction · 0.45
_target_to_requirementFunction · 0.45
_build_flag_enabledFunction · 0.45
has_adreno_openclFunction · 0.45

Calls 1

castMethod · 0.45

Tested by

no test coverage detected