zeroshade commented on code in PR #42118: URL: https://github.com/apache/arrow/pull/42118#discussion_r2047491267
########## cpp/src/arrow/c/dlpack.cc: ########## @@ -130,4 +131,71 @@ Result<DLDevice> ExportDevice(const std::shared_ptr<Array>& arr) { } } +struct TensorManagerCtx { + std::shared_ptr<Tensor> t; + std::vector<int64_t> strides; + std::vector<int64_t> shape; + DLManagedTensor tensor; +}; + +Result<DLManagedTensor*> ExportTensor(const std::shared_ptr<Tensor>& t) { + // Define the DLDataType struct + const DataType& type = *t->type(); + ARROW_ASSIGN_OR_RAISE(DLDataType dlpack_type, GetDLDataType(type)); + + // Define DLDevice struct + ARROW_ASSIGN_OR_RAISE(DLDevice device, ExportDevice(t)) + + // Create TensorManagerCtx that will serve as the owner of the DLManagedTensor + std::unique_ptr<TensorManagerCtx> ctx(new TensorManagerCtx); Review Comment: for stylistic reasons, `std::make_unique`? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org