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

Function pyobj2hval

imperative/python/src/tensor.cpp:366–388  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

364}
365
366HostTensorArgs pyobj2hval(py::object obj, CompNode cn, DType dtype) {
367 HostTensorArgs ret;
368 bool success = false;
369 // check order: float -> int -> tuple(int -> float) -> list(int -> float)
370 // only handle `exact` pytype, isinstance also accepts subtype
371 // for example, isinstance(True, int) == True
372 if (obj.get_type().is(py_type<py::float_>())) {
373 success = pyfloat2hval(py::float_(obj), cn, dtype, ret);
374 } else if (obj.get_type().is(py_type<py::int_>())) { // py::bool_ is py::int_
375 success = pyint2hval(py::int_(obj), cn, dtype, ret);
376 } else if (obj.get_type().is(py_type<py::tuple>())) {
377 success = pyseq2hval<py::tuple>(py::tuple(obj), cn, dtype, ret);
378 } else if (obj.get_type().is(py_type<py::list>())) {
379 success = pyseq2hval<py::list>(py::list(obj), cn, dtype, ret);
380 } else if (obj.is_none()) {
381 obj = py::list(0);
382 }
383 if (!success) {
384 success = pyarr2hval(obj, cn, dtype, ret);
385 }
386 mgb_assert(success);
387 return ret;
388}
389
390struct PyArgDesc {
391 const char* name;

Callers 1

TensorWrapperMethod · 0.85

Calls 6

pyfloat2hvalFunction · 0.85
pyint2hvalFunction · 0.85
listFunction · 0.85
pyarr2hvalFunction · 0.85
isMethod · 0.45
get_typeMethod · 0.45

Tested by

no test coverage detected