question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Do we need from_dlpack when DLPack is supported by asarray?

See original GitHub issue

I guess one possible advantage of from_dlpack() is that it’s more explicit? If that’s desired, then perhaps we should add other explicit constructors like from_buffer(). Otherwise, it seems redundant with the generic asarray(), and I would lean towards removing it.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
rgommerscommented, May 8, 2021

Would it be better, then, to remove both DLPack and buffer protocol supports from asarray(), so it is more focused and has a separate responsibility from from_dlpack()?

I’m not sure, maybe. I’m fine removing just DLPack as well, or leaving as is, or removing both. I think idiomatic code would use:

  • from_dlpack for standard-compliant objects
  • asarray for converting scalars or sequences
  • preferably nothing else (because nothing else will have universal support)

It’s not great in a standard to have to deal with optional other protocols that are hard to test for. Saying the buffer protocol must/may be supported is not ideal in both cases. And __array_interface__ or __cuda_array_interface__ the same. I’d lean towards an explicit “may” if we want to do anything, not a “must”.

from the perspective of CUDA/ROCm whatever can be done using DLPack (without the Python methods) can also be done using the buffer protocol,

I’m not sure what this means, since the buffer protocol does not support GPUs. Do you mean __cuda_array_interface__ maybe?

1reaction
leofangcommented, Mar 30, 2021

from_dlpack is the one function that one should be using when converting one kind of array into another where you know both support the array API standard. It’s more explicit (signalling intent to the reader of code matters), reliable and fast.

I’d much rather remove buffer protocol support from asarray.

Would it be better, then, to remove both DLPack and buffer protocol supports from asarray(), so it is more focused and has a separate responsibility from from_dlpack()?

Read more comments on GitHub >

github_iconTop Results From Across the Web

DLPack support for NumPy · Issue #19013 - GitHub
If I use numpy but import a JAX array (unknowingly where it came from), I should have to know about NUMPY only. And...
Read more >
Interoperability — CuPy 11.4.0 documentation
It means you can pass CuPy arrays to kernels JITed with Numba. ... Tensor to cupy.from_dlpack() is only supported in the (new) DLPack...
Read more >
How to transfer CuPy arrays to tensorflow - Stack Overflow
DLPack tensor structure is now supported in Tensorflow 2 in the tf.experimental.dlpack package. You can find the howto usage in this repo: ...
Read more >
tf.experimental.dlpack.from_dlpack | TensorFlow v2.11.0
Returns the Tensorflow eager tensor. ... The returned tensor uses the memory shared by dlpack capsules from other framework. a = tf ...
Read more >
torch.asarray — PyTorch 1.13 documentation
Converts obj to a tensor. obj can be one of: ... When obj is a tensor, NumPy array, or DLPack capsule the returned...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found