MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / _get_tuple_idx

Function _get_tuple_idx

imperative/python/src/tensor_utils.cpp:1253–1274  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1251}
1252
1253py::tuple _get_tuple_idx(py::handle idx_hdl) {
1254 if (py::isinstance<py::list>(idx_hdl)) {
1255 bool is_all_int = true;
1256 py::list idx = py::reinterpret_borrow<py::list>(idx_hdl);
1257 for (size_t i = 0; i < idx.size(); i++) {
1258 if (py::int_::check_(idx[i])) {
1259 continue;
1260 } else if (py::float_::check_(idx[i])) {
1261 throw py::value_error("float idx is vaild in subtensor");
1262 } else {
1263 is_all_int = false;
1264 }
1265 }
1266 if (is_all_int) {
1267 return py::make_tuple(idx_hdl);
1268 } else {
1269 return py::tuple(idx);
1270 }
1271 } else {
1272 return py::make_tuple(idx_hdl);
1273 }
1274}
1275
1276py::object _getitem_cpp(py::handle inp_hdl, py::handle idx_hdl) {
1277 py::tuple try_res = _try_cond_take(inp_hdl, idx_hdl);

Callers 1

_getitem_cppFunction · 0.85

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected