| 1274 | } |
| 1275 | |
| 1276 | py::object _getitem_cpp(py::handle inp_hdl, py::handle idx_hdl) { |
| 1277 | py::tuple try_res = _try_cond_take(inp_hdl, idx_hdl); |
| 1278 | if (try_res.size() == 2) { |
| 1279 | return try_res[0]; |
| 1280 | } |
| 1281 | py::tuple tuple_val; |
| 1282 | if (py::isinstance<py::tuple>(idx_hdl)) { |
| 1283 | tuple_val = py::reinterpret_borrow<py::tuple>(idx_hdl); |
| 1284 | } else { |
| 1285 | tuple_val = _get_tuple_idx(idx_hdl); |
| 1286 | } |
| 1287 | if (subtensor_fastpath(inp_hdl, tuple_val)) { |
| 1288 | return _fastpath_getitem_cpp(inp_hdl, tuple_val); |
| 1289 | } |
| 1290 | py::tuple up = _unpack_indexes(inp_hdl, tuple_val); |
| 1291 | py::object tensor = py::reinterpret_borrow<py::object>(up[0]); |
| 1292 | py::list tensors = py::reinterpret_borrow<py::list>(up[1]); |
| 1293 | py::list py_items = py::reinterpret_borrow<py::list>(up[2]); |
| 1294 | std::vector<std::tuple<int8_t, bool, bool, bool, bool>> cpp_items; |
| 1295 | std::vector<std::tuple<int32_t, int32_t, int32_t, int32_t>> slice_items; |
| 1296 | for (size_t i = 0; i < py_items.size(); ++i) { |
| 1297 | py::list item = py::reinterpret_borrow<py::list>(py_items[i]); |
| 1298 | cpp_items.push_back( |
| 1299 | {item[0].cast<int8_t>(), item[1].cast<bool>(), item[2].cast<bool>(), |
| 1300 | item[3].cast<bool>(), item[4].cast<bool>()}); |
| 1301 | } |
| 1302 | std::shared_ptr<OpDef> op; |
| 1303 | if (up[3].cast<bool>()) { |
| 1304 | op = Subtensor::make(cpp_items, slice_items); |
| 1305 | } else { |
| 1306 | op = IndexingMultiAxisVec::make(cpp_items); |
| 1307 | } |
| 1308 | std::vector<PyObject*> p; |
| 1309 | p.resize(tensors.size() + 2); |
| 1310 | py::object Op = py::cast(op); |
| 1311 | p[0] = Op.ptr(); |
| 1312 | p[1] = tensor.ptr(); |
| 1313 | for (size_t i = 0; i < tensors.size(); ++i) { |
| 1314 | p[i + 2] = tensors[i].ptr(); |
| 1315 | } |
| 1316 | py::tuple ret = |
| 1317 | py::reinterpret_steal<py::object>(py_apply(NULL, p.data(), p.size())); |
| 1318 | return ret[0]; |
| 1319 | } |
| 1320 | |
| 1321 | py::object _setitem_cpp(py::handle inp_hdl, py::handle idx_hdl, py::handle val_hdl) { |
| 1322 | py::object org_shape = getattr(inp_hdl, "shape"); |
no test coverage detected