This repository has been archived by the owner on Nov 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
[MXNET-1408] Adding test to verify Large Tensor Support for ravel and unravel #15048
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,9 +15,9 @@ | |
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
import mxnet as mx | ||
import numpy as np | ||
from mxnet.test_utils import rand_ndarray, assert_almost_equal | ||
import mxnet as mx | ||
from mxnet.test_utils import rand_ndarray, assert_almost_equal, rand_coord_2d | ||
from mxnet import gluon, nd | ||
from tests.python.unittest.common import with_seed | ||
|
||
|
@@ -74,7 +74,7 @@ def test_ndarray_random_randint(): | |
# 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) | ||
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) | ||
|
@@ -130,13 +130,6 @@ def test_clip(): | |
assert np.sum(res[-1].asnumpy() == 1000) == a.shape[1] | ||
|
||
|
||
def test_take(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was duplicate |
||
a = nd.ones(shape=(LARGE_X, SMALL_Y)) | ||
idx = nd.arange(LARGE_X-1000, LARGE_X) | ||
res = nd.take(a, idx) | ||
assert np.sum(res[-1].asnumpy() == 1) == res.shape[1] | ||
|
||
|
||
def test_split(): | ||
a = nd.arange(0, LARGE_X * SMALL_Y).reshape(LARGE_X, SMALL_Y) | ||
outs = nd.split(a, num_outputs=SMALL_Y, axis=1) | ||
|
@@ -215,9 +208,9 @@ def test_where(): | |
|
||
|
||
def test_pick(): | ||
a = mx.nd.ones(shape=(256*35, 1024*1024)) | ||
b = mx.nd.ones(shape=(256*35,)) | ||
res = mx.nd.pick(a,b) | ||
a = mx.nd.ones(shape=(256 * 35, 1024 * 1024)) | ||
b = mx.nd.ones(shape=(256 * 35, )) | ||
res = mx.nd.pick(a, b) | ||
assert res.shape == b.shape | ||
|
||
|
||
|
@@ -252,11 +245,9 @@ def numpy_space_to_depth(x, blocksize): | |
output = mx.nd.space_to_depth(data, 2) | ||
assert_almost_equal(output.asnumpy(), expected, atol=1e-3, rtol=1e-3) | ||
|
||
|
||
@with_seed() | ||
def test_diag(): | ||
h = np.random.randint(2,9) | ||
w = np.random.randint(2,9) | ||
a_np = np.random.random((LARGE_X, 64)).astype(np.float32) | ||
a_np = np.random.random((LARGE_X, SMALL_Y)).astype(np.float32) | ||
a = mx.nd.array(a_np) | ||
|
||
# k == 0 | ||
|
@@ -274,11 +265,33 @@ def test_diag(): | |
assert_almost_equal(r.asnumpy(), np.diag(a_np, k=k)) | ||
|
||
# random k | ||
k = np.random.randint(-min(LARGE_X, 64) + 1, min(h, w)) | ||
k = np.random.randint(-min(LARGE_X, SMALL_Y) + 1, min(LARGE_X, SMALL_Y)) | ||
r = mx.nd.diag(a, k=k) | ||
assert_almost_equal(r.asnumpy(), np.diag(a_np, k=k)) | ||
|
||
|
||
@with_seed() | ||
def test_ravel_multi_index(): | ||
x1, y1 = rand_coord_2d((LARGE_X - 100), LARGE_X, 10, SMALL_Y) | ||
x2, y2 = rand_coord_2d((LARGE_X - 200), LARGE_X, 9, SMALL_Y) | ||
x3, y3 = rand_coord_2d((LARGE_X - 300), LARGE_X, 8, SMALL_Y) | ||
indices_2d = [[x1, x2, x3], [y1, y2, y3]] | ||
idx = mx.nd.ravel_multi_index(mx.nd.array(indices_2d, dtype=np.int64), shape=(LARGE_X, SMALL_Y)) | ||
idx_numpy = np.ravel_multi_index(indices_2d, (LARGE_X, SMALL_Y)) | ||
assert np.sum(1 for i in range(idx.size) if idx[i] == idx_numpy[i]) == 3 | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove extra line There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done :) |
||
@with_seed() | ||
def test_unravel_index(): | ||
x1, y1 = rand_coord_2d((LARGE_X - 100), LARGE_X, 10, SMALL_Y) | ||
x2, y2 = rand_coord_2d((LARGE_X - 200), LARGE_X, 9, SMALL_Y) | ||
x3, y3 = rand_coord_2d((LARGE_X - 300), LARGE_X, 8, SMALL_Y) | ||
original_2d_indices = [[x1, x2, x3], [y1, y2, y3]] | ||
idx_numpy = np.ravel_multi_index(original_2d_indices, (LARGE_X, SMALL_Y)) | ||
indices_2d = mx.nd.unravel_index(mx.nd.array(idx_numpy, dtype=np.int64), shape=(LARGE_X, SMALL_Y)) | ||
assert (indices_2d.asnumpy() == np.array(original_2d_indices)).all() | ||
|
||
|
||
if __name__ == '__main__': | ||
import nose | ||
nose.runmodule() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggested reordering of imports by pylint