| 1190 | |
| 1191 | template <typename Backend> |
| 1192 | std::unique_ptr<Tensor<Backend> > TensorListGetItemImpl(TensorList<Backend> &t, Index id) { |
| 1193 | int num_tensors = static_cast<int>(t.num_samples()); |
| 1194 | if (id < 0) { |
| 1195 | id = num_tensors + id; |
| 1196 | } |
| 1197 | if (id >= num_tensors || id < 0) { |
| 1198 | throw py::index_error("TensorListCPU index out of range"); |
| 1199 | } |
| 1200 | auto ptr = std::make_unique<Tensor<Backend>>(); |
| 1201 | // TODO(klecki): Rework this with proper sample-based tensor batch data structure |
| 1202 | auto &sample_shared_ptr = unsafe_sample_owner(t, id); |
| 1203 | auto &tshape = t.tensor_shape(id); |
| 1204 | size_t num_bytes = tshape.num_elements() * t.type_info().size(); |
| 1205 | ptr->ShareData(sample_shared_ptr, num_bytes, t.is_pinned(), tshape, t.type(), |
| 1206 | t.device_id(), t.order(), t.ready_event()); |
| 1207 | ptr->SetMeta(t.GetMeta(id)); |
| 1208 | return ptr; |
| 1209 | } |
| 1210 | |
| 1211 | template <typename Backend> |
| 1212 | constexpr uint32_t TensorListDLPackRangeColor() { |
no test coverage detected