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

Commit 3bb21b1

Browse files
committed
add dispatch
1 parent 380bf03 commit 3bb21b1

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

python/mxnet/numpy_dispatch_protocol.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@ def _run_with_array_ufunc_proto(*args, **kwargs):
123123
'tril',
124124
'meshgrid',
125125
'outer',
126-
'einsum'
126+
'einsum',
127+
'shares_memory',
128+
'may_share_memory',
127129
]
128130

129131

tests/python/unittest/test_numpy_interoperability.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,6 +1070,8 @@ def _check_interoperability_helper(op_name, *args, **kwargs):
10701070

10711071
def check_interoperability(op_list):
10721072
for name in op_list:
1073+
if name in ['shares_memory', 'may_share_memory']: # skip list
1074+
continue
10731075
print('Dispatch test:', name)
10741076
workloads = OpArgMngr.get_workloads(name)
10751077
assert workloads is not None, 'Workloads for operator `{}` has not been ' \
@@ -1079,6 +1081,19 @@ def check_interoperability(op_list):
10791081
_check_interoperability_helper(name, *workload['args'], **workload['kwargs'])
10801082

10811083

1084+
@with_seed()
1085+
@use_np
1086+
@with_array_function_protocol
1087+
def test_np_memory_array_function():
1088+
ops = [_np.shares_memory, _np.may_share_memory]
1089+
for op in ops:
1090+
data_mx = np.zeros([13, 21, 23, 22], dtype=np.float32)
1091+
data_np = _np.zeros([13, 21, 23, 22], dtype=np.float32)
1092+
assert op(data_mx[0,:,:,:], data_mx[1,:,:,:]) == op(data_np[0,:,:,:], data_np[1,:,:,:])
1093+
assert op(data_mx[0,0,0,2:5], data_mx[0,0,0,4:7]) == op(data_np[0,0,0,2:5], data_np[0,0,0,4:7])
1094+
assert op(data_mx, np.ones((5, 0))) == op(data_np, _np.ones((5, 0)))
1095+
1096+
10821097
@with_seed()
10831098
@use_np
10841099
@with_array_function_protocol

0 commit comments

Comments
 (0)