From c560fa48ce850e6e8a95ab92fe76e3b4f8504df6 Mon Sep 17 00:00:00 2001 From: Xi Wang Date: Thu, 10 Oct 2019 10:36:00 +0000 Subject: [PATCH 1/5] tests added --- python/mxnet/numpy_dispatch_protocol.py | 4 ++++ .../unittest/test_numpy_interoperability.py | 22 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/python/mxnet/numpy_dispatch_protocol.py b/python/mxnet/numpy_dispatch_protocol.py index f483e299ffed..1d9afa5d1e76 100644 --- a/python/mxnet/numpy_dispatch_protocol.py +++ b/python/mxnet/numpy_dispatch_protocol.py @@ -111,6 +111,8 @@ def _run_with_array_ufunc_proto(*args, **kwargs): 'transpose', 'var', 'zeros_like', + 'meshgrid', + 'outer' ] @@ -194,6 +196,8 @@ def _register_array_function(): 'ceil', 'trunc', 'floor', + 'logical_not', + 'not_equal' ] diff --git a/tests/python/unittest/test_numpy_interoperability.py b/tests/python/unittest/test_numpy_interoperability.py index f0c205f72dc4..081872bd315e 100644 --- a/tests/python/unittest/test_numpy_interoperability.py +++ b/tests/python/unittest/test_numpy_interoperability.py @@ -66,6 +66,9 @@ def _prepare_workloads(): OpArgMngr.add_workload('min', array_pool['4x1']) OpArgMngr.add_workload('mean', array_pool['4x1']) OpArgMngr.add_workload('mean', array_pool['4x1'], axis=0, keepdims=True) + OpArgMngr.add_workload('mean', np.array([[1, 2, 3], [4, 5, 6]])) + OpArgMngr.add_workload('mean', np.array([[1, 2, 3], [4, 5, 6]]), axis=0) + OpArgMngr.add_workload('mean', np.array([[1, 2, 3], [4, 5, 6]]), axis=1) OpArgMngr.add_workload('ones_like', array_pool['4x1']) OpArgMngr.add_workload('prod', array_pool['4x1']) OpArgMngr.add_workload('repeat', array_pool['4x1'], 3) @@ -82,6 +85,8 @@ def _prepare_workloads(): OpArgMngr.add_workload('transpose', array_pool['4x1']) OpArgMngr.add_workload('var', array_pool['4x1']) OpArgMngr.add_workload('zeros_like', array_pool['4x1']) + OpArgMngr.add_workload('outer', np.ones((5)), np.ones((2))) + OpArgMngr.add_workload('outer', np.ones((5,)), np.linspace(-2, 2, 5), np.zeros(shape=(5,5))) # workloads for array ufunc protocol OpArgMngr.add_workload('add', array_pool['4x1'], array_pool['1x2']) @@ -100,6 +105,9 @@ def _prepare_workloads(): OpArgMngr.add_workload('power', array_pool['4x1'], 2) OpArgMngr.add_workload('power', 2, array_pool['4x1']) OpArgMngr.add_workload('power', array_pool['4x1'], array_pool['1x1x0']) + OpArgMngr.add_workload('power', np.array([1, 2, 3], np.int32), 2.00001) + OpArgMngr.add_workload('power', np.array([15, 15], np.int64), np.array([15, 15], np.int64)) + OpArgMngr.add_workload('power', 0, np.arange(1, 10)) OpArgMngr.add_workload('mod', array_pool['4x1'], array_pool['1x2']) OpArgMngr.add_workload('mod', array_pool['4x1'], 2) OpArgMngr.add_workload('mod', 2, array_pool['4x1']) @@ -123,6 +131,12 @@ def _prepare_workloads(): OpArgMngr.add_workload('exp', array_pool['4x1']) OpArgMngr.add_workload('log', array_pool['4x1']) OpArgMngr.add_workload('log2', array_pool['4x1']) + OpArgMngr.add_workload('log2', np.array(2.**65)) + OpArgMngr.add_workload('log2', np.array(np.inf)) + OpArgMngr.add_workload('log2', np.array(1.)) + OpArgMngr.add_workload('log1p', np.array(-1.)) + OpArgMngr.add_workload('log1p', np.array(np.inf)) + OpArgMngr.add_workload('log1p', np.array(1e-6)) OpArgMngr.add_workload('log10', array_pool['4x1']) OpArgMngr.add_workload('expm1', array_pool['4x1']) OpArgMngr.add_workload('sqrt', array_pool['4x1']) @@ -144,6 +158,14 @@ def _prepare_workloads(): OpArgMngr.add_workload('ceil', array_pool['4x1']) OpArgMngr.add_workload('trunc', array_pool['4x1']) OpArgMngr.add_workload('floor', array_pool['4x1']) + OpArgMngr.add_workload('logical_not', np.ones(10, dtype=np.int32)) + OpArgMngr.add_workload('logical_not', array_pool['4x1']) + OpArgMngr.add_workload('meshgrid', np.array([1, 2, 3])) + OpArgMngr.add_workload('meshgrid', np.array([1, 2, 3]), np.array([4, 5, 6, 7])) + OpArgMngr.add_workload('meshgrid', np.array([1, 2, 3]), np.array([4, 5, 6, 7]), indexing='ij') + OpArgMngr.add_workload('meshgrid', np.array([1, 2, 3]), np.array([4, 5, 6, 7]), sparse=True) + OpArgMngr.add_workload('not_equal', np.array([0, 0, 3, 2]), np.array([0, 4, 0, 2])) + _prepare_workloads() From 8ad774f58ee9e59728aa708b2da60823bdf9eab6 Mon Sep 17 00:00:00 2001 From: Xi Wang Date: Tue, 15 Oct 2019 03:17:11 +0000 Subject: [PATCH 2/5] remove not equal --- tests/python/unittest/test_numpy_interoperability.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/python/unittest/test_numpy_interoperability.py b/tests/python/unittest/test_numpy_interoperability.py index 081872bd315e..5df0679ae736 100644 --- a/tests/python/unittest/test_numpy_interoperability.py +++ b/tests/python/unittest/test_numpy_interoperability.py @@ -164,7 +164,6 @@ def _prepare_workloads(): OpArgMngr.add_workload('meshgrid', np.array([1, 2, 3]), np.array([4, 5, 6, 7])) OpArgMngr.add_workload('meshgrid', np.array([1, 2, 3]), np.array([4, 5, 6, 7]), indexing='ij') OpArgMngr.add_workload('meshgrid', np.array([1, 2, 3]), np.array([4, 5, 6, 7]), sparse=True) - OpArgMngr.add_workload('not_equal', np.array([0, 0, 3, 2]), np.array([0, 4, 0, 2])) From 10630ff520603d56c4b6158e6192de993b4fde78 Mon Sep 17 00:00:00 2001 From: Xi Wang Date: Tue, 15 Oct 2019 05:10:51 +0000 Subject: [PATCH 3/5] fix tiny bug --- python/mxnet/numpy_dispatch_protocol.py | 1 - 1 file changed, 1 deletion(-) diff --git a/python/mxnet/numpy_dispatch_protocol.py b/python/mxnet/numpy_dispatch_protocol.py index 1d9afa5d1e76..6fc9dc3648a1 100644 --- a/python/mxnet/numpy_dispatch_protocol.py +++ b/python/mxnet/numpy_dispatch_protocol.py @@ -197,7 +197,6 @@ def _register_array_function(): 'trunc', 'floor', 'logical_not', - 'not_equal' ] From 919e5240d244512aceecbb408ef033ef6e619ff8 Mon Sep 17 00:00:00 2001 From: Xi Wang Date: Wed, 16 Oct 2019 06:31:37 +0000 Subject: [PATCH 4/5] remove meshgrid test --- tests/python/unittest/test_numpy_interoperability.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/python/unittest/test_numpy_interoperability.py b/tests/python/unittest/test_numpy_interoperability.py index 5df0679ae736..4ab591b76a42 100644 --- a/tests/python/unittest/test_numpy_interoperability.py +++ b/tests/python/unittest/test_numpy_interoperability.py @@ -86,7 +86,8 @@ def _prepare_workloads(): OpArgMngr.add_workload('var', array_pool['4x1']) OpArgMngr.add_workload('zeros_like', array_pool['4x1']) OpArgMngr.add_workload('outer', np.ones((5)), np.ones((2))) - OpArgMngr.add_workload('outer', np.ones((5,)), np.linspace(-2, 2, 5), np.zeros(shape=(5,5))) + OpArgMngr.add_workload('meshgrid', np.array([1, 2, 3]), np.array([4, 5, 6, 7])) + OpArgMngr.add_workload('meshgrid', np.array([1, 2, 3]), np.array([4, 5, 6, 7]), indexing='ij') # workloads for array ufunc protocol OpArgMngr.add_workload('add', array_pool['4x1'], array_pool['1x2']) @@ -160,10 +161,8 @@ def _prepare_workloads(): OpArgMngr.add_workload('floor', array_pool['4x1']) OpArgMngr.add_workload('logical_not', np.ones(10, dtype=np.int32)) OpArgMngr.add_workload('logical_not', array_pool['4x1']) - OpArgMngr.add_workload('meshgrid', np.array([1, 2, 3])) - OpArgMngr.add_workload('meshgrid', np.array([1, 2, 3]), np.array([4, 5, 6, 7])) - OpArgMngr.add_workload('meshgrid', np.array([1, 2, 3]), np.array([4, 5, 6, 7]), indexing='ij') - OpArgMngr.add_workload('meshgrid', np.array([1, 2, 3]), np.array([4, 5, 6, 7]), sparse=True) + OpArgMngr.add_workload('logical_not', np.array([True, False, True, False], dtype=np.bool)) + From b90f24a02355e44a86abd64343c0d6001fc26bf7 Mon Sep 17 00:00:00 2001 From: Xi Wang Date: Wed, 16 Oct 2019 06:51:46 +0000 Subject: [PATCH 5/5] modify meshgrid return type, add test --- python/mxnet/numpy/stride_tricks.py | 2 +- tests/python/unittest/test_numpy_interoperability.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/python/mxnet/numpy/stride_tricks.py b/python/mxnet/numpy/stride_tricks.py index 1848a292e673..0b2fe523b0f3 100644 --- a/python/mxnet/numpy/stride_tricks.py +++ b/python/mxnet/numpy/stride_tricks.py @@ -51,6 +51,6 @@ def broadcast_arrays(*args): if all(array.shape == shape for array in args): # Common case where nothing needs to be broadcasted. - return args + return list(args) return [_mx_np_op.broadcast_to(array, shape) for array in args] diff --git a/tests/python/unittest/test_numpy_interoperability.py b/tests/python/unittest/test_numpy_interoperability.py index 4ab591b76a42..29cfddd0709a 100644 --- a/tests/python/unittest/test_numpy_interoperability.py +++ b/tests/python/unittest/test_numpy_interoperability.py @@ -86,6 +86,7 @@ def _prepare_workloads(): OpArgMngr.add_workload('var', array_pool['4x1']) OpArgMngr.add_workload('zeros_like', array_pool['4x1']) OpArgMngr.add_workload('outer', np.ones((5)), np.ones((2))) + OpArgMngr.add_workload('meshgrid', np.array([1, 2, 3])) OpArgMngr.add_workload('meshgrid', np.array([1, 2, 3]), np.array([4, 5, 6, 7])) OpArgMngr.add_workload('meshgrid', np.array([1, 2, 3]), np.array([4, 5, 6, 7]), indexing='ij')