You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by ap...@apache.org on 2019/06/02 22:07:11 UTC
[incubator-mxnet] branch master updated: [MXNET-1410]Adding Large
Tensor Support for tensor transpose (#15059)
This is an automated email from the ASF dual-hosted git repository.
apeforest pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-mxnet.git
The following commit(s) were added to refs/heads/master by this push:
new 99e69e6 [MXNET-1410]Adding Large Tensor Support for tensor transpose (#15059)
99e69e6 is described below
commit 99e69e68258d832f9f866988c1f25e0a579ddd69
Author: Rohit Kumar Srivastava <sr...@osu.edu>
AuthorDate: Sun Jun 2 15:06:33 2019 -0700
[MXNET-1410]Adding Large Tensor Support for tensor transpose (#15059)
---
src/operator/tensor/matrix_op-inl.h | 8 ++++----
tests/nightly/test_large_array.py | 27 +++++++++++++++++++++++++++
2 files changed, 31 insertions(+), 4 deletions(-)
diff --git a/src/operator/tensor/matrix_op-inl.h b/src/operator/tensor/matrix_op-inl.h
index 50cb1ae..5cd7bf6 100644
--- a/src/operator/tensor/matrix_op-inl.h
+++ b/src/operator/tensor/matrix_op-inl.h
@@ -1950,10 +1950,10 @@ struct ReverseParam : public dmlc::Parameter<ReverseParam> {
#define REVERSE_MAX_DIM 10U
struct reverse {
- MSHADOW_XINLINE static int ReverseIndex(index_t idx,
- index_t nreversedim,
- const index_t * stride_,
- const index_t * trailing_) {
+ MSHADOW_XINLINE static index_t ReverseIndex(index_t idx,
+ index_t nreversedim,
+ const index_t * stride_,
+ const index_t * trailing_) {
index_t outputIndex = idx;
for (index_t i = 0; i < nreversedim; ++i) {
const index_t low = outputIndex % trailing_[i];
diff --git a/tests/nightly/test_large_array.py b/tests/nightly/test_large_array.py
index 286f2e4..8c80e9e 100644
--- a/tests/nightly/test_large_array.py
+++ b/tests/nightly/test_large_array.py
@@ -292,6 +292,33 @@ def test_unravel_index():
assert (indices_2d.asnumpy() == np.array(original_2d_indices)).all()
+def create_2d_tensor(rows, columns):
+ a = np.arange(0, rows).reshape(rows, 1)
+ b = np.broadcast_to(a, shape=(a.shape[0], columns))
+ return nd.array(b, dtype=np.int64)
+
+
+def test_transpose():
+ b = create_2d_tensor(rows=LARGE_X, columns=SMALL_Y)
+ t = b.T
+ assert t.shape == (SMALL_Y, LARGE_X)
+ assert np.sum(t[:, -1].asnumpy() == (LARGE_X - 1)) == b.shape[1]
+
+
+def test_swapaxes():
+ b = create_2d_tensor(rows=LARGE_X, columns=SMALL_Y)
+ t = nd.swapaxes(b, dim1=0, dim2=1)
+ assert t.shape == (SMALL_Y, LARGE_X)
+ assert np.sum(t[:, -1].asnumpy() == (LARGE_X - 1)) == b.shape[1]
+
+
+def test_flip():
+ b = create_2d_tensor(rows=LARGE_X, columns=SMALL_Y)
+ t = nd.flip(b, axis=0)
+ assert t.shape == (LARGE_X, SMALL_Y)
+ assert np.sum(t[-1, :].asnumpy() == 0) == b.shape[1]
+
+
if __name__ == '__main__':
import nose
nose.runmodule()