Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

array protocol support on memory sharing #18561

Closed
szha opened this issue Jun 14, 2020 · 0 comments · Fixed by #18562
Closed

array protocol support on memory sharing #18561

szha opened this issue Jun 14, 2020 · 0 comments · Fixed by #18562

Comments

@szha
Copy link
Member

szha commented Jun 14, 2020

Description

For arrays that share memory, np.may_share_memory doesn't work for numpy types yet.

import mxnet as mx
import numpy as _np
np_array = _np.ones((3,5))
mx_nd_array = mx.nd.from_numpy(np_array, zero_copy=True)
mx_np_array = mx_nd_array.as_np_ndarray()
mx_np_array[0, 0] = 2

In [42]: mx_np_array
Out[42]:
array([[2., 1., 1., 1., 1.],
       [1., 1., 1., 1., 1.],
       [1., 1., 1., 1., 1.]], dtype=float64)

In [43]: mx_nd_array
Out[43]:

[[2. 1. 1. 1. 1.]
 [1. 1. 1. 1. 1.]
 [1. 1. 1. 1. 1.]]
<NDArray 3x5 @cpu(0)>

In [44]: np_array
Out[44]:
array([[2., 1., 1., 1., 1.],
       [1., 1., 1., 1., 1.],
       [1., 1., 1., 1., 1.]])

Then, if we call np.may_share_memory(np_array, mx_np_array) or np.may_share_memory(np_array, mx_nd_array), it returns

TypeError: no implementation found for 'numpy.may_share_memory' on types that implement __array_function__: [<class 'numpy.ndarray'>, <class 'mxnet.numpy.ndarray'>]

It works for _np.may_share_memory(mx_nd_array, mx_np_array) though

True
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants