MCPcopy Create free account
hub / github.com/apache/tvm-ffi / RegisterReflection

Method RegisterReflection

tests/cpp/testing_object.h:90–110  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

88};
89
90inline void TIntObj::RegisterReflection() {
91 namespace refl = tvm::ffi::reflection;
92 refl::ObjectDef<TIntObj>()
93 .def_ro("value", &TIntObj::value)
94 .def_static("static_add", &TInt::StaticAdd, "static add method");
95 // define extra type attributes
96 refl::TypeAttrDef<TIntObj>()
97 .def("test.GetValue", &TIntObj::GetValue)
98 .attr("test.size", sizeof(TIntObj))
99 .attr(refl::type_attr::kAnyHash, reinterpret_cast<void*>(&TInt::CustomAnyHash))
100 .attr(refl::type_attr::kAnyEqual, reinterpret_cast<void*>(&TInt::CustomAnyEqual));
101 // custom json serialization
102 refl::TypeAttrDef<TIntObj>()
103 .def(refl::type_attr::kDataToJson,
104 [](const TIntObj* self) -> Map<String, Any> {
105 return Map<String, Any>{{"value", self->value}};
106 })
107 .def(refl::type_attr::kDataFromJson, [](Map<String, Any> json_obj) -> TInt {
108 return TInt(json_obj["value"].cast<int64_t>());
109 });
110}
111
112class TFloatObj : public TNumberObj {
113 public:

Callers

nothing calls this directly

Calls 3

default_valueClass · 0.85
attrMethod · 0.80
TIntClass · 0.70

Tested by

no test coverage detected