| 364 | } |
| 365 | |
| 366 | HostTensorArgs 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 | |
| 390 | struct PyArgDesc { |
| 391 | const char* name; |
no test coverage detected