8000 Perf nitpicks on python_arg_parser's is_int_or_symint_list · pytorch/pytorch@0ec9031 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0ec9031

Browse files
committed
Perf nitpicks on python_arg_parser's is_int_or_symint_list
This function has come up in DTensor perf work, and I had a nitpick on #160256 so here it is. I have neither compiled nor measured this, but am reasonably confident it's better nonetheless. [ghstack-poisoned]
1 parent dcf3853 commit 0ec9031

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

torch/csrc/utils/python_arg_parser.cpp

Copy file name to clipboard
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -962,15 +962,15 @@ static bool is_int_or_symint_list(
962962
int broadcast_size,
963963
int64_t* failed_idx = nullptr,
964964
std::vector<PyObject*>* overloaded_args = nullptr) {
965-
if (PyTuple_Check(obj) || PyList_Check(obj)) {
966-
if (PySequence_Size(obj) == 0) {
965+
const bool is_tuple = PyTuple_Check(obj);
966+
if (is_tuple || PyList_Check(obj)) {
967+
const auto size = is_tuple ? PyTuple_GET_SIZE(obj) : PyList_GET_SIZE(obj);
968+
if (size == 0) {
967969
return true;
968970
}
969971

970972
// Check all elements, not just the first one, when looking for torch
971973
// functions
972-
const bool is_tuple = PyTuple_Check(obj);
973-
const auto size = is_tuple ? PyTuple_GET_SIZE(obj) : PyList_GET_SIZE(obj);
974974
bool has_torch_func = false;
975975

976976
for (Py_ssize_t idx = 0; idx < size; idx++) {

0 commit comments

Comments
 (0)
0