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_r316442809
##########
File path: tests/nightly/test_large_vector.py
##########
@@ -33,6 +35,293 @@ def test_slice():
assert res.shape[0] == MEDIUM_X
+def test_gluon_embedding():
+ m = gluon.nn.Embedding(1, LARGE_Y)
+ m.initialize()
+ a = nd.zeros((LARGE_Y, 1))
+ b = m(a)
+ assert b.shape == (LARGE_Y, 1, LARGE_Y)
+ assert b.asnumpy().size == LARGE_X*2
+
+
+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 np.sum(res[-1].asnumpy() == 2) == a.shape[1]
+ res = a + 1
+ assert np.sum(res[-1].asnumpy() == 2) == a.shape[1]
+ res = nd.sqrt(a + 3)
+ assert np.sum(res[-1].asnumpy() == 2) == a.shape[1]
+
+
+def test_reduce():
+ a = nd.ones(shape=(LARGE_X, SMALL_Y))
+ assert nd.sum(a).asnumpy() == a.shape[0] * a.shape[1]
+
+
+def test_FullyConnected():
+ a = nd.ones(shape=(LARGE_X, SMALL_Y))
+ b = nd.ones(shape=(SMALL_Y, SMALL_Y))
+ res = nd.FullyConnected(a, b, num_hidden=b.shape[1], no_bias=True)
+ assert np.sum(res[-1].asnumpy() == SMALL_Y) == b.shape[1]
+
+
+def test_broadcast():
+ a = nd.ones(shape=(LARGE_X, SMALL_Y*2))
+ b = nd.arange(0, LARGE_X).reshape(LARGE_X, 1)
+ res = nd.broadcast_to(b, shape=(b.shape[0], SMALL_Y*2))
+ assert np.sum(res[-1].asnumpy() == LARGE_X) == res.shape[1]
+ res = mx.nd.broadcast_like(b, a)
+ assert np.sum(res[-1].asnumpy() == LARGE_X) == res.shape[1]
+
+
+def test_clip():
+ a = nd.arange(0, LARGE_X)
+ res = nd.clip(a, a_min=100, a_max=1000)
+ assert np.sum(res[-1].asnumpy() == 1000) == 101
Review comment:
Have you tested this? Isn't np.sum(res[-1].asnumpy() == 1000) == 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]
With regards,
Apache Git Services