DOC: clarify DLPack GPU tensor example with device='cpu' workaround by crawfordxx · Pull Request #30989 · numpy/numpy · GitHub
Skip to content

DOC: clarify DLPack GPU tensor example with device='cpu' workaround#30989

Merged
rgommers merged 1 commit into
numpy:mainfrom
crawfordxx:doc-fix-dlpack-example-30936
Mar 13, 2026
Merged

DOC: clarify DLPack GPU tensor example with device='cpu' workaround#30989
rgommers merged 1 commit into
numpy:mainfrom
crawfordxx:doc-fix-dlpack-example-30936

Conversation

@crawfordxx

@crawfordxx crawfordxx commented Mar 11, 2026

Copy link
Copy Markdown
Contributor

PR summary

  • Update the DLPack example in the interoperability docs
  • Show that np.from_dlpack(x_torch, device='cpu') works for GPU tensors since DLPack v1 supports cross-device copy
  • Previous note was misleading: it implied GPU tensors cannot be converted to NumPy arrays at all

Closes #30936

First time committer introduction

I use NumPy extensively for numerical computing. This is my first contribution to the NumPy project.

AI Disclosure

No AI tools used.

Update the DLPack example in the interoperability docs to show that
since DLPack v1, cross-device copy is supported via the device parameter.
The example now shows that np.from_dlpack(x_torch, device='cpu') works
for GPU tensors.

Closes #30936

@mattip mattip left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks. Will let it sit for a bit so other reviewers can take a look.

@rgommers rgommers left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks @crawfordxx!

@rgommers rgommers added this to the 2.5.0 Release milestone Mar 13, 2026
@rgommers rgommers merged commit a0cbfd2 into numpy:main Mar 13, 2026
7 checks passed
@j-bowhay

Copy link
Copy Markdown
Contributor

@rgommers

Copy link
Copy Markdown
Member

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.

DOC: DLPack example in "Interoperability examples" misleading

4 participants