| 723 | } |
| 724 | |
| 725 | RefCountedPtr<ITensor> ViewAsTensor() const override { |
| 726 | if (!tl_->IsDenseTensor()) |
| 727 | throw std::runtime_error( |
| 728 | "Only a densely packed list of tensors of uniform shape can be viewed as a Tensor."); |
| 729 | |
| 730 | auto t = std::make_shared<Tensor<Backend>>(); |
| 731 | auto buf = unsafe_owner(*tl_); |
| 732 | auto &lshape = tl_->shape(); |
| 733 | TensorShape<> tshape = shape_cat(lshape.num_samples(), lshape[0]); |
| 734 | t->ShareData( |
| 735 | std::move(buf), |
| 736 | tl_->nbytes(), |
| 737 | tl_->is_pinned(), |
| 738 | tshape, |
| 739 | tl_->type(), |
| 740 | tl_->device_id(), |
| 741 | tl_->order(), |
| 742 | tl_->ready_event()); |
| 743 | TensorLayout layout = tl_->GetLayout(); |
| 744 | if (layout.size() == lshape.sample_dim()) { |
| 745 | t->SetLayout("N" + layout); |
| 746 | } |
| 747 | return Wrap(std::move(t)); |
| 748 | } |
| 749 | |
| 750 | void CopyOut( |
| 751 | void *dst_buffer, |
no test coverage detected