-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GH-39294: [C++][Python] DLPack on Tensor class #42118
base: main
Are you sure you want to change the base?
Conversation
std::vector<int64_t>* strides_arr = &ctx->strides; | ||
strides_arr->resize(t->ndim()); | ||
for (int i = 0; i < t->ndim(); i++) { | ||
(*strides_arr)[i] = t->strides().data()[i] / t->type()->byte_width(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am entirely sure if this was written this way for performance, but my feeling is that this is quite complicated written, and you should also be able to just iterate through the values in t->strides()
and add them to &ctx->strides
with more standard std::vector functionality.
(for example, have a look at FixedShapeTensorArray::FromTensor
how some of the vectors are being created)
Rationale for this change
Producing part of DLPack protocol has been added to Arrow Arrays but is missing on Arrow Tensor class.
What changes are included in this PR?
This PR adds support for producing DLPack struct and bindings to it in Python:
ExportTensor
andExportTensorDevice
methods on Arrow C++ Tensor class__dlpack__
method on PyArrow Tensor class exposing ExportTensor method__dlpack_device__
method on PyArrow Tensor class exposing ExportTensorDevice methodAre these changes tested?
Yes
Are there any user-facing changes?
No