Skip to content
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

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

AlenkaF
Copy link
Member

@AlenkaF AlenkaF commented Jun 12, 2024

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 and ExportTensorDevice methods on Arrow C++ Tensor class
  • __dlpack__ method on PyArrow Tensor class exposing ExportTensor method
  • __dlpack_device__ method on PyArrow Tensor class exposing ExportTensorDevice method

Are these changes tested?

Yes

Are there any user-facing changes?

No

@github-actions github-actions bot added awaiting changes Awaiting changes and removed awaiting review Awaiting review labels Jun 12, 2024
@github-actions github-actions bot added awaiting change review Awaiting change review and removed awaiting changes Awaiting changes labels Jun 12, 2024
@github-actions github-actions bot added awaiting changes Awaiting changes and removed awaiting change review Awaiting change review labels Jun 13, 2024
@github-actions github-actions bot added awaiting change review Awaiting change review and removed awaiting changes Awaiting changes labels Jun 13, 2024
Comment on lines +164 to +168
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();
}
Copy link
Member

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)

@github-actions github-actions bot added awaiting changes Awaiting changes and removed awaiting change review Awaiting change review labels Jun 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants