apeforest commented on a change in pull request #15943: Added tests to verify
Large Vector Support for initial set of ops
URL: https://github.com/apache/incubator-mxnet/pull/15943#discussion_r317387091
##########
File path: tests/nightly/test_large_vector.py
##########
@@ -30,9 +30,159 @@
def test_slice():
a = nd.ones(LARGE_X)
res = nd.slice(a, begin=(LARGE_X - MEDIUM_X), end=LARGE_X)
+ assert a[0] == 1
assert res.shape[0] == MEDIUM_X
+def test_ndarray_zeros():
+ a = nd.zeros(shape=LARGE_X)
+ assert a[-1] == 0
+ assert a.shape == (LARGE_X,)
+ assert a.size == LARGE_X
+
+
+def test_ndarray_ones():
+ a = nd.ones(shape=LARGE_X)
+ assert a[-1] == 1
+ assert nd.sum(a).asnumpy() == LARGE_X
+
+
+@with_seed()
+def test_ndarray_random_uniform():
+ a = nd.random.uniform(shape=LARGE_X)
+ assert a[-1] != 0
+
+
+@with_seed()
+def test_ndarray_random_randint():
+ a = nd.random.randint(100, 10000, shape=LARGE_X)
+ assert a.shape == (LARGE_X,)
+ # check if randint can generate value greater than 2**32 (large)
+ low_large_value = 2**32
+ high_large_value = 2**34
+ a = nd.random.randint(low_large_value, high_large_value, dtype=np.int64)
+ low = mx.nd.array([low_large_value], dtype='int64')
+ high = mx.nd.array([high_large_value], dtype='int64')
+ assert a.__gt__(low) and a.__lt__(high)
+
+
+def test_ndarray_empty():
+ a = nd.empty(LARGE_X)
+ assert a.shape == (LARGE_X,)
+
+
+def test_elementwise():
+ a = nd.ones(shape=LARGE_X)
+ b = nd.ones(shape=LARGE_X)
+ res = a + b
+ assert res[-1].asnumpy() == 2
+ res = a + 1
+ assert res[-1].asnumpy() == 2
+ res = nd.sqrt(a + 8)
+ assert res[-1].asnumpy() == 3
+
+
+def test_reduce():
+ a = nd.ones(shape=(LARGE_X, 1))
+ assert nd.sum(a).asnumpy() == a.shape[0] * a.shape[1]
+
+
+def test_clip():
+ a = create_vector(LARGE_X)
+ res = nd.clip(a, a_min=100, a_max=1000)
+ assert np.sum(res[-1].asnumpy() == 1000) == 1
+
+
+def test_argmin():
+ a = create_vector(LARGE_X)
+ assert a[0] == 0
+ idx = mx.nd.argmin(a, axis=0)
+ assert idx.shape[0] == 1
+
+
+def test_take():
+ a = nd.ones(shape=LARGE_X)
+ idx = nd.arange(LARGE_X - 1000, LARGE_X)
+ res = nd.take(a, idx)
+ assert np.sum(res.asnumpy() == 1) == res.shape[0]
+
+
+def test_slice_assign():
+ a = nd.ones(shape=LARGE_X)
+ a[LARGE_X-1:LARGE_X] = 1000
+ assert np.sum(a[-1].asnumpy() == 1000) == 1
+
+
+def test_expand_dims():
+ a = nd.ones(shape=LARGE_X)
+ res = nd.expand_dims(a, axis=0)
+ assert res[0][0] == 1
+ assert res.shape == (1, a.shape[0])
+
+
+def test_squeeze():
+ a = nd.ones(shape=LARGE_X)
+ data = nd.expand_dims(a, axis=0)
+ res = nd.squeeze(data)
+ assert a[0] == res[0]
+ assert res.shape == a.shape
+
+
+def test_broadcast_div():
+ a = nd.ones(shape=LARGE_X)
+ b = nd.ones(shape=LARGE_X) * 2
+ res = a / b
+ assert np.sum(res.asnumpy() == 0.5) == a.shape[0]
+
+
+def test_Dense(ctx=mx.cpu(0)):
+ data = mx.nd.ones(shape=LARGE_X)
+ linear = gluon.nn.Dense(2)
+ linear.initialize(ctx=ctx)
+ res = linear(data)
+ res.wait_to_read()
+ assert res.shape == (LARGE_X, 2)
+
+
+def test_pick():
+ a = mx.nd.ones(shape=(LARGE_X, 2))
+ b = mx.nd.ones(shape=LARGE_X)
+ res = mx.nd.pick(a, b)
+ assert res.shape == b.shape
+
+
+def test_softmax():
+ input_data = nd.ones((2, LARGE_X))
+ output = nd.softmax(input_data, axis=0)
+ assert output[0][0] == 0.5
+ assert output[-1][-1] == 0.5
+
+
+def test_argsort():
+ b = create_vector(size=LARGE_X)
+ s = nd.argsort(b, axis=0, is_ascend=False, dtype=np.int64)
+ mx.nd.waitall()
+ assert (s[0].asnumpy() == (LARGE_X - 1)).all()
+
+
+def test_sort():
+ b = create_vector(size=LARGE_X)
+ s = nd.sort(b, axis=0, is_ascend=False)
+ assert np.sum(s[-1].asnumpy() == 0).all()
+ s = nd.sort(b, is_ascend=True)
+ assert np.sum(s[0].asnumpy() == 0).all()
+
+
+def test_topk():
+ b = create_vector(size=LARGE_X)
+ k = nd.topk(b, k=10, axis=0, dtype=np.int64)
Review comment:
would it be more consistent to rename it to ind?
----------------------------------------------------------------
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]
With regards,
Apache Git Services