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

Commit 61fa38e

Browse files
author
Rohit Kumar Srivastava
committed
[MXNET-1408] Adding test to verify Large Tensor Support for ravel and unravel
1 parent 8a9dd72 commit 61fa38e

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

tests/nightly/test_large_array.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
import mxnet as mx
1918
import numpy as np
19+
import mxnet as mx
2020
from mxnet.test_utils import rand_ndarray, assert_almost_equal
2121
from mxnet import gluon, nd
2222
from tests.python.unittest.common import with_seed
@@ -74,7 +74,7 @@ def test_ndarray_random_randint():
7474
# check if randint can generate value greater than 2**32 (large)
7575
low_large_value = 2**32
7676
high_large_value = 2**34
77-
a = nd.random.randint(low_large_value,high_large_value, dtype=np.int64)
77+
a = nd.random.randint(low_large_value, high_large_value, dtype=np.int64)
7878
low = mx.nd.array([low_large_value], dtype='int64')
7979
high = mx.nd.array([high_large_value], dtype='int64')
8080
assert a.__gt__(low) and a.__lt__(high)
@@ -130,13 +130,6 @@ def test_clip():
130130
assert np.sum(res[-1].asnumpy() == 1000) == a.shape[1]
131131

132132

133-
def test_take():
134-
a = nd.ones(shape=(LARGE_X, SMALL_Y))
135-
idx = nd.arange(LARGE_X-1000, LARGE_X)
136-
res = nd.take(a, idx)
137-
assert np.sum(res[-1].asnumpy() == 1) == res.shape[1]
138-
139-
140133
def test_split():
141134
a = nd.arange(0, LARGE_X * SMALL_Y).reshape(LARGE_X, SMALL_Y)
142135
outs = nd.split(a, num_outputs=SMALL_Y, axis=1)
@@ -216,8 +209,8 @@ def test_where():
216209

217210
def test_pick():
218211
a = mx.nd.ones(shape=(256*35, 1024*1024))
219-
b = mx.nd.ones(shape=(256*35,))
220-
res = mx.nd.pick(a,b)
212+
b = mx.nd.ones(shape=(256*35, ))
213+
res = mx.nd.pick(a, b)
221214
assert res.shape == b.shape
222215

223216

@@ -254,8 +247,8 @@ def numpy_space_to_depth(x, blocksize):
254247

255248

256249
def test_diag():
257-
h = np.random.randint(2,9)
258-
w = np.random.randint(2,9)
250+
h = np.random.randint(2, 9)
251+
w = np.random.randint(2, 9)
259252
a_np = np.random.random((LARGE_X, 64)).astype(np.float32)
260253
a = mx.nd.array(a_np)
261254

@@ -279,6 +272,21 @@ def test_diag():
279272
assert_almost_equal(r.asnumpy(), np.diag(a_np, k=k))
280273

281274

275+
def test_ravel_multi_index():
276+
indices_2d = [[LARGE_X-1, LARGE_X-100, 6], [SMALL_Y-1, SMALL_Y-10, 1]]
277+
idx = mx.nd.ravel_multi_index(mx.nd.array(indices_2d, dtype=np.int64), shape=(LARGE_X, SMALL_Y))
278+
idx_numpy = np.ravel_multi_index(indices_2d, (LARGE_X, SMALL_Y))
279+
assert np.sum(1 for i in range(idx.size) if idx[i] == idx_numpy[i]) == 3
280+
281+
282+
def test_unravel_index():
283+
original_2d_indices = [[LARGE_X-1, LARGE_X-100, 6], [SMALL_Y-1, SMALL_Y-10, 1]]
284+
idx = mx.nd.ravel_multi_index(mx.nd.array(original_2d_indices, dtype=np.int64), shape=(LARGE_X, SMALL_Y))
285+
idx_numpy = np.ravel_multi_index(original_2d_indices, (LARGE_X, SMALL_Y))
286+
indices_2d = mx.nd.unravel_index(mx.nd.array(idx, dtype=np.int64), shape=(LARGE_X, SMALL_Y))
287+
assert (indices_2d.asnumpy() == np.array(original_2d_indices)).all()
288+
289+
282290
if __name__ == '__main__':
283291
import nose
284292
nose.runmodule()

0 commit comments

Comments
 (0)