MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / cast

Method cast

imperative/python/src/ops.cpp:501–518  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

499 return true;
500}
501handle type_caster<OpDef>::cast(const OpDef& op, return_value_policy, handle) {
502 if (auto* pyop = op.try_cast_final<GenericPyOp>()) {
503 return object(pyop->obj).release();
504 }
505 PyTypeObject* pytype;
506 auto& c2p = PyOp(OpDef)::ctype2pytype;
507 auto&& iter = c2p.find(op.dyn_typeinfo());
508 if (iter != c2p.end()) { // FIXME: should always meet this condition
509 pytype = iter->second;
510 } else { // which means unregistered op type, jsut make it as an opaque op type
511 // currently, only OprAttr goes into this branch
512 pytype = &PyOpType(OpDef);
513 }
514 PyObject* obj = pytype->tp_alloc(pytype, 0);
515 mgb_assert(PyObject_TypeCheck(obj, &PyOpType(OpDef)));
516 reinterpret_cast<PyOp(OpDef)*>(obj)->op = const_cast<OpDef&>(op).shared_from_this();
517 return py::handle(obj);
518}
519
520#define ENUM_CASTER_IMPL(T) \
521 bool type_caster<T>::load(handle src, bool) { \

Callers 9

apply_transformationMethod · 0.45
dynamic_castFunction · 0.45
dynamic_castFunction · 0.45
__init__Method · 0.45
__init__Method · 0.45
print_small_tensorFunction · 0.45
childrenMethod · 0.45
__call__Method · 0.45
__call__Method · 0.45

Calls 4

shared_from_thisMethod · 0.80
releaseMethod · 0.45
findMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected