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

Function CastPyArg2Longs

paddle/fluid/pybind/op_function_common.cc:696–766  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

694}
695
696std::vector<int64_t> CastPyArg2Longs(PyObject* obj,
697 const std::string& op_type,
698 ssize_t arg_pos) {
699 std::vector<int64_t> value;
700 if (PyList_Check(obj)) {
701 Py_ssize_t len = PyList_Size(obj);
702 PyObject* item = nullptr;
703 for (Py_ssize_t i = 0; i < len; i++) {
704 item = PyList_GetItem(obj, i);
705 if (PyObject_CheckLong(item)) {
706 value.emplace_back(PyObject_ToInt64(item));
707 } else {
708 PADDLE_THROW(common::errors::InvalidType(
709 "%s(): argument (position %d) must be "
710 "list of int, but got %s at pos %d",
711 op_type,
712 arg_pos + 1,
713 ((PyTypeObject*)item->ob_type)->tp_name, // NOLINT
714 i));
715 }
716 }
717 } else if (PyTuple_Check(obj)) {
718 Py_ssize_t len = PyTuple_Size(obj);
719 PyObject* item = nullptr;
720 for (Py_ssize_t i = 0; i < len; i++) {
721 item = PyTuple_GetItem(obj, i);
722 if (PyObject_CheckLong(item)) {
723 value.emplace_back(PyObject_ToInt64(item));
724 } else {
725 PADDLE_THROW(common::errors::InvalidType(
726 "%s(): argument (position %d) must be "
727 "list of int, but got %s at pos %d",
728 op_type,
729 arg_pos + 1,
730 ((PyTypeObject*)item->ob_type)->tp_name, // NOLINT
731 i));
732 }
733 }
734 } else if (PySequence_Check(obj) && !PyObject_TypeCheck(obj, p_tensor_type)) {
735 Py_ssize_t len = PySequence_Size(obj);
736 PyObject* item = nullptr;
737 for (Py_ssize_t i = 0; i < len; i++) {
738 item = PySequence_GetItem(obj, i);
739 if (PyObject_CheckLong(item)) {
740 value.emplace_back(PyObject_ToInt64(item));
741 } else {
742 PADDLE_THROW(common::errors::InvalidType(
743 "%s(): argument (position %d) must be "
744 "list of int, but got %s at pos %d",
745 op_type,
746 arg_pos + 1,
747 ((PyTypeObject*)item->ob_type)->tp_name, // NOLINT
748 i));
749 }
750 Py_DECREF(item);
751 }
752 } else if (obj == Py_None) {
753 return {};

Callers 8

static_api_fullFunction · 0.85
static_api_slice_arrayFunction · 0.85
parse_attrsFunction · 0.85
CastPyArg2IntArrayFunction · 0.85
eager_api_run_custom_opFunction · 0.85
CastPyArg2AttrLongsFunction · 0.85
ArgSumMapperFunction · 0.85

Calls 3

PyObject_CheckLongFunction · 0.85
PyObject_ToInt64Function · 0.85
emplace_backMethod · 0.45

Tested by

no test coverage detected