MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / CastPyArg2VectorOfInt64

Function CastPyArg2VectorOfInt64

paddle/fluid/pybind/eager_utils.cc:569–615  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

567}
568
569std::vector<int64_t> CastPyArg2VectorOfInt64(PyObject* obj, size_t arg_pos) {
570 std::vector<int64_t> result;
571 if (PyList_Check(obj)) {
572 Py_ssize_t len = PyList_Size(obj);
573 PyObject* item = nullptr;
574 for (Py_ssize_t i = 0; i < len; i++) {
575 item = PyList_GET_ITEM(obj, i);
576 if (PyObject_CheckLong(item)) {
577 result.emplace_back(PyObject_ToInt64(item));
578 } else {
579 PADDLE_THROW(common::errors::InvalidType(
580 "argument (position %d) must be "
581 "list of int, but got %s at pos %d",
582 arg_pos + 1,
583 reinterpret_cast<PyTypeObject*>(item->ob_type)->tp_name,
584 i));
585 }
586 }
587 } else if (PyTuple_Check(obj)) {
588 Py_ssize_t len = PyTuple_Size(obj);
589 PyObject* item = nullptr;
590 for (Py_ssize_t i = 0; i < len; i++) {
591 item = PyTuple_GET_ITEM(obj, i);
592 if (PyObject_CheckLong(item)) {
593 result.emplace_back(PyObject_ToInt64(item));
594 } else {
595 PADDLE_THROW(common::errors::InvalidType(
596 "argument (position %d) must be "
597 "list of int, but got %s at pos %d",
598 arg_pos + 1,
599 reinterpret_cast<PyTypeObject*>(item->ob_type)->tp_name,
600 i));
601 }
602 }
603 } else if (obj == Py_None) {
604 return {};
605 } else if (PyObject_CheckLong(obj)) {
606 return {PyObject_ToInt64(obj)}; // NOLINT
607 } else {
608 PADDLE_THROW(common::errors::InvalidType(
609 "argument (position %d) must be "
610 "list or tuple, but got %s",
611 arg_pos + 1,
612 reinterpret_cast<PyTypeObject*>(obj->ob_type)->tp_name));
613 }
614 return result;
615}
616
617std::vector<size_t> CastPyArg2VectorOfSize_t(PyObject* obj, size_t arg_pos) {
618 std::vector<size_t> result;

Callers 4

static_api_run_custom_opFunction · 0.85
static_api_dist_reshapeFunction · 0.85

Calls 3

PyObject_CheckLongFunction · 0.85
PyObject_ToInt64Function · 0.85
emplace_backMethod · 0.45

Tested by

no test coverage detected