irange-ify 11 (#62121)

Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/62121

Test Plan: Sandcastle

Reviewed By: ngimel

Differential Revision: D29879701

fbshipit-source-id: 5c51879c88fa6a5790db241c8b33ec0dc4b177ca
This commit is contained in:
Richard Barnes
2021-07-28 13:28:39 -07:00
committed by Facebook GitHub Bot
parent b5867a1b34
commit 9e77113e85
9 changed files with 33 additions and 22 deletions

View File

@ -1,3 +1,4 @@
#include <c10/util/irange.h>
#include <torch/csrc/jit/python/python_arg_flatten.h>
#include <torch/csrc/utils/python_strings.h>
#include <torch/csrc/utils/six.h>
@ -33,8 +34,9 @@ template <typename T>
py::object cast_handle_sequence(std::vector<py::handle> objs) {
auto num_objs = objs.size();
T sequence{num_objs};
for (size_t i = 0; i < num_objs; ++i)
for (const auto i : c10::irange(num_objs)) {
sequence[i] = py::reinterpret_borrow<py::object>(objs[i]);
}
return sequence;
}
@ -109,15 +111,16 @@ template <typename T>
py::object cast_sequence(std::vector<py::object> objs) {
auto num_objs = objs.size();
T sequence{num_objs};
for (size_t i = 0; i < num_objs; ++i)
for (const auto i : c10::irange(num_objs)) {
sequence[i] = std::move(objs[i]);
}
return std::move(sequence);
}
py::object cast_dict(std::vector<py::object> objs) {
auto num_objs = objs.size();
py::dict sequence = {};
for (size_t i = 0; i < num_objs; ++i) {
for (const auto i : c10::irange(num_objs)) {
py::tuple obj = py::reinterpret_borrow<py::tuple>(objs[i]);
sequence[obj[0]] = obj[1];
}