sxjscience opened a new issue #18341:
URL: https://github.com/apache/incubator-mxnet/issues/18341
## Description
In the legacy NDArray API, we have the `to_dlpack` and `from_dlpack`
functionality that facilitates us to convert to/from pytorch tensors. We should
port these features to the new numpy interface:
```python
mx.npx.from_dlpack(...)
mx.npx.to_dlpack(...)
```
Currently, we are able to workaround via
```python
import torch as th
import mxnet as mx
from torch.utils.dlpack import to_dlpack
mx.npx.set_np()
a_th = th.ones(10, 10)
a_mx_np = mx.nd.from_dlpack(to_dlpack(a_th)).as_np_ndarray()
print(a_mx_np)
```
Out:
```
[[1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]
[1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]
[1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]
[1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]
[1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]
[1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]
[1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]
[1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]
[1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]
[1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]]
```
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]