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

Function get_res_by_refhdl

imperative/python/src/tensor_utils.cpp:388–418  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

386}
387
388py::object get_res_by_refhdl(
389 py::handle value, py::handle dtype, py::handle device, py::handle ref_hdl) {
390 py::object res = _Const(value, dtype, device);
391 py::object ref;
392 if (py::isinstance<py::tuple>(ref_hdl)) {
393 py::tuple tup = py::reinterpret_borrow<py::tuple>(ref_hdl);
394 if (tup.size()) {
395 ref = tup[0];
396 } else {
397 ref = py::none();
398 }
399 } else {
400 ref = py::reinterpret_borrow<py::object>(ref_hdl);
401 }
402 if (PyObject_TypeCheck(ref.ptr(), py_varnode_type)) {
403 ComputingGraph* graph = getattr(ref, "graph").cast<ComputingGraph*>();
404 cg::VarNode* node = getattr(ref, "var").cast<cg::VarNode*>();
405 CompNode cn;
406 if (device.ptr() == Py_None) {
407 cn = node->comp_node();
408 } else {
409 cn = device2obj(device).cast<CompNode>();
410 }
411 OperatorNodeConfig config(cn);
412 auto hv = npy::np2tensor(
413 value.ptr(), npy::Meth::borrow(cn), dtype.cast<mgb::DType>());
414 auto typeobj = ref.get_type();
415 return typeobj(opr::ImmutableTensor::make(*graph, hv, config).node());
416 }
417 return res;
418}
419
420mgb::DType _get_dtype(py::handle tensor) {
421 auto* tw = TensorWrapper::try_cast(tensor.ptr());

Callers 1

_astensor1d_cppFunction · 0.85

Calls 9

_ConstFunction · 0.85
device2objFunction · 0.85
np2tensorFunction · 0.85
makeFunction · 0.50
sizeMethod · 0.45
ptrMethod · 0.45
comp_nodeMethod · 0.45
get_typeMethod · 0.45
nodeMethod · 0.45

Tested by

no test coverage detected