mirror of
https://github.com/pytorch/pytorch.git
synced 2025-11-05 16:44:58 +08:00
[JIT] clang-format JIT code (#35115)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/35115 This commit runs the newly added tools/clang_format.py on the JIT codebase and includes all of the formatting changes thus produced. Testing: Ran the script, CI. Test Plan: Imported from OSS Reviewed By: eellison Differential Revision: D20568523 Pulled By: SplitInfinity fbshipit-source-id: e09bdb982ccf090eecfb7c7b461b8d0681eef82b
This commit is contained in:
committed by
Facebook GitHub Bot
parent
1422d2cd8b
commit
6384c2d81b
@ -1,6 +1,6 @@
|
||||
#include <torch/csrc/jit/python/python_arg_flatten.h>
|
||||
#include <torch/csrc/utils/six.h>
|
||||
#include <torch/csrc/utils/python_strings.h>
|
||||
#include <torch/csrc/utils/six.h>
|
||||
|
||||
#include <torch/csrc/autograd/grad_mode.h>
|
||||
|
||||
@ -49,7 +49,7 @@ void flatten_rec(PyObject* obj, ParsedArgs& args) {
|
||||
} else if (PyDict_Check(obj)) {
|
||||
auto dict_items = PyDict_Items(obj);
|
||||
structure.push_back(D::DictOpen);
|
||||
for (auto item : py::reinterpret_borrow<py::list>(dict_items)){
|
||||
for (auto item : py::reinterpret_borrow<py::list>(dict_items)) {
|
||||
flatten_rec(item.ptr(), args);
|
||||
}
|
||||
structure.push_back(D::DictClose);
|
||||
@ -95,7 +95,7 @@ py::object cast_sequence(std::vector<py::object> objs) {
|
||||
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 (size_t i = 0; i < num_objs; ++i) {
|
||||
py::tuple obj = py::reinterpret_borrow<py::tuple>(objs[i]);
|
||||
sequence[obj[0]] = std::move(obj[1]);
|
||||
}
|
||||
@ -112,19 +112,22 @@ py::object unflatten_rec(
|
||||
if (type == D::TupleOpen) {
|
||||
std::vector<py::object> objs;
|
||||
while (*desc_it != D::TupleClose)
|
||||
objs.push_back(unflatten_rec(var_it, var_it_end, desc_it, str_it, str_it_end));
|
||||
objs.push_back(
|
||||
unflatten_rec(var_it, var_it_end, desc_it, str_it, str_it_end));
|
||||
++desc_it;
|
||||
return cast_sequence<py::tuple>(objs);
|
||||
} else if (type == D::ListOpen) {
|
||||
std::vector<py::object> objs;
|
||||
while (*desc_it != D::ListClose)
|
||||
objs.push_back(unflatten_rec(var_it, var_it_end, desc_it,str_it, str_it_end));
|
||||
objs.push_back(
|
||||
unflatten_rec(var_it, var_it_end, desc_it, str_it, str_it_end));
|
||||
++desc_it;
|
||||
return cast_sequence<py::list>(objs);
|
||||
} else if (type == D::DictOpen) {
|
||||
std::vector<py::object> objs;
|
||||
while (*desc_it != D::DictClose){
|
||||
objs.push_back(unflatten_rec(var_it, var_it_end, desc_it,str_it, str_it_end));
|
||||
while (*desc_it != D::DictClose) {
|
||||
objs.push_back(
|
||||
unflatten_rec(var_it, var_it_end, desc_it, str_it, str_it_end));
|
||||
}
|
||||
++desc_it;
|
||||
return cast_dict(objs);
|
||||
@ -133,8 +136,7 @@ py::object unflatten_rec(
|
||||
throw std::runtime_error("Not enough Variables given to unflatten");
|
||||
auto str = *str_it++;
|
||||
return py::reinterpret_borrow<py::object>(THPUtils_packString(str));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (var_it == var_it_end)
|
||||
throw std::runtime_error("Not enough Variables given to unflatten");
|
||||
auto var = *var_it++;
|
||||
|
||||
Reference in New Issue
Block a user