[GitHub] [incubator-mxnet] ckt624 commented on a change in pull request #15349: Numpy Tensordot Operator

2019-07-12 Thread GitBox
ckt624 commented on a change in pull request #15349: Numpy Tensordot Operator 
URL: https://github.com/apache/incubator-mxnet/pull/15349#discussion_r302852496
 
 

 ##
 File path: tests/python/unittest/test_numpy_op.py
 ##
 @@ -26,6 +26,151 @@
 from mxnet.test_utils import check_numeric_gradient
 from common import assertRaises, with_seed
 import random
+import collections
+
+@with_seed()
+@npx.use_np_shape
+def test_np_tensordot():
+class TestTensordot(HybridBlock):
+def __init__(self, axes):
+super(TestTensordot, self).__init__()
+self._axes = axes
+
+def hybrid_forward(self, F, a, b):
+return F.np.tensordot(a, b, self._axes)
+
+def tensordot_backward(a, b, axes = 2):
+if (a.ndim < 1) or (b.ndim < 1):
+raise ValueError('An input is zero-dim')
+
+if isinstance(axes, collections.abc.Sequence):
+if len(axes) != 2:
+raise ValueError('Axes must consist of two arrays.')
+a_axes_summed, b_axes_summed = axes
+if _np.isscalar(a_axes_summed):
+a_axes_summed = a_axes_summed,
+if _np.isscalar(b_axes_summed):
+b_axes_summed = b_axes_summed,
+else:
+a_axes_summed = [i + a.ndim - axes for i in range(axes)]
+b_axes_summed = [i for i in range(axes)]
+
+if len(a_axes_summed) != len(b_axes_summed):
+raise ValueError('Axes length mismatch') 
+
+a_axes_remained = []
+for i in range(a.ndim):
+if not (i in a_axes_summed):
+a_axes_remained.append(i)
+a_axes = a_axes_remained[:] + a_axes_summed[:]
+
+b_axes_remained = []
+for i in range(b.ndim):
+if not (i in b_axes_summed):
+b_axes_remained.append(i)
+b_axes = b_axes_summed[:] + b_axes_remained[:]
+
+ad1 = _np.prod([a.shape[i] for i in a_axes_remained]) if 
len(a_axes_remained) > 0 else 1
+ad2 = _np.prod([a.shape[i] for i in a_axes_summed]) if 
len(a_axes_summed) > 0 else 1
+bd1 = _np.prod([b.shape[i] for i in b_axes_summed]) if 
len(b_axes_summed) > 0 else 1
+bd2 = _np.prod([b.shape[i] for i in b_axes_remained]) if 
len(b_axes_remained) > 0 else 1
+
+out_grad = _np.ones((ad1, bd2))
+
+new_a = _np.transpose(a, a_axes)
+new_a_shape = new_a.shape[:]
+new_a = new_a.reshape((ad1, ad2)) 
+new_b = _np.transpose(b, b_axes) 
+new_b_shape = new_b.shape[:]
+new_b = new_b.reshape((bd1, bd2))
+
+reverse_a_axes = [0 for i in a_axes]
+for i in range(len(a_axes)):
+reverse_a_axes[a_axes[i]] = i
+
+reverse_b_axes = [0 for i in b_axes]
+for i in range(len(b_axes)):
+reverse_b_axes[b_axes[i]] = i
+
+grad_b = _np.dot(new_a.T, out_grad).reshape(new_b_shape)
+grad_b = _np.transpose(grad_b, reverse_b_axes)
+grad_a = _np.dot(out_grad, new_b.T).reshape(new_a_shape)
+grad_a = _np.transpose(grad_a, reverse_a_axes)
+
+return [grad_a, grad_b]
+
+# test non zero size input
+tensor_shapes = [ 
+((3, 5), (5, 4), 1),  # (a_shape, b_shape, axes)
+((3,), (3,), 1),   
+((3, 4, 5, 6, 7), (5, 6, 7, 1, 2), 3),
+((3, 5, 4, 6, 7), (7, 6, 5, 1, 2), [[1, 3, 4], [2, 1, 0]]),
+((2, 2), (2, 2), 2),
+((3, 5, 4), (5, ), [[1], [0]]),  
+((2,), (2, 3), 1),
+((3,), (3,), 0),
+((2,), (2, 3), 0),
+((3, 5, 4), (5, ), 0)
+]
+
+for hybridize in [True, False]:
+for a_shape, b_shape, axes in tensor_shapes:
+for dtype in [_np.float32, _np.float64]:
 
 Review comment:
   Don't support fp16 at CPU.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] roywei commented on issue #15452: fix nightly CI failure

2019-07-12 Thread GitBox
roywei commented on issue #15452: fix nightly CI failure
URL: https://github.com/apache/incubator-mxnet/pull/15452#issuecomment-510776556
 
 
I have verified test_estimator passed. but test tutorials is still failing 
due to other tutorials are failing. This change is needed nonetheless
   ```
   --
   Ran 2 tests in 341.805s
   
   OK
   build.py: 2019-07-12 01:33:11,865Z INFO Waiting for status of container 
594316b5c329 for 600 s.
   build.py: 2019-07-12 01:33:12,139Z INFO Container exit status: {'Error': 
None, 'StatusCode': 0}
   build.py: 2019-07-12 01:33:12,139Z INFO Container exited with success 👍
   build.py: 2019-07-12 01:33:12,140Z INFO Stopping container: 594316b5c329
   build.py: 2019-07-12 01:33:12,141Z INFO Removing container: 594316b5c329
   ```


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] matteosal commented on issue #15497: [MKLDNN] Independent gradients requests check with respect to weights and bias of convolution

2019-07-12 Thread GitBox
matteosal commented on issue #15497: [MKLDNN] Independent gradients requests 
check with respect to weights and bias of convolution
URL: https://github.com/apache/incubator-mxnet/pull/15497#issuecomment-510787762
 
 
   > @matteosal I tested your example with commit 
[9ca0428](https://github.com/apache/incubator-mxnet/commit/9ca042839b519c91963f77f694673557e9fddfc8),
 and it ran successfully without any exception. Could you test it again with 
commit 
[9ca0428](https://github.com/apache/incubator-mxnet/commit/9ca042839b519c91963f77f694673557e9fddfc8)?
   
   Ops sorry, I've missed that commit. Yes, it works on that


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] zixuanweeei commented on issue #15497: [MKLDNN] Independent gradients requests check with respect to weights and bias of convolution

2019-07-12 Thread GitBox
zixuanweeei commented on issue #15497: [MKLDNN] Independent gradients requests 
check with respect to weights and bias of convolution
URL: https://github.com/apache/incubator-mxnet/pull/15497#issuecomment-510794204
 
 
   @matteosal Thanks. That's great. I am working on a unit test for this 
feature. Then we can merge it to master after further review and verification. 


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] mikemwx commented on a change in pull request #15302: [Numpy] Numpy hstack

2019-07-12 Thread GitBox
mikemwx commented on a change in pull request #15302: [Numpy] Numpy hstack
URL: https://github.com/apache/incubator-mxnet/pull/15302#discussion_r302873300
 
 

 ##
 File path: tests/python/unittest/test_numpy_op.py
 ##
 @@ -860,6 +860,72 @@ def get_new_shape(shape, axis):
 assert_almost_equal(mx_out.asnumpy(), np_out, rtol=1e-3, 
atol=1e-5)
 
 
+@with_seed()
+@npx.use_np_shape
+def test_np_hstack():
+class TestHStack(HybridBlock):
+def __init__(self):
+super(TestHStack, self).__init__()
+
+def hybrid_forward(self, F, a, *args):
+return F.np.hstack([a] + list(args))
+
+def get_new_shape(shape):
+if len(shape) == 0:
+l = random.randint(0,3)
+if l == 0:
+return shape 
+else:
+return (l,)
+shape_lst = list(shape)
+axis = 1 if len(shape) > 1 else 0
+shape_lst[axis] = random.randint(0, 5)
+return tuple(shape_lst)
+
+shapes = [
+(),
+(1,),
+(2,1),
+(2,2,4),
+(2,0,0),
+(0,1,3),
+(2,0,3),
+(2,3,4,5)
+]
+for hybridize in [True, False]:
+for shape in shapes:
+test_hstack = TestHStack()
+if hybridize:
+test_hstack.hybridize()
+# test symbolic forward
+a = np.random.uniform(size=get_new_shape(shape))
+a.attach_grad()
+b = np.random.uniform(size=get_new_shape(shape))
+b.attach_grad()
+c = np.random.uniform(size=get_new_shape(shape))
+c.attach_grad()
+d = np.random.uniform(size=get_new_shape(shape))
+d.attach_grad()
+with mx.autograd.record():
+mx_out = test_hstack(a, b, c, d)
+np_out = _np.hstack((a.asnumpy(), b.asnumpy(), c.asnumpy(), 
d.asnumpy()))
+assert mx_out.shape == np_out.shape
+assert_almost_equal(mx_out.asnumpy(), np_out, rtol=1e-3, atol=1e-5)
+
+# test symbolic backward
+mx_out.backward()
+assert_almost_equal(a.grad.asnumpy(), _np.ones(a.shape), 
rtol=1e-3, atol=1e-5)
+assert_almost_equal(b.grad.asnumpy(), _np.ones(b.shape), 
rtol=1e-3, atol=1e-5)
+assert_almost_equal(c.grad.asnumpy(), _np.ones(c.shape), 
rtol=1e-3, atol=1e-5)
+assert_almost_equal(d.grad.asnumpy(), _np.ones(d.shape), 
rtol=1e-3, atol=1e-5)
+
+# test imperative
+mx_out = np.hstack((a, b, c, d))
+np_out = _np.hstack((a.asnumpy(),b.asnumpy(), c.asnumpy(), 
d.asnumpy()))
+assert_almost_equal(mx_out.asnumpy(), np_out, rtol=1e-3, atol=1e-5)
+
+
 
 Review comment:
   Done


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] mikemwx commented on a change in pull request #15314: [Numpy] Numpy dstack

2019-07-12 Thread GitBox
mikemwx commented on a change in pull request #15314: [Numpy] Numpy dstack
URL: https://github.com/apache/incubator-mxnet/pull/15314#discussion_r302874471
 
 

 ##
 File path: src/operator/numpy/np_matrix_op.cc
 ##
 @@ -55,6 +55,67 @@ bool NumpyTransposeShape(const nnvm::NodeAttrs& attrs,
   return shape_is_known(ret);
 }
 
+bool DStackShape(const nnvm::NodeAttrs& attrs,
+ mxnet::ShapeVector *in_shape,
+ mxnet::ShapeVector *out_shape) {
+  using namespace mshadow;
+  ConcatParam param_ = nnvm::get(attrs.parsed);
+  CHECK_EQ(in_shape->size(), static_cast(param_.num_args));
+  mxnet::TShape dshape;
+  dim_t size = 0;
+  bool has_unknown_dim_size = false;
+  int axis = 2;
+  param_.dim = axis;
+  for (int i = 0; i < param_.num_args; ++i) {
+if ((*in_shape)[i].ndim() == 0) {
+  (*in_shape)[i] = mxnet::TShape(3, 1);
+} else if ((*in_shape)[i].ndim() == 1) {
+  mxnet::TShape t = mxnet::TShape(3, 1);
+  t[1] = (*in_shape)[i][0];
+  (*in_shape)[i] = t;
+} else if ((*in_shape)[i].ndim() == 2) {
+  mxnet::TShape t = mxnet::TShape(3, 1);
+  t[0] = (*in_shape)[i][0];
+  t[1] = (*in_shape)[i][1];
+  (*in_shape)[i] = t;
+}
+mxnet::TShape &tmp = (*in_shape)[i];
+if (tmp.ndim() > 0) {
+  CheckAxis(axis, tmp.ndim());
+  if (!mxnet::dim_size_is_known(tmp, axis)) {
+has_unknown_dim_size = true;
+  } else {
+size += tmp[axis];
+  }
+  tmp[axis] = -1;
+  shape_assign(&dshape, tmp);
+}
+  }
+
+  mxnet::TShape tmp = (*out_shape)[0];
+  if (tmp.ndim() > 0) {
+axis = CheckAxis(param_.dim, tmp.ndim());
+tmp[axis] = -1;
+shape_assign(&dshape, tmp);
+  }
+
+  if (dshape.ndim() == -1) return false;
+  CHECK_NE(dshape.ndim(), 0) << "zero-dimensional arrays cannot be 
concatenated";
+
+  for (int i = 0; i < param_.num_args; ++i) {
+CHECK(shape_assign(&(*in_shape)[i], dshape))
+<< "Incompatible input shape: expected " << dshape << ", got " << 
(*in_shape)[i];
 
 Review comment:
   Thanks. Resolved.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] mikemwx commented on a change in pull request #15456: [Numpy] numpy compatible invert

2019-07-12 Thread GitBox
mikemwx commented on a change in pull request #15456: [Numpy] numpy compatible 
invert
URL: https://github.com/apache/incubator-mxnet/pull/15456#discussion_r302875177
 
 

 ##
 File path: python/mxnet/ndarray/numpy/_op.py
 ##
 @@ -1414,6 +1413,48 @@ def rint(x, out=None, **kwargs):
 """
 return _unary_func_helper(x, _npi.rint, _np.rint, out=out, **kwargs)
 
+def invert(x, out=None, **kwargs):
+"""
+Compute bit-wise inversion, or bit-wise NOT, element-wise.
+Computes the bit-wise NOT of the underlying binary representation of
+the integers in the input arrays. This ufunc implements the C/Python 
operator ~.
+For signed integer inputs, the two’s complement is returned.
+In a two’s-complement system negative numbers are represented
+by the two’s complement of the absolute value.
+This is the most common method of representing signed integers on 
computers [1].
+A N-bit two’s-complement system can represent every integer in the range 
-2^{N-1} to +2^{N-1}-1.
+
+Parameters
+--
+x : ndarray
+Only integer and boolean types are handled.
+out : ndarray or None
+A location into which the result is stored.
+If provided, it must have the same shape as the input.
+If not provided or None, a freshly-allocated array is returned.
+
+Returns
+---
+out : ndarray
+Bitwisely inverted elements of the original array.
+
+Examples
+
+>>> np.invert(np.array([13], dtype=np.uint8))
+array([242], dtype=uint8)
+
+Notes
+-
+This function differs from the original `numpy.invert
+`_ 
in
+the following way(s):
+
+- only ndarray or scalar is accpted as valid input, tuple of ndarray is 
not supported
+- broadcasting to `out` of different shape is currently not supported
+- when input is plain python numerics, the result will not be stored in 
the `out` param
+
+"""
+return _unary_func_helper(x, _npi.invert, _np.invert, out=out, **kwargs)
 
 Review comment:
   Thank you. Resolved.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] zoeygxy commented on a change in pull request #15346: numpy_split support param type fix; numpy_vsplit added

2019-07-12 Thread GitBox
zoeygxy commented on a change in pull request #15346: numpy_split support param 
type fix; numpy_vsplit added
URL: https://github.com/apache/incubator-mxnet/pull/15346#discussion_r302902846
 
 

 ##
 File path: python/mxnet/numpy/multiarray.py
 ##
 @@ -1835,6 +1835,83 @@ def split(ary, indices_or_sections, axis=0):
 return _mx_nd_np.split(ary, indices_or_sections, axis=axis)
 
 
+@set_module('mxnet.numpy')
+def vsplit(ary, indices_or_sections):
+r"""
+vsplit(ary, indices_or_sections)
+
+Split an array into multiple sub-arrays vertically (row-wise).
+
+``vsplit`` is equivalent to ``split`` with `axis=0` (default): the array 
is always split
+along the first axis regardless of the array dimension.
+
+Parameters
+--
+ary : ndarray
+Array to be divided into sub-arrays.
+indices_or_sections : int or 1 - D Python tuple, list or set.
+If `indices_or_sections` is an integer, N, the array will be divided 
into N equal arrays
+along axis 0.  If such a split is not possible, an error is raised.
+
+If `indices_or_sections` is a 1-D array of sorted integers, the 
entries indicate where
+along axis 0 the array is split.  For example, ``[2, 3]`` would result 
in
+
+  - ary[:2]
+  - ary[2:3]
+  - ary[3:]
+
+If an index exceeds the dimension of the array along axis 0, an error 
will be thrown.
+
+Returns
+---
+sub-arrays : list of ndarrays
+A list of sub-arrays.
+
+See Also
+
+split : Split an array into multiple sub-arrays of equal size.
+
+Notes
+---
+This function differs from the original `numpy.degrees
+
`_ in
+the following aspects:
+
+- Currently parameter ``indices_or_sections`` does not support ndarray, 
but supports scalar,
+tuple
 
 Review comment:
   Good catch! Fixed. 


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] tingying2020 closed pull request #15350: Add operator arctan2 with its test code

2019-07-12 Thread GitBox
tingying2020 closed pull request #15350: Add operator arctan2 with its test code
URL: https://github.com/apache/incubator-mxnet/pull/15350
 
 
   


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] tingying2020 opened a new pull request #15519: [Numpy] arctan2, a new branch for pr.

2019-07-12 Thread GitBox
tingying2020 opened a new pull request #15519: [Numpy] arctan2, a new branch 
for pr.
URL: https://github.com/apache/incubator-mxnet/pull/15519
 
 
   ## Description ##
   (Brief description on what this PR is about)
   
   ## Checklist ##
   ### Essentials ###
   Please feel free to remove inapplicable items for your PR.
   - [x] Changes are complete (i.e. I finished coding on this PR)
   - [x] All changes have test coverage:
   - Unit tests are added for small changes to verify correctness (e.g. adding 
a new operator)
   - Nightly tests are added for complicated/long-running ones (e.g. changing 
distributed kvstore)
   - Build tests will be added for build configuration changes (e.g. adding a 
new build option with NCCL)
   - [x] To the my best knowledge, examples are either not affected by this 
change, or have been fixed to be compatible with this change
   
   ## Comments ##
   - Create a new branch and move code to it.
   
   @haojin2 


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] braindotai commented on issue #15504: Saved model and then looked at the output of the same batch after loading, got different results!

2019-07-12 Thread GitBox
braindotai commented on issue #15504: Saved model and then looked at the output 
of the same batch after loading, got different results!
URL: 
https://github.com/apache/incubator-mxnet/issues/15504#issuecomment-510829624
 
 
   Make sure you are saving and loading the model from the same path. I've 
tested the code below and it is working fine.
   
   ```python
   for batch in data_iter:
   model.forward(batch)
   out1 = model.get_outputs()[0]
   break
   model.save_checkpoint('model', epoch = 0)
   sym, arg_params, aux_params = mx.model.load_checkpoint('model', epoch = 0)
   model.set_params(arg_params, aux_params)
   model.forward(batch)
   out2 = model.get_outputs()[0]
   print(f'diff_output:{nd.abs(out1 - out2)}') 
   ```
   Output is all zeros.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] KhurramPirov commented on issue #15504: Saved model and then looked at the output of the same batch after loading, got different results!

2019-07-12 Thread GitBox
KhurramPirov commented on issue #15504: Saved model and then looked at the 
output of the same batch after loading, got different results!
URL: 
https://github.com/apache/incubator-mxnet/issues/15504#issuecomment-510831907
 
 
   I checked the path, I do it inside batch_callback and model.fit, can it be
   the case(seems no), but nevetheless.
   
   пт, 12 июл. 2019 г. в 13:03, Rishik Mourya :
   
   > Make sure you are saving and loading the model from the same path. I've
   > tested the code below and it is working fine.
   >
   > for batch in data_iter:
   > model.forward(batch)
   > out1 = model.get_outputs()[0]
   > break
   > model.save_checkpoint('model', epoch = 0)
   > sym, arg_params, aux_params = mx.model.load_checkpoint('model', epoch = 0)
   > model.set_params(arg_params, aux_params)
   > model.forward(batch)
   > out2 = model.get_outputs()[0]print(f'diff_output:{nd.abs(out1 - out2)}')
   >
   > Output is all zeros.
   >
   > —
   > You are receiving this because you were mentioned.
   > Reply to this email directly, view it on GitHub
   > 
,
   > or mute the thread
   > 

   > .
   >
   
   
   -- 
   Khurram Pirov
   skype: matrixrextended
   mob: +7-916-439-53-76
   


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] haojin2 commented on a change in pull request #15468: Numpy compatible diagflat operator

2019-07-12 Thread GitBox
haojin2 commented on a change in pull request #15468: Numpy compatible diagflat 
operator
URL: https://github.com/apache/incubator-mxnet/pull/15468#discussion_r302921428
 
 

 ##
 File path: src/operator/numpy/np_diagflat_op-inl.h
 ##
 @@ -0,0 +1,201 @@
+/*
 
 Review comment:
   Better put this op in `np_init_op` files.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] haojin2 merged pull request #15282: Numpy compatible eye

2019-07-12 Thread GitBox
haojin2 merged pull request #15282: Numpy compatible eye
URL: https://github.com/apache/incubator-mxnet/pull/15282
 
 
   


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:
us...@infra.apache.org


With regards,
Apache Git Services


[incubator-mxnet] branch numpy updated (19c7c6e -> 3ea5f8c)

2019-07-12 Thread haoj
This is an automated email from the ASF dual-hosted git repository.

haoj pushed a change to branch numpy
in repository https://gitbox.apache.org/repos/asf/incubator-mxnet.git.


from 19c7c6e  fix memory override bug in multinomial (#15397)
 add 3ea5f8c  numpy eye op (#15282)

No new revisions were added by this update.

Summary of changes:
 python/mxnet/ndarray/numpy/_op.py  |  33 +-
 python/mxnet/numpy/multiarray.py   |  29 -
 python/mxnet/symbol/numpy/_symbol.py   |  33 +-
 src/operator/numpy/np_init_op.cc   |  30 -
 src/operator/numpy/np_init_op.cu   |   5 +-
 src/operator/numpy/np_init_op.h| 113 +
 src/operator/tensor/init_op.h  |  40 +++-
 tests/python/unittest/test_numpy_op.py |  69 
 8 files changed, 314 insertions(+), 38 deletions(-)
 create mode 100644 src/operator/numpy/np_init_op.h



[GitHub] [incubator-mxnet] haojin2 commented on a change in pull request #15468: Numpy compatible diagflat operator

2019-07-12 Thread GitBox
haojin2 commented on a change in pull request #15468: Numpy compatible diagflat 
operator
URL: https://github.com/apache/incubator-mxnet/pull/15468#discussion_r302921968
 
 

 ##
 File path: tests/python/unittest/test_numpy_op.py
 ##
 @@ -28,6 +28,59 @@
 import random
 
 
+@with_seed()
+@npx.use_np_shape
+def test_np_diagflat():
+@npx.use_np_shape
+class TestDiagflat(HybridBlock):
+def __init__(self, k):
+super(TestDiagflat, self).__init__()
+self.k = k
+
+def hybrid_forward(self, F, a):
+return F.np.diagflat(a, self.k)
+
+for hybridize in [True, False]:
+for dtype in ['int32', 'float16', 'float32', 'float64']:
+for shape_x in [(1,),  # single element
+(3, 3),  # square
+(),  # scalar
+(3, 0, 2),  # zero-dim
+(3, 4, 5),
+]:
+for k in range(-5, 6):
+if dtype == 'float16':
+rtol = atol = 1e-2
+else:
+rtol = atol = 1e-5
+
+test_diagflat = TestDiagflat(k)
+if hybridize:
+test_diagflat.hybridize()
+
+x = rand_ndarray(shape_x, dtype=dtype).as_np_ndarray()
+x.attach_grad()
+
+np_out = _np.diagflat(x.asnumpy(), k)
+with mx.autograd.record():
+mx_out = test_diagflat(x)
+assert mx_out.shape == np_out.shape
+assert_almost_equal(mx_out.asnumpy(), np_out, rtol=rtol,
+atol=atol)
+# test grad
+mx_out.backward()
+assert_almost_equal(x.grad.asnumpy(), _np.ones(x.shape),
+rtol=1e-3, atol=1e-5)
+
+# test imperative once again
+mx_out = np.diagflat(x, k)
+np_out = _np.diagflat(x.asnumpy(), k)
+assert_almost_equal(mx_out.asnumpy(), np_out, rtol=rtol,
+atol=atol)
+
 
 Review comment:
   2 blank lines between functions.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] haojin2 commented on a change in pull request #15468: Numpy compatible diagflat operator

2019-07-12 Thread GitBox
haojin2 commented on a change in pull request #15468: Numpy compatible diagflat 
operator
URL: https://github.com/apache/incubator-mxnet/pull/15468#discussion_r302921755
 
 

 ##
 File path: src/operator/numpy/np_diagflat_op-inl.h
 ##
 @@ -0,0 +1,201 @@
+/*
 
 Review comment:
   Seems like there's no `np_init_op-inl.h`, you could probably rename this 
`-inl.h` to that.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] haojin2 commented on a change in pull request #15468: Numpy compatible diagflat operator

2019-07-12 Thread GitBox
haojin2 commented on a change in pull request #15468: Numpy compatible diagflat 
operator
URL: https://github.com/apache/incubator-mxnet/pull/15468#discussion_r302922300
 
 

 ##
 File path: src/operator/numpy/np_diagflat_op.cu
 ##
 @@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*!
+ *  Copyright (c) 2019 by Contributors
+ * \file np_diagflat_op.cu
+ * \brief CPU Implementation of numpy-compatible diagflat operator
 
 Review comment:
   `GPU Implementation`?
   Actually please move those registrations to `np_init_op` files.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] qqaatw edited a comment on issue #15484: Binding Model fails with simple_bind error

2019-07-12 Thread GitBox
qqaatw edited a comment on issue #15484: Binding Model fails with simple_bind 
error
URL: 
https://github.com/apache/incubator-mxnet/issues/15484#issuecomment-510480630
 
 
   @Maicus I have the same problem as you, could you tell more in detail about 
the Target and the TargetCode Section? thanks.
   
   edited:
   Version 1.5.0b20190409 is fine but 1.5.0b20190712 has this problem.
   environment: 2080Ti & windows 10 x64 & cuda 10.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] haojin2 commented on a change in pull request #15519: [Numpy] arctan2, a new branch for pr.

2019-07-12 Thread GitBox
haojin2 commented on a change in pull request #15519: [Numpy] arctan2, a new 
branch for pr.
URL: https://github.com/apache/incubator-mxnet/pull/15519#discussion_r302927677
 
 

 ##
 File path: src/operator/numpy/np_elemwise_broadcast_op.cc
 ##
 @@ -198,5 +198,74 @@ 
MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR(_npi_minimum_scalar)
 .set_attr("FCompute", BinaryScalarOp::Compute)
 .set_attr("FGradient", 
ElemwiseGradUseIn{"_backward_minimum_scalar"});
 
+inline bool Arctan2OpType(const nnvm::NodeAttrs& attrs,
+ std::vector* in_attrs,
+ std::vector* out_attrs){
+ CHECK_EQ(in_attrs->size(), 2U);
+ CHECK_EQ(out_attrs->size(), 1U);
+
+ TYPE_ASSIGN_CHECK(*out_attrs, 0, in_attrs->at(0));
+ TYPE_ASSIGN_CHECK(*out_attrs, 0, in_attrs->at(1));
+ TYPE_ASSIGN_CHECK(*in_attrs, 0, out_attrs->at(0));
+ TYPE_ASSIGN_CHECK(*in_attrs, 1, out_attrs->at(0));
+ //check if it is float16, float32 or float64. If not, raise error
+ if(in_attrs->at(0) > 2){
+ // do not support int now.
+ std::ostringstream os;
+ os << "Do not support `int` as input.\n";
+ throw ::mxnet::op::InferTypeError(os.str(), 0);
+ }
+ return out_attrs->at(0) != -1;
 
 Review comment:
   2-space indentations, please fix for all your code


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] haojin2 commented on a change in pull request #15519: [Numpy] arctan2, a new branch for pr.

2019-07-12 Thread GitBox
haojin2 commented on a change in pull request #15519: [Numpy] arctan2, a new 
branch for pr.
URL: https://github.com/apache/incubator-mxnet/pull/15519#discussion_r302927529
 
 

 ##
 File path: src/operator/numpy/np_elemwise_broadcast_op.cc
 ##
 @@ -198,5 +198,74 @@ 
MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR(_npi_minimum_scalar)
 .set_attr("FCompute", BinaryScalarOp::Compute)
 .set_attr("FGradient", 
ElemwiseGradUseIn{"_backward_minimum_scalar"});
 
+inline bool Arctan2OpType(const nnvm::NodeAttrs& attrs,
+ std::vector* in_attrs,
+ std::vector* out_attrs){
 
 Review comment:
   ```c++
   inline bool Arctan2OpType(const nnvm::NodeAttrs& attrs,
  std::vector* in_attrs,
  std::vector* out_attrs){
   ```


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] haojin2 commented on a change in pull request #15519: [Numpy] arctan2, a new branch for pr.

2019-07-12 Thread GitBox
haojin2 commented on a change in pull request #15519: [Numpy] arctan2, a new 
branch for pr.
URL: https://github.com/apache/incubator-mxnet/pull/15519#discussion_r302927764
 
 

 ##
 File path: src/operator/numpy/np_elemwise_broadcast_op.cc
 ##
 @@ -198,5 +198,74 @@ 
MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR(_npi_minimum_scalar)
 .set_attr("FCompute", BinaryScalarOp::Compute)
 .set_attr("FGradient", 
ElemwiseGradUseIn{"_backward_minimum_scalar"});
 
+inline bool Arctan2OpType(const nnvm::NodeAttrs& attrs,
+ std::vector* in_attrs,
+ std::vector* out_attrs){
+ CHECK_EQ(in_attrs->size(), 2U);
+ CHECK_EQ(out_attrs->size(), 1U);
+
+ TYPE_ASSIGN_CHECK(*out_attrs, 0, in_attrs->at(0));
+ TYPE_ASSIGN_CHECK(*out_attrs, 0, in_attrs->at(1));
+ TYPE_ASSIGN_CHECK(*in_attrs, 0, out_attrs->at(0));
+ TYPE_ASSIGN_CHECK(*in_attrs, 1, out_attrs->at(0));
+ //check if it is float16, float32 or float64. If not, raise error
+ if(in_attrs->at(0) > 2){
+ // do not support int now.
+ std::ostringstream os;
+ os << "Do not support `int` as input.\n";
+ throw ::mxnet::op::InferTypeError(os.str(), 0);
 
 Review comment:
   indentation here?


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] haojin2 commented on a change in pull request #15519: [Numpy] arctan2, a new branch for pr.

2019-07-12 Thread GitBox
haojin2 commented on a change in pull request #15519: [Numpy] arctan2, a new 
branch for pr.
URL: https://github.com/apache/incubator-mxnet/pull/15519#discussion_r302927937
 
 

 ##
 File path: src/operator/numpy/np_elemwise_broadcast_op.cc
 ##
 @@ -198,5 +198,74 @@ 
MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR(_npi_minimum_scalar)
 .set_attr("FCompute", BinaryScalarOp::Compute)
 .set_attr("FGradient", 
ElemwiseGradUseIn{"_backward_minimum_scalar"});
 
+inline bool Arctan2OpType(const nnvm::NodeAttrs& attrs,
+ std::vector* in_attrs,
+ std::vector* out_attrs){
+ CHECK_EQ(in_attrs->size(), 2U);
+ CHECK_EQ(out_attrs->size(), 1U);
+
+ TYPE_ASSIGN_CHECK(*out_attrs, 0, in_attrs->at(0));
+ TYPE_ASSIGN_CHECK(*out_attrs, 0, in_attrs->at(1));
+ TYPE_ASSIGN_CHECK(*in_attrs, 0, out_attrs->at(0));
+ TYPE_ASSIGN_CHECK(*in_attrs, 1, out_attrs->at(0));
+ //check if it is float16, float32 or float64. If not, raise error
+ if(in_attrs->at(0) > 2){
+ // do not support int now.
+ std::ostringstream os;
+ os << "Do not support `int` as input.\n";
+ throw ::mxnet::op::InferTypeError(os.str(), 0);
+ }
+ return out_attrs->at(0) != -1;
+}
+
+NNVM_REGISTER_OP(_npi_arctan2)
+.set_num_inputs(2)
+.set_num_outputs(1)
+.set_attr("FListInputNames",
+ [](const NodeAttrs& attrs) {
+ return std::vector{"x1", "x2"};
+ })
+.set_attr("FInferShape", BinaryBroadcastShape)
+.set_attr("FInferType", Arctan2OpType)
+.set_attr("FCompute", BinaryBroadcastCompute)
+.set_attr("FGradient", 
ElemwiseGradUseIn{"_backward_npi_arctan2"})
+.set_attr("FInplaceOption",
+ [](const NodeAttrs& attrs) {
+ return std::vector >{{0, 0}};
+ })
+.add_argument("x1", "NDArray-or-Symbol", "The input array")
+.add_argument("x2", "NDArray-or-Symbol", "The input array");
+
+NNVM_REGISTER_OP(_backward_npi_arctan2)
+.set_num_inputs(3)
+.set_num_outputs(2)
+.set_attr("TIsBackward", true)
+.set_attr("FResourceRequest",
+  [](const NodeAttrs& attrs) {
+  return std::vector{ResourceRequest::kTempSpace};
+  })
+.set_attr("FCompute", 
BinaryBroadcastBackwardUseIn);
+
+MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR(_npi_arctan2_scalar)
+.set_attr("FCompute", BinaryScalarOp::Compute)
+.set_attr("FGradient", 
ElemwiseGradUseIn{"_backward_npi_arctan2_scalar"});
+
+MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR(_npi_rarctan2_scalar)
+.set_attr("FCompute", BinaryScalarOp::Compute)
+.set_attr("FGradient", 
ElemwiseGradUseIn{"_backward_npi_rarctan2_scalar"});
+
+MXNET_OPERATOR_REGISTER_BINARY(_backward_npi_arctan2_scalar)
+.add_argument("scalar", "float", "scalar value")
+.set_attr_parser([](NodeAttrs *attrs) { attrs->parsed = 
std::stod(attrs->dict["scalar"]); })
+.set_attr("FCompute", BinaryScalarOp::Backward<
+ cpu, mshadow_op::arctan2_grad>);
 
 Review comment:
   ```c++
   .set_attr("FCompute",
   BinaryScalarOp::Backward);
   ```


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] haojin2 commented on a change in pull request #15519: [Numpy] arctan2, a new branch for pr.

2019-07-12 Thread GitBox
haojin2 commented on a change in pull request #15519: [Numpy] arctan2, a new 
branch for pr.
URL: https://github.com/apache/incubator-mxnet/pull/15519#discussion_r302928018
 
 

 ##
 File path: src/operator/numpy/np_elemwise_broadcast_op.cc
 ##
 @@ -198,5 +198,74 @@ 
MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR(_npi_minimum_scalar)
 .set_attr("FCompute", BinaryScalarOp::Compute)
 .set_attr("FGradient", 
ElemwiseGradUseIn{"_backward_minimum_scalar"});
 
+inline bool Arctan2OpType(const nnvm::NodeAttrs& attrs,
+ std::vector* in_attrs,
+ std::vector* out_attrs){
+ CHECK_EQ(in_attrs->size(), 2U);
+ CHECK_EQ(out_attrs->size(), 1U);
+
+ TYPE_ASSIGN_CHECK(*out_attrs, 0, in_attrs->at(0));
+ TYPE_ASSIGN_CHECK(*out_attrs, 0, in_attrs->at(1));
+ TYPE_ASSIGN_CHECK(*in_attrs, 0, out_attrs->at(0));
+ TYPE_ASSIGN_CHECK(*in_attrs, 1, out_attrs->at(0));
+ //check if it is float16, float32 or float64. If not, raise error
+ if(in_attrs->at(0) > 2){
+ // do not support int now.
+ std::ostringstream os;
+ os << "Do not support `int` as input.\n";
+ throw ::mxnet::op::InferTypeError(os.str(), 0);
+ }
+ return out_attrs->at(0) != -1;
+}
+
+NNVM_REGISTER_OP(_npi_arctan2)
+.set_num_inputs(2)
+.set_num_outputs(1)
+.set_attr("FListInputNames",
+ [](const NodeAttrs& attrs) {
+ return std::vector{"x1", "x2"};
+ })
+.set_attr("FInferShape", BinaryBroadcastShape)
+.set_attr("FInferType", Arctan2OpType)
+.set_attr("FCompute", BinaryBroadcastCompute)
+.set_attr("FGradient", 
ElemwiseGradUseIn{"_backward_npi_arctan2"})
+.set_attr("FInplaceOption",
+ [](const NodeAttrs& attrs) {
+ return std::vector >{{0, 0}};
+ })
+.add_argument("x1", "NDArray-or-Symbol", "The input array")
+.add_argument("x2", "NDArray-or-Symbol", "The input array");
+
+NNVM_REGISTER_OP(_backward_npi_arctan2)
+.set_num_inputs(3)
+.set_num_outputs(2)
+.set_attr("TIsBackward", true)
+.set_attr("FResourceRequest",
+  [](const NodeAttrs& attrs) {
+  return std::vector{ResourceRequest::kTempSpace};
+  })
+.set_attr("FCompute", 
BinaryBroadcastBackwardUseIn);
+
+MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR(_npi_arctan2_scalar)
+.set_attr("FCompute", BinaryScalarOp::Compute)
+.set_attr("FGradient", 
ElemwiseGradUseIn{"_backward_npi_arctan2_scalar"});
+
+MXNET_OPERATOR_REGISTER_NP_BINARY_SCALAR(_npi_rarctan2_scalar)
+.set_attr("FCompute", BinaryScalarOp::Compute)
+.set_attr("FGradient", 
ElemwiseGradUseIn{"_backward_npi_rarctan2_scalar"});
+
+MXNET_OPERATOR_REGISTER_BINARY(_backward_npi_arctan2_scalar)
+.add_argument("scalar", "float", "scalar value")
+.set_attr_parser([](NodeAttrs *attrs) { attrs->parsed = 
std::stod(attrs->dict["scalar"]); })
+.set_attr("FCompute", BinaryScalarOp::Backward<
+ cpu, mshadow_op::arctan2_grad>);
 
 Review comment:
   Similar for the case below.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] haojin2 commented on a change in pull request #15519: [Numpy] arctan2, a new branch for pr.

2019-07-12 Thread GitBox
haojin2 commented on a change in pull request #15519: [Numpy] arctan2, a new 
branch for pr.
URL: https://github.com/apache/incubator-mxnet/pull/15519#discussion_r302928599
 
 

 ##
 File path: tests/python/gpu/test_operator_gpu.py
 ##
 @@ -2300,6 +2300,81 @@ def test_math():
 for op in ops:
 run_math(op, shape, dtype, check_value=check_value)
 
+@with_seed()
+@npx.use_np_shape
+def test_np_arctan2():
+@npx.use_np_shape
+class TestArctan2(HybridBlock):
+def __init__(self):
+super(TestArctan2, self).__init__()
+
+def hybrid_forward(self, F, x1, x2):
+return F.np.arctan2(x1, x2)
+
+#Reduce dimension of src to dimention of des.
+def dimReduce(src, des):
+srcShape = src.shape
+desShape = des.shape
+if len(desShape) == 0:
+return src.sum()
+redu = []
+for i, j in zip(range(len(srcShape)-1, -1, -1), range(len(desShape)-1, 
-1, -1)):
+if srcShape[i] != desShape[j] and desShape[j] == 1:
+redu.append(i)
+if j == 0:
+for k in range(0, i):
+redu.append(k)
+break
+if len(redu) > 0:
+src = np.reshape(src.sum(axis=tuple(redu)), desShape)
+return src
+
+types = ['float64', 'float32', 'float16']
+for hybridize in [True, False]:
+for shape1, shape2 in [[(1,), (1,)],  # single elements
+[(4, 5), (4, 5)],  # normal case
+[(3, 2), (3, 2)],  # tall matrices
+[(), ()],  # scalar only
+[(3, 0, 2), (3, 0, 2)],  # zero-dim
+[(3, 4, 5), (4, 1)],  # trailing dim 
broadcasting
+[(3, 4, 5), ()],  # scalar broadcasting
+[(), (1, 2, 3)],  # scalar broadcasting
+[(4, 3), (4, 1)],  # single 
broadcasting
+[(3, 4, 5), (3, 1, 5)]  # single 
broadcasting in the middle
+]:
 
 Review comment:
   Align lines:
   ```python
   for shape1, shape2 in [[(1,), (1,)],  # single elements
  [(4, 5), (4, 5)],  # normal case
  [(3, 2), (3, 2)],  # tall matrices
  [(), ()],  # scalar only
  [(3, 0, 2), (3, 0, 2)],  # zero-dim
  [(3, 4, 5), (4, 1)],  # trailing dim 
broadcasting
  [(3, 4, 5), ()],  # scalar broadcasting
  [(), (1, 2, 3)],  # scalar broadcasting
  [(4, 3), (4, 1)],  # single broadcasting
  [(3, 4, 5), (3, 1, 5)]  # single broadcasting 
in the middle
  ]:
   ```


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] haojin2 commented on a change in pull request #15519: [Numpy] arctan2, a new branch for pr.

2019-07-12 Thread GitBox
haojin2 commented on a change in pull request #15519: [Numpy] arctan2, a new 
branch for pr.
URL: https://github.com/apache/incubator-mxnet/pull/15519#discussion_r302928820
 
 

 ##
 File path: src/operator/numpy/np_elemwise_broadcast_op.cu
 ##
 @@ -42,6 +42,12 @@ NNVM_REGISTER_OP(_npi_mod)
 NNVM_REGISTER_OP(_npi_power)
 .set_attr("FCompute", BinaryBroadcastCompute);
 
+NNVM_REGISTER_OP(_npi_arctan2)
+.set_attr("FCompute", BinaryBroadcastCompute);
+
+NNVM_REGISTER_OP(_backward_npi_arctan2)
+.set_attr("FCompute", 
BinaryBroadcastBackwardUseIn);
 
 Review comment:
   one more blank line below.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] haojin2 commented on a change in pull request #15519: [Numpy] arctan2, a new branch for pr.

2019-07-12 Thread GitBox
haojin2 commented on a change in pull request #15519: [Numpy] arctan2, a new 
branch for pr.
URL: https://github.com/apache/incubator-mxnet/pull/15519#discussion_r302928682
 
 

 ##
 File path: tests/python/gpu/test_operator_gpu.py
 ##
 @@ -2300,6 +2300,81 @@ def test_math():
 for op in ops:
 run_math(op, shape, dtype, check_value=check_value)
 
+@with_seed()
+@npx.use_np_shape
+def test_np_arctan2():
+@npx.use_np_shape
+class TestArctan2(HybridBlock):
+def __init__(self):
+super(TestArctan2, self).__init__()
+
+def hybrid_forward(self, F, x1, x2):
+return F.np.arctan2(x1, x2)
+
+#Reduce dimension of src to dimention of des.
+def dimReduce(src, des):
+srcShape = src.shape
+desShape = des.shape
+if len(desShape) == 0:
+return src.sum()
+redu = []
+for i, j in zip(range(len(srcShape)-1, -1, -1), range(len(desShape)-1, 
-1, -1)):
+if srcShape[i] != desShape[j] and desShape[j] == 1:
+redu.append(i)
+if j == 0:
+for k in range(0, i):
+redu.append(k)
+break
+if len(redu) > 0:
+src = np.reshape(src.sum(axis=tuple(redu)), desShape)
+return src
+
+types = ['float64', 'float32', 'float16']
+for hybridize in [True, False]:
+for shape1, shape2 in [[(1,), (1,)],  # single elements
+[(4, 5), (4, 5)],  # normal case
+[(3, 2), (3, 2)],  # tall matrices
+[(), ()],  # scalar only
+[(3, 0, 2), (3, 0, 2)],  # zero-dim
+[(3, 4, 5), (4, 1)],  # trailing dim 
broadcasting
+[(3, 4, 5), ()],  # scalar broadcasting
+[(), (1, 2, 3)],  # scalar broadcasting
+[(4, 3), (4, 1)],  # single 
broadcasting
+[(3, 4, 5), (3, 1, 5)]  # single 
broadcasting in the middle
+]:
+for oneType in types:
+if oneType == 'float16':
+rtol=1e-2
+atol = 1e-2
+else:
+rtol=1e-3
+atol = 1e-5
+test_arctan2 = TestArctan2()
+if hybridize:
+test_arctan2.hybridize()
+x1 = rand_ndarray(shape1, dtype=oneType).as_np_ndarray()
+x2 = rand_ndarray(shape2, dtype=oneType).as_np_ndarray()
+x11 = x1.asnumpy()
+x21 = x2.asnumpy()
+x1.attach_grad()
+x2.attach_grad()
+np_out = np.arctan2(x1.asnumpy(), x2.asnumpy())
+with mx.autograd.record():
+mx_out = test_arctan2(x1, x2)
+assert mx_out.shape == np_out.shape
+assert_almost_equal(mx_out.asnumpy(), np_out, rtol=rtol, 
atol=atol)
+mx_out.backward()
+np_backward_1 = x21 / (x11 * x11 + x21 * x21)
+np_backward_2 = -1 * x11 / (x11 * x11 + x21 * x21)
+np_backward_1 = dimReduce(np_backward_1, x11)
+np_backward_2 = dimReduce(np_backward_2, x21)
+assert_almost_equal(x1.grad.asnumpy(), np_backward_1, 
rtol=rtol, atol=atol)
+assert_almost_equal(x2.grad.asnumpy(), np_backward_2, 
rtol=rtol, atol=atol)
+
+mx_out = mx.np.arctan2(x1, x2)
+np_out = np.arctan2(x1.asnumpy(), x2.asnumpy())
+assert_almost_equal(mx_out.asnumpy(), np_out, rtol=rtol, 
atol=atol)
+
 
 Review comment:
   one more blank line below


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] haojin2 commented on a change in pull request #15519: [Numpy] arctan2, a new branch for pr.

2019-07-12 Thread GitBox
haojin2 commented on a change in pull request #15519: [Numpy] arctan2, a new 
branch for pr.
URL: https://github.com/apache/incubator-mxnet/pull/15519#discussion_r302928767
 
 

 ##
 File path: tests/python/gpu/test_operator_gpu.py
 ##
 @@ -2300,6 +2300,81 @@ def test_math():
 for op in ops:
 run_math(op, shape, dtype, check_value=check_value)
 
+@with_seed()
 
 Review comment:
   One more blank line above, 2 blank lines between functions.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] haojin2 commented on issue #15169: Softmax with length

2019-07-12 Thread GitBox
haojin2 commented on issue #15169: Softmax with length
URL: https://github.com/apache/incubator-mxnet/pull/15169#issuecomment-510842258
 
 
   @apeforest Trust me or not, I've tried what you're suggesting to do on my 
end way before this PR was raised but found it not easily done without 
affecting the existing softmax's performance by much. I think I'll stick to 
this version for now.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] haojin2 commented on a change in pull request #15169: Softmax with length

2019-07-12 Thread GitBox
haojin2 commented on a change in pull request #15169: Softmax with length
URL: https://github.com/apache/incubator-mxnet/pull/15169#discussion_r302931319
 
 

 ##
 File path: src/operator/nn/softmax-inl.h
 ##
 @@ -464,35 +755,56 @@ void SoftmaxGradCompute(const nnvm::NodeAttrs& attrs,
   mxnet::TShape shape = AxisShapeCompact(inputs[0].shape_, &axis, true);
 
   int out_idx = softmax_has_dtype_override(attrs) ? 2 : 1;
+  out_idx = softmax_use_length(attrs) ? 3 : out_idx;
   bool safe_acc = dmlc::GetEnv("MXNET_SAFE_ACCUMULATION", false);
 
   MXNET_REAL_ACC_TYPE_SWITCH(inputs[0].type_flag_, OType, AType, {
 MSHADOW_REAL_TYPE_SWITCH(outputs[0].type_flag_, DType, {
   MXNET_ASSIGN_REQ_SWITCH(req[0], Req, {
-if (safe_acc) {
-  if (shape.ndim() == 2) {
-SoftmaxGrad(
-ctx.get_stream(), inputs[out_idx].dptr(),
-inputs[0].dptr(), outputs[0].dptr(),
-shape.get<2>(), axis, static_cast(temperature));
+if (!softmax_use_length(attrs)) {
+  if (safe_acc) {
+if (shape.ndim() == 2) {
+  SoftmaxGrad(
+  ctx.get_stream(), inputs[out_idx].dptr(),
+  inputs[0].dptr(), outputs[0].dptr(),
+  shape.get<2>(), axis, static_cast(temperature));
+} else {
+  SoftmaxGrad(
+  ctx.get_stream(), inputs[out_idx].dptr(),
+  inputs[0].dptr(), outputs[0].dptr(),
+  shape.get<3>(), axis, static_cast(temperature));
+}
   } else {
-SoftmaxGrad(
-ctx.get_stream(), inputs[out_idx].dptr(),
-inputs[0].dptr(), outputs[0].dptr(),
-shape.get<3>(), axis, static_cast(temperature));
+if (shape.ndim() == 2) {
+  SoftmaxGrad(
+  ctx.get_stream(), inputs[out_idx].dptr(),
+  inputs[0].dptr(), outputs[0].dptr(),
+  shape.get<2>(), axis, static_cast(temperature));
+} else {
+  SoftmaxGrad(
+  ctx.get_stream(), inputs[out_idx].dptr(),
+  inputs[0].dptr(), outputs[0].dptr(),
+  shape.get<3>(), axis, static_cast(temperature));
+}
   }
 } else {
-  if (shape.ndim() == 2) {
-SoftmaxGrad(
+  MXNET_INT_TYPE_SWITCH(inputs[2].type_flag_, IType, {
 
 Review comment:
   It may not necessarily be int64_t, and what do you mean by "cast the type to 
int64_t"? Allocating a new buffer on the fly within the operator to hold the 
casted `length` input? I would consider that a big performance bottleneck.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] haojin2 commented on a change in pull request #15169: Softmax with length

2019-07-12 Thread GitBox
haojin2 commented on a change in pull request #15169: Softmax with length
URL: https://github.com/apache/incubator-mxnet/pull/15169#discussion_r302931406
 
 

 ##
 File path: src/operator/nn/softmax-inl.h
 ##
 @@ -113,6 +113,60 @@ inline void Softmax(Stream *s, DType *in, OType *out,
   }
 }
 
+template
+inline void SoftmaxWithLength(Stream *s, DType *in, OType *out, IType 
*length,
 
 Review comment:
   Answered below.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] haojin2 commented on a change in pull request #15169: Softmax with length

2019-07-12 Thread GitBox
haojin2 commented on a change in pull request #15169: Softmax with length
URL: https://github.com/apache/incubator-mxnet/pull/15169#discussion_r302931553
 
 

 ##
 File path: tests/python/unittest/test_operator.py
 ##
 @@ -7838,6 +7871,7 @@ def get_output_names_callback(name, arr):
 except mx.base.MXNetError:
 # skip errors since test is to check all names
 pass
+print(output_names)
 
 Review comment:
   Done.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] haojin2 commented on a change in pull request #15169: Softmax with length

2019-07-12 Thread GitBox
haojin2 commented on a change in pull request #15169: Softmax with length
URL: https://github.com/apache/incubator-mxnet/pull/15169#discussion_r302932168
 
 

 ##
 File path: src/operator/nn/softmax-inl.h
 ##
 @@ -464,35 +755,56 @@ void SoftmaxGradCompute(const nnvm::NodeAttrs& attrs,
   mxnet::TShape shape = AxisShapeCompact(inputs[0].shape_, &axis, true);
 
   int out_idx = softmax_has_dtype_override(attrs) ? 2 : 1;
+  out_idx = softmax_use_length(attrs) ? 3 : out_idx;
   bool safe_acc = dmlc::GetEnv("MXNET_SAFE_ACCUMULATION", false);
 
   MXNET_REAL_ACC_TYPE_SWITCH(inputs[0].type_flag_, OType, AType, {
 MSHADOW_REAL_TYPE_SWITCH(outputs[0].type_flag_, DType, {
   MXNET_ASSIGN_REQ_SWITCH(req[0], Req, {
-if (safe_acc) {
-  if (shape.ndim() == 2) {
-SoftmaxGrad(
-ctx.get_stream(), inputs[out_idx].dptr(),
-inputs[0].dptr(), outputs[0].dptr(),
-shape.get<2>(), axis, static_cast(temperature));
+if (!softmax_use_length(attrs)) {
 
 Review comment:
   The `length` is a tensor, not a single value. Please read the test cases 
carefully.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] apeforest commented on a change in pull request #15490: Utility to help developers debug operators: Tensor Inspector

2019-07-12 Thread GitBox
apeforest commented on a change in pull request #15490: Utility to help 
developers debug operators: Tensor Inspector
URL: https://github.com/apache/incubator-mxnet/pull/15490#discussion_r302933381
 
 

 ##
 File path: src/common/tensor_inspector.h
 ##
 @@ -0,0 +1,733 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*!
+ * Copyright (c) 2019 by Contributors
+ * \file tensor_inspector.h
+ * \brief utility to inspect tensor objects
+ * \author Zhaoqi Zhu
+ */
+
+#ifndef MXNET_COMMON_TENSOR_INSPECTOR_H_
+#define MXNET_COMMON_TENSOR_INSPECTOR_H_
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "../../3rdparty/mshadow/mshadow/base.h"
+#include "../../tests/cpp/include/test_util.h"
+
+namespace mxnet {
+
+/*!
+ * \brief this singleton struct mediates individual TensorInspector objects
+ * so that we can control the global behavior from each of them
+ */
+struct InspectorManager {
+  static InspectorManager* get() {
+static std::mutex mtx;
+static std::unique_ptr im = nullptr;
+if (!im) {
+  std::unique_lock lk(mtx);
+  if (!im)
+im = std::make_unique();
+}
+return im.get();
+  }
+  /* !\brief mutex used to lock interactive_print() and check_value() */
+  std::mutex mutex_;
+  /* !\brief skip all interactive prints */
+  bool interactive_print_skip_all_ = false;
+  /* !\brief skip all value checks */
+  bool check_value_skip_all_ = false;
+  /* !\brief visit count for interactive print tags */
+  std::unordered_map interactive_print_tag_counter_;
+  /* !\brief visit count for check value tags */
+  std::unordered_map check_value_tag_counter_;
+  /* !\brief visit count for dump value tags */
+  std::unordered_map dump_value_tag_counter_;
+};
+
+/*!
+ * \brief Enum for building value checkers for TensorInspector::check_value()
+ */
+enum CheckerType {
+  NegativeChecker,  // check if is negative
+  PositiveChecker,  // check if is positive
+  ZeroChecker,  // check if is zero
+  NaNChecker,  // check if is NaN, will always return false if DType is not a 
float type
+  InfChecker,  // check if is infinity, will always return false if DType is 
not a float type
+  PositiveInfChecker,  // check if is positive infinity,
+   // will always return false if DType is not a float type
+  NegativeInfChecker,  // check if is nagative infinity,
+   // will always return false if DType is not a float type
+  FiniteChecker,  // check if is finite, will always return false if DType is 
not a float type
+  NormalChecker,  // check if is neither infinity nor NaN
+  AbnormalChecker,  // chekck if is infinity or nan
+};
+
+/**
+ *  ___  _   _ 
+ * |__   __||_   _| | |
+ *| | ___ _ __  ___  ___  _ __| |  _ __  ___ _ __   ___  ___| |_ ___  _ __ 
+ *| |/ _ \ '_ \/ __|/ _ \| '__| | | '_ \/ __| '_ \ / _ \/ __| __/ _ \| '__|
+ *| |  __/ | | \__ \ (_) | | _| |_| | | \__ \ |_) |  __/ (__| || (_) | |   
+ *|_|\___|_| |_|___/\___/|_||_|_| |_|___/ .__/ \___|\___|\__\___/|_|   
+ *  | |
+ *  |_|   
+ */
+
+/*!
+ * \brief This class provides a unified interface to inspect the value of all 
data types
+ * including Tensor, TBlob, and NDArray. If the tensor resides on GPU, then it 
will be
+ * copied from GPU memory back to CPU memory to be operated on. Internally, 
all data types
+ * are stored as a TBlob object tb_.
+ */
+class TensorInspector {
+ private:
+  /*!
+   * \brief generate the tensor info, including data type and shape 
+   * \tparam DType the data type
+   * \tparam StreamType the type of the stream object
+   * \param os stream object to output to
+   */
+  template
+  inline void tensor_info_to_string(StreamType* os) {
+int dimension = tb_.ndim();
+*os << "<" << typeid(tb_.dptr()[0]).name() << " Tensor ";
+*os << tb_.shape_[0];
+for (int i = 1; i < dimension; i++) {
 
 Review comment:
   nit: use ++i for performance


This is

[GitHub] [incubator-mxnet] apeforest commented on a change in pull request #15490: Utility to help developers debug operators: Tensor Inspector

2019-07-12 Thread GitBox
apeforest commented on a change in pull request #15490: Utility to help 
developers debug operators: Tensor Inspector
URL: https://github.com/apache/incubator-mxnet/pull/15490#discussion_r302934098
 
 

 ##
 File path: src/common/tensor_inspector.h
 ##
 @@ -0,0 +1,733 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*!
+ * Copyright (c) 2019 by Contributors
+ * \file tensor_inspector.h
+ * \brief utility to inspect tensor objects
+ * \author Zhaoqi Zhu
+ */
+
+#ifndef MXNET_COMMON_TENSOR_INSPECTOR_H_
+#define MXNET_COMMON_TENSOR_INSPECTOR_H_
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "../../3rdparty/mshadow/mshadow/base.h"
+#include "../../tests/cpp/include/test_util.h"
+
+namespace mxnet {
+
+/*!
+ * \brief this singleton struct mediates individual TensorInspector objects
+ * so that we can control the global behavior from each of them
+ */
+struct InspectorManager {
+  static InspectorManager* get() {
+static std::mutex mtx;
+static std::unique_ptr im = nullptr;
+if (!im) {
+  std::unique_lock lk(mtx);
+  if (!im)
+im = std::make_unique();
+}
+return im.get();
+  }
+  /* !\brief mutex used to lock interactive_print() and check_value() */
+  std::mutex mutex_;
+  /* !\brief skip all interactive prints */
+  bool interactive_print_skip_all_ = false;
+  /* !\brief skip all value checks */
+  bool check_value_skip_all_ = false;
+  /* !\brief visit count for interactive print tags */
+  std::unordered_map interactive_print_tag_counter_;
+  /* !\brief visit count for check value tags */
+  std::unordered_map check_value_tag_counter_;
+  /* !\brief visit count for dump value tags */
+  std::unordered_map dump_value_tag_counter_;
+};
+
+/*!
+ * \brief Enum for building value checkers for TensorInspector::check_value()
+ */
+enum CheckerType {
+  NegativeChecker,  // check if is negative
+  PositiveChecker,  // check if is positive
+  ZeroChecker,  // check if is zero
+  NaNChecker,  // check if is NaN, will always return false if DType is not a 
float type
+  InfChecker,  // check if is infinity, will always return false if DType is 
not a float type
+  PositiveInfChecker,  // check if is positive infinity,
+   // will always return false if DType is not a float type
+  NegativeInfChecker,  // check if is nagative infinity,
+   // will always return false if DType is not a float type
+  FiniteChecker,  // check if is finite, will always return false if DType is 
not a float type
+  NormalChecker,  // check if is neither infinity nor NaN
+  AbnormalChecker,  // chekck if is infinity or nan
+};
+
+/**
+ *  ___  _   _ 
+ * |__   __||_   _| | |
+ *| | ___ _ __  ___  ___  _ __| |  _ __  ___ _ __   ___  ___| |_ ___  _ __ 
+ *| |/ _ \ '_ \/ __|/ _ \| '__| | | '_ \/ __| '_ \ / _ \/ __| __/ _ \| '__|
+ *| |  __/ | | \__ \ (_) | | _| |_| | | \__ \ |_) |  __/ (__| || (_) | |   
+ *|_|\___|_| |_|___/\___/|_||_|_| |_|___/ .__/ \___|\___|\__\___/|_|   
+ *  | |
+ *  |_|   
+ */
+
+/*!
+ * \brief This class provides a unified interface to inspect the value of all 
data types
+ * including Tensor, TBlob, and NDArray. If the tensor resides on GPU, then it 
will be
+ * copied from GPU memory back to CPU memory to be operated on. Internally, 
all data types
+ * are stored as a TBlob object tb_.
+ */
+class TensorInspector {
+ private:
+  /*!
+   * \brief generate the tensor info, including data type and shape 
+   * \tparam DType the data type
+   * \tparam StreamType the type of the stream object
+   * \param os stream object to output to
+   */
+  template
+  inline void tensor_info_to_string(StreamType* os) {
+int dimension = tb_.ndim();
+*os << "<" << typeid(tb_.dptr()[0]).name() << " Tensor ";
+*os << tb_.shape_[0];
+for (int i = 1; i < dimension; i++) {
+  *os << 'x' << tb_.shape_[i];
+}
+*os << ">" << std::endl;
+  }
+
+  /*!
+   * \brief output the tensor info, 

[GitHub] [incubator-mxnet] apeforest commented on a change in pull request #15490: Utility to help developers debug operators: Tensor Inspector

2019-07-12 Thread GitBox
apeforest commented on a change in pull request #15490: Utility to help 
developers debug operators: Tensor Inspector
URL: https://github.com/apache/incubator-mxnet/pull/15490#discussion_r302935550
 
 

 ##
 File path: src/common/tensor_inspector.h
 ##
 @@ -0,0 +1,733 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*!
+ * Copyright (c) 2019 by Contributors
+ * \file tensor_inspector.h
+ * \brief utility to inspect tensor objects
+ * \author Zhaoqi Zhu
+ */
+
+#ifndef MXNET_COMMON_TENSOR_INSPECTOR_H_
+#define MXNET_COMMON_TENSOR_INSPECTOR_H_
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "../../3rdparty/mshadow/mshadow/base.h"
+#include "../../tests/cpp/include/test_util.h"
+
+namespace mxnet {
+
+/*!
+ * \brief this singleton struct mediates individual TensorInspector objects
+ * so that we can control the global behavior from each of them
+ */
+struct InspectorManager {
+  static InspectorManager* get() {
+static std::mutex mtx;
+static std::unique_ptr im = nullptr;
+if (!im) {
+  std::unique_lock lk(mtx);
+  if (!im)
+im = std::make_unique();
+}
+return im.get();
+  }
+  /* !\brief mutex used to lock interactive_print() and check_value() */
+  std::mutex mutex_;
+  /* !\brief skip all interactive prints */
+  bool interactive_print_skip_all_ = false;
+  /* !\brief skip all value checks */
+  bool check_value_skip_all_ = false;
+  /* !\brief visit count for interactive print tags */
+  std::unordered_map interactive_print_tag_counter_;
+  /* !\brief visit count for check value tags */
+  std::unordered_map check_value_tag_counter_;
+  /* !\brief visit count for dump value tags */
+  std::unordered_map dump_value_tag_counter_;
+};
+
+/*!
+ * \brief Enum for building value checkers for TensorInspector::check_value()
+ */
+enum CheckerType {
+  NegativeChecker,  // check if is negative
+  PositiveChecker,  // check if is positive
+  ZeroChecker,  // check if is zero
+  NaNChecker,  // check if is NaN, will always return false if DType is not a 
float type
+  InfChecker,  // check if is infinity, will always return false if DType is 
not a float type
+  PositiveInfChecker,  // check if is positive infinity,
+   // will always return false if DType is not a float type
+  NegativeInfChecker,  // check if is nagative infinity,
+   // will always return false if DType is not a float type
+  FiniteChecker,  // check if is finite, will always return false if DType is 
not a float type
+  NormalChecker,  // check if is neither infinity nor NaN
+  AbnormalChecker,  // chekck if is infinity or nan
+};
+
+/**
+ *  ___  _   _ 
+ * |__   __||_   _| | |
+ *| | ___ _ __  ___  ___  _ __| |  _ __  ___ _ __   ___  ___| |_ ___  _ __ 
+ *| |/ _ \ '_ \/ __|/ _ \| '__| | | '_ \/ __| '_ \ / _ \/ __| __/ _ \| '__|
+ *| |  __/ | | \__ \ (_) | | _| |_| | | \__ \ |_) |  __/ (__| || (_) | |   
+ *|_|\___|_| |_|___/\___/|_||_|_| |_|___/ .__/ \___|\___|\__\___/|_|   
+ *  | |
+ *  |_|   
+ */
+
+/*!
+ * \brief This class provides a unified interface to inspect the value of all 
data types
+ * including Tensor, TBlob, and NDArray. If the tensor resides on GPU, then it 
will be
+ * copied from GPU memory back to CPU memory to be operated on. Internally, 
all data types
+ * are stored as a TBlob object tb_.
+ */
+class TensorInspector {
+ private:
+  /*!
+   * \brief generate the tensor info, including data type and shape 
+   * \tparam DType the data type
+   * \tparam StreamType the type of the stream object
+   * \param os stream object to output to
+   */
+  template
+  inline void tensor_info_to_string(StreamType* os) {
+int dimension = tb_.ndim();
+*os << "<" << typeid(tb_.dptr()[0]).name() << " Tensor ";
+*os << tb_.shape_[0];
+for (int i = 1; i < dimension; i++) {
+  *os << 'x' << tb_.shape_[i];
+}
+*os << ">" << std::endl;
+  }
+
+  /*!
+   * \brief output the tensor info, 

[GitHub] [incubator-mxnet] braindotai commented on issue #15496: Loaded pretrained model but train accuracy starts from zero,

2019-07-12 Thread GitBox
braindotai commented on issue #15496: Loaded pretrained model but train 
accuracy starts from zero,
URL: 
https://github.com/apache/incubator-mxnet/issues/15496#issuecomment-510847042
 
 
   Below code should work
   ```python
   model.save_checkpoint('model', epoch = 0)
   
   sym, arg_params, aux_params = mx.model.load_checkpoint('model', epoch = 0)
   
   model = mx.mod.Module(sym, context = mx.gpu())
   model.bind(data_shapes = train_data.provide_data, label_shapes = 
train_data.provide_label)
   model.set_params(arg_params, aux_params)
   
   ```


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] apeforest commented on issue #15490: Utility to help developers debug operators: Tensor Inspector

2019-07-12 Thread GitBox
apeforest commented on issue #15490: Utility to help developers debug 
operators: Tensor Inspector
URL: https://github.com/apache/incubator-mxnet/pull/15490#issuecomment-510847250
 
 
   @eric-haibin-lin This utility looks really useful for debugging mxnet 
backend. Please take a look if interested.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] marcoabreu commented on issue #15506: Improving error message

2019-07-12 Thread GitBox
marcoabreu commented on issue #15506: Improving error message
URL: 
https://github.com/apache/incubator-mxnet/issues/15506#issuecomment-510860930
 
 
   I think that this error is a quite standard one. Considering that the 
compiler might write to a lot of locations due to optimizations, I don't think 
that we can safely tell which partition in particular is too small.
   
   To avoid giving false leads, I wouldn't improve the error message here. As 
long as the error is really related to disk or ram space, it should be straight 
forward to solve it.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] wkcn commented on issue #15499: Improve diagnose.py, adding build features info and binary library path.

2019-07-12 Thread GitBox
wkcn commented on issue #15499: Improve diagnose.py, adding build features info 
and binary library path.
URL: https://github.com/apache/incubator-mxnet/pull/15499#issuecomment-510861117
 
 
   Thank you for the improvement!
   
   I have a suggestion : )
   Could we only print the relative path?
   Some users don't like the printing of the absolute path with their privacy.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] wkcn edited a comment on issue #15499: Improve diagnose.py, adding build features info and binary library path.

2019-07-12 Thread GitBox
wkcn edited a comment on issue #15499: Improve diagnose.py, adding build 
features info and binary library path.
URL: https://github.com/apache/incubator-mxnet/pull/15499#issuecomment-510861117
 
 
   Thank you for the improvement! LGTM.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] pengzhao-intel edited a comment on issue #13598: More fine-grained operator implementation dispatch & memory planning flow

2019-07-12 Thread GitBox
pengzhao-intel edited a comment on issue #13598: More fine-grained operator 
implementation dispatch & memory planning flow 
URL: 
https://github.com/apache/incubator-mxnet/issues/13598#issuecomment-472725241
 
 
   @danithaca Tao has answered the question in the forum :) thanks to raising 
the question.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] KhurramPirov commented on issue #15504: Saved model and then looked at the output of the same batch after loading, got different results!

2019-07-12 Thread GitBox
KhurramPirov commented on issue #15504: Saved model and then looked at the 
output of the same batch after loading, got different results!
URL: 
https://github.com/apache/incubator-mxnet/issues/15504#issuecomment-510873701
 
 
   It doesn't work inside batch_callback.
   
   пт, 12 июл. 2019 г. в 13:03, Rishik Mourya :
   
   > Make sure you are saving and loading the model from the same path. I've
   > tested the code below and it is working fine.
   >
   > for batch in data_iter:
   > model.forward(batch)
   > out1 = model.get_outputs()[0]
   > break
   > model.save_checkpoint('model', epoch = 0)
   > sym, arg_params, aux_params = mx.model.load_checkpoint('model', epoch = 0)
   > model.set_params(arg_params, aux_params)
   > model.forward(batch)
   > out2 = model.get_outputs()[0]print(f'diff_output:{nd.abs(out1 - out2)}')
   >
   > Output is all zeros.
   >
   > —
   > You are receiving this because you were mentioned.
   > Reply to this email directly, view it on GitHub
   > 
,
   > or mute the thread
   > 

   > .
   >
   
   
   -- 
   Khurram Pirov
   skype: matrixrextended
   mob: +7-916-439-53-76
   


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] KhurramPirov commented on issue #15496: Loaded pretrained model but train accuracy starts from zero,

2019-07-12 Thread GitBox
KhurramPirov commented on issue #15496: Loaded pretrained model but train 
accuracy starts from zero,
URL: 
https://github.com/apache/incubator-mxnet/issues/15496#issuecomment-510873847
 
 
   It doesn't work inside batch_callback and model.fit.
   
   пт, 12 июл. 2019 г. в 14:08, Rishik Mourya :
   
   > Below code should work
   >
   > model.save_checkpoint('model', epoch = 0)
   >
   > sym, arg_params, aux_params = mx.model.load_checkpoint('model', epoch = 0)
   >
   > model = mx.mod.Module(sym, context = mx.gpu())
   > model.bind(data_shapes = train_data.provide_data, label_shapes = 
train_data.provide_label)
   > model.set_params(arg_params, aux_params)
   >
   > —
   > You are receiving this because you were mentioned.
   > Reply to this email directly, view it on GitHub
   > 
,
   > or mute the thread
   > 

   > .
   >
   
   
   -- 
   Khurram Pirov
   skype: matrixrextended
   mob: +7-916-439-53-76
   


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] gxkevin opened a new issue #15520: most time cost in NDArray GetData() func

2019-07-12 Thread GitBox
gxkevin opened a new issue #15520: most time cost in NDArray GetData() func
URL: https://github.com/apache/incubator-mxnet/issues/15520
 
 
My predict code is like this, I have 32 worker thread, each has 1 openmp 
thread, the mxnet engine is NaiveEngine , using the openblas, disable the 
mkldnn, running the code on the Skylatex machine, using the avx512, but it is 
not faster than the avx2, I don't know why?
   
   And what's more, the naiveEngine means that all the funcs are 
sequential?(not asynchronous?)
   In this condition, the WaitAll() func should removed?
   
   what's more , I found that the most time is the NDArray.GetData(), about 
17ms, and the Forward() cost 6ms, why GetData() cost so much time? How to 
increase the proformance?
   the Avx512 doesn't work.
   
   dnn_model->model_data["data"].SyncCopyFromCPU(batch_data.data(), 
batch_size * fea_num);
   mxnet::cpp::NDArray::WaitAll();
   dnn_model->exec->Forward(false);
   mxnet::cpp::NDArray::WaitAll();
   uint32_t output_num = dnn_model->exec->outputs.size();
   for (uint32_t j = 0; j < b_num; j++) {
   for (uint32_t q_idx = 0; q_idx < output_num; q_idx++) {
   //cvm_q_t* item = result + ins_idx;
   //item->q[q_idx]  = 
dnn_model->exec->outputs[q_idx].GetData()[j];
   _result[ins_index][q_idx] = 
dnn_model->exec->outputs[q_idx].GetData()[j];
   CVM_DEBUG_LOG("ins_index:%u  q_idx %u q:%f", ins_index, 
q_idx, _result[ins_index][q_idx]);
   }
ins_index += 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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] mikemwx commented on issue #15302: [Numpy] Numpy hstack

2019-07-12 Thread GitBox
mikemwx commented on issue #15302: [Numpy] Numpy hstack
URL: https://github.com/apache/incubator-mxnet/pull/15302#issuecomment-510876247
 
 
   > LGTM, remember to add examples to the doc and it will be good for merge
   
   Docs are added


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] smissan closed issue #15514: dmlc.lib is not generated

2019-07-12 Thread GitBox
smissan closed issue #15514: dmlc.lib is not generated
URL: https://github.com/apache/incubator-mxnet/issues/15514
 
 
   


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] braindotai commented on issue #12185: from_logits definition seems different from what is expected?

2019-07-12 Thread GitBox
braindotai commented on issue #12185: from_logits definition seems different 
from what is expected?
URL: 
https://github.com/apache/incubator-mxnet/issues/12185#issuecomment-510939653
 
 
   [Check this 
out](https://www.tensorflow.org/api_docs/python/tf/nn/softmax_cross_entropy_with_logits)
   Here it says "logits: Per-label activations, typically a linear output", 
which means `nd.dot(x, w) + b` in terms of MXNet. 
   There are actually two versions of logits, first is simply the linear 
layer(as mentions in the above link), and second is the unscaled log 
probabilities. That is the reason Tensorflow provided 2 versions of 
"softmax_cross_entropy_with_logits".
   
   In MXNet mx.gluon.loss.SoftmaxCrossEntropyLoss accepts the linear 
output(`nd.dot(x, w) + b`) as output in the argument. 
   You can check 
[here](https://gluon.mxnet.io/chapter02_supervised-learning/softmax-regression-gluon.html),
 the layer definition is `net = gluon.nn.Dense(num_outputs)`,
   defining the loss as `gluon.loss.SoftmaxCrossEntropyLoss()` and then 
calculating loss as
   ```python
   output = net(data)
   loss = softmax_cross_entropy(output, label)
   ```


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] frankfliu commented on issue #15520: most time cost in NDArray GetData() func

2019-07-12 Thread GitBox
frankfliu commented on issue #15520: most time cost in NDArray GetData() func
URL: 
https://github.com/apache/incubator-mxnet/issues/15520#issuecomment-510943143
 
 
   @mxnet-label-bot add [question, performance]


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] TaoLv opened a new pull request #15521: Avoid memory copy for dropout inference

2019-07-12 Thread GitBox
TaoLv opened a new pull request #15521: Avoid memory copy for dropout inference
URL: https://github.com/apache/incubator-mxnet/pull/15521
 
 
   ## Description ##
   Fix the first item in #14198. 
   
   ## Checklist ##
   ### Essentials ###
   Please feel free to remove inapplicable items for your PR.
   - [ ] The PR title starts with [MXNET-$JIRA_ID], where $JIRA_ID refers to 
the relevant [JIRA issue](https://issues.apache.org/jira/projects/MXNET/issues) 
created (except PRs with tiny changes)
   - [ ] Changes are complete (i.e. I finished coding on this PR)
   - [ ] All changes have test coverage:
   - Unit tests are added for small changes to verify correctness (e.g. adding 
a new operator)
   - Nightly tests are added for complicated/long-running ones (e.g. changing 
distributed kvstore)
   - Build tests will be added for build configuration changes (e.g. adding a 
new build option with NCCL)
   - [ ] Code is well-documented: 
   - For user-facing API changes, API doc string has been updated. 
   - For new C++ functions in header files, their functionalities and arguments 
are documented. 
   - For new examples, README.md is added to explain the what the example does, 
the source of the dataset, expected performance on test set and reference to 
the original paper if applicable
   - Check the API doc at 
http://mxnet-ci-doc.s3-accelerate.dualstack.amazonaws.com/PR-$PR_ID/$BUILD_ID/index.html
   - [ ] To the my best knowledge, examples are either not affected by this 
change, or have been fixed to be compatible with this change
   
   ### Changes ###
   - [ ] Feature1, tests, (and when applicable, API doc)
   - [ ] Feature2, tests, (and when applicable, API doc)
   
   ## Comments ##
   - If this change is a backward incompatible change, why must this change be 
made.
   - Interesting edge cases to note here
   


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] TaoLv commented on issue #15521: Avoid memory copy for dropout inference

2019-07-12 Thread GitBox
TaoLv commented on issue #15521: Avoid memory copy for dropout inference
URL: https://github.com/apache/incubator-mxnet/pull/15521#issuecomment-510944094
 
 
   @eric-haibin-lin please help to review.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] ChaiBapchya commented on issue #15506: Improving error message

2019-07-12 Thread GitBox
ChaiBapchya commented on issue #15506: Improving error message
URL: 
https://github.com/apache/incubator-mxnet/issues/15506#issuecomment-510944105
 
 
   Alright. If it is tough to safely tell the location, can't it be renamed to
   ```
   fatal error : No space left on device
   compilation terminated.
   ```
   Might sound like a nitpick and in that case I don't mind closing this issue.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] KellenSunderland commented on a change in pull request #15449: cuda/cuDNN lib version checking. Force cuDNN v7 usage.

2019-07-12 Thread GitBox
KellenSunderland commented on a change in pull request #15449: cuda/cuDNN lib 
version checking.  Force cuDNN v7 usage.
URL: https://github.com/apache/incubator-mxnet/pull/15449#discussion_r303065500
 
 

 ##
 File path: src/common/cuda_utils.cc
 ##
 @@ -0,0 +1,108 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*!
+ * Copyright (c) 2019 by Contributors
+ * \file cuda_utils.cc
+ * \brief CUDA debugging utilities.
+ */
+
+#include 
+#include "cuda_utils.h"
+
+#if MXNET_USE_CUDA == 1
+
+namespace mxnet {
+namespace common {
+namespace cuda {
+
+// The oldest version of cuda used in upstream MXNet CI testing, both for unix 
and windows.
+// Users that have rebuilt MXNet against older versions will we advised with a 
warning to upgrade
+// their systems to match the CI level.  Minimally, users should rerun the CI 
locally.
+#if defined(_MSC_VER)
+#define MXNET_CI_OLDEST_CUDA_VERSION  9020
+#else
+#define MXNET_CI_OLDEST_CUDA_VERSION 1
+#endif
+
+// Dynamic init here will emit a warning if runtime and compile-time cuda lib 
versions mismatch.
+// Also if the user has recompiled their source to a version no longer tested 
by upstream CI.
+bool cuda_version_check_performed = []() {
+  // Don't bother with checks if there are no GPUs visible (e.g. with 
CUDA_VISIBLE_DEVICES="")
+  if (dmlc::GetEnv("MXNET_CUDA_VERSION_CHECKING", true) && 
Context::GetGPUCount() > 0) {
+int linkedAgainstCudaVersion = 0;
+CUDA_CALL(cudaRuntimeGetVersion(&linkedAgainstCudaVersion));
+if (linkedAgainstCudaVersion != CUDA_VERSION)
+  LOG(WARNING) << "cuda library mismatch: linked-against version " << 
linkedAgainstCudaVersion
 
 Review comment:
   Thanks for the updates and clarification Dick.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] KellenSunderland merged pull request #15449: cuda/cuDNN lib version checking. Force cuDNN v7 usage.

2019-07-12 Thread GitBox
KellenSunderland merged pull request #15449: cuda/cuDNN lib version checking.  
Force cuDNN v7 usage.
URL: https://github.com/apache/incubator-mxnet/pull/15449
 
 
   


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:
us...@infra.apache.org


With regards,
Apache Git Services


[incubator-mxnet] branch master updated (554b196 -> 6a564be)

2019-07-12 Thread kellen
This is an automated email from the ASF dual-hosted git repository.

kellen pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-mxnet.git.


from 554b196  Rebase #13757 to master (#15189)
 add 6a564be  cuda/cuDNN lib version checking.  Force cuDNN v7 usage. 
(#15449)

No new revisions were added by this update.

Summary of changes:
 docs/faq/env_var.md  |  10 +
 include/mxnet/resource.h |   8 ++--
 src/common/cuda_utils.cc | 105 +++
 src/common/cuda_utils.h  |  27 
 src/resource.cc  |  22 +-
 5 files changed, 158 insertions(+), 14 deletions(-)
 create mode 100644 src/common/cuda_utils.cc



[incubator-mxnet] branch numpy updated: [Numpy] Numpy hstack (#15302)

2019-07-12 Thread haoj
This is an automated email from the ASF dual-hosted git repository.

haoj pushed a commit to branch numpy
in repository https://gitbox.apache.org/repos/asf/incubator-mxnet.git


The following commit(s) were added to refs/heads/numpy by this push:
 new a26b201  [Numpy] Numpy hstack (#15302)
a26b201 is described below

commit a26b2010183c5ad167c53d1c8e57d950959a3ac3
Author: Mike 
AuthorDate: Sat Jul 13 01:08:11 2019 +0800

[Numpy] Numpy hstack (#15302)

* Add numpy compatible hstack that currently pass CPU tests

Regsiter hstack in GPU

Rgister backward function to GPU

Add some comments

Fix the issues pointed out in code review

Minor syntax fix according to comments

Add docs

* Minor syntax fix
---
 python/mxnet/ndarray/numpy/_op.py  | 42 +++-
 python/mxnet/numpy/multiarray.py   | 42 +++-
 python/mxnet/symbol/numpy/_symbol.py   | 42 +++-
 src/operator/nn/concat-inl.h   | 44 
 src/operator/numpy/np_matrix_op.cc | 91 ++
 src/operator/numpy/np_matrix_op.cu |  6 +++
 tests/python/unittest/test_numpy_op.py | 65 
 7 files changed, 329 insertions(+), 3 deletions(-)

diff --git a/python/mxnet/ndarray/numpy/_op.py 
b/python/mxnet/ndarray/numpy/_op.py
index ff0e8c8..76ed88c 100644
--- a/python/mxnet/ndarray/numpy/_op.py
+++ b/python/mxnet/ndarray/numpy/_op.py
@@ -33,7 +33,7 @@ __all__ = ['zeros', 'ones', 'maximum', 'minimum', 'stack', 
'arange', 'argmax',
'clip', 'split', 'swapaxes', 'expand_dims', 'tile', 'linspace', 
'eye',
'sin', 'cos', 'sinh', 'cosh', 'log10', 'sqrt', 'abs', 'exp', 
'arctan', 'sign', 'log',
'degrees', 'log2', 'rint', 'radians', 'mean', 'reciprocal', 
'square', 'arcsin',
-   'argsort']
+   'argsort', 'hstack']
 
 
 @set_module('mxnet.ndarray.numpy')
@@ -511,6 +511,46 @@ def concatenate(seq, axis=0, out=None):
 
 
 @set_module('mxnet.ndarray.numpy')
+def hstack(arrays):
+"""
+Stack arrays in sequence horizontally (column wise).
+This is equivalent to concatenation along the second axis,
+except for 1-D arrays where it concatenates along the first axis.
+Rebuilds arrays divided by hsplit.
+This function makes most sense for arrays with up to 3 dimensions.
+For instance, for pixel-data with a height (first axis), width (second 
axis),
+and r/g/b channels (third axis). The functions concatenate,
+stack and block provide more general stacking and concatenation operations.
+
+Parameters
+--
+tup : sequence of ndarrays
+The arrays must have the same shape along all but the second axis, 
except 1-D arrays which can be any length.
+
+Returns
+---
+stacked : ndarray
+The array formed by stacking the given arrays.
+
+Examples
+
+>>> from mxnet import np,npx
+>>> a = np.array((1,2,3))
+>>> b = np.array((2,3,4))
+>>> np.hstack((a,b))
+array([1., 2., 3., 2., 3., 4.])
+
+>>> a = np.array([[1],[2],[3]])
+>>> b = np.array([[2],[3],[4]])
+>>> np.hstack((a,b))
+array([[1., 2.],
+   [2., 3.],
+   [3., 4.]])
+"""
+return _npi.hstack(*arrays)
+
+
+@set_module('mxnet.ndarray.numpy')
 def add(x1, x2, out=None):
 """Add arguments element-wise.
 
diff --git a/python/mxnet/numpy/multiarray.py b/python/mxnet/numpy/multiarray.py
index 83fcfc1..d20db96 100644
--- a/python/mxnet/numpy/multiarray.py
+++ b/python/mxnet/numpy/multiarray.py
@@ -48,7 +48,7 @@ __all__ = ['ndarray', 'empty', 'array', 'zeros', 'ones', 
'maximum', 'minimum', '
'clip', 'split', 'swapaxes', 'expand_dims', 'tile', 'linspace', 
'eye', 'sin', 'cos',
'sin', 'cos', 'sinh', 'cosh', 'log10', 'sqrt', 'abs', 'exp', 
'arctan', 'sign', 'log',
'degrees', 'log2', 'rint', 'radians', 'mean', 'reciprocal', 
'square', 'arcsin',
-   'argsort']
+   'argsort', 'hstack']
 
 
 # This function is copied from ndarray.py since pylint
@@ -1566,6 +1566,46 @@ def stack(arrays, axis=0, out=None):
 
 
 @set_module('mxnet.numpy')
+def hstack(arrays):
+"""
+Stack arrays in sequence horizontally (column wise).
+This is equivalent to concatenation along the second axis,
+except for 1-D arrays where it concatenates along the first axis.
+Rebuilds arrays divided by hsplit.
+This function makes most sense for arrays with up to 3 dimensions.
+For instance, for pixel-data with a height (first axis), width (second 
axis),
+and r/g/b channels (third axis). The functions concatenate,
+stack and block provide more general stacking and concatenation operations.
+
+Parameters
+--
+tup : sequence of ndarrays
+The arrays must have the same shape along all but the second axis, 
except 1-D arrays which can be any length.
+
+Returns
+---
+stacked : ndarray

[GitHub] [incubator-mxnet] haojin2 merged pull request #15302: [Numpy] Numpy hstack

2019-07-12 Thread GitBox
haojin2 merged pull request #15302: [Numpy] Numpy hstack
URL: https://github.com/apache/incubator-mxnet/pull/15302
 
 
   


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] Zha0q1 commented on a change in pull request #15490: Utility to help developers debug operators: Tensor Inspector

2019-07-12 Thread GitBox
Zha0q1 commented on a change in pull request #15490: Utility to help developers 
debug operators: Tensor Inspector
URL: https://github.com/apache/incubator-mxnet/pull/15490#discussion_r303073483
 
 

 ##
 File path: src/common/tensor_inspector.h
 ##
 @@ -0,0 +1,733 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*!
+ * Copyright (c) 2019 by Contributors
+ * \file tensor_inspector.h
+ * \brief utility to inspect tensor objects
+ * \author Zhaoqi Zhu
+ */
+
+#ifndef MXNET_COMMON_TENSOR_INSPECTOR_H_
+#define MXNET_COMMON_TENSOR_INSPECTOR_H_
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "../../3rdparty/mshadow/mshadow/base.h"
+#include "../../tests/cpp/include/test_util.h"
+
+namespace mxnet {
+
+/*!
+ * \brief this singleton struct mediates individual TensorInspector objects
+ * so that we can control the global behavior from each of them
+ */
+struct InspectorManager {
+  static InspectorManager* get() {
+static std::mutex mtx;
+static std::unique_ptr im = nullptr;
+if (!im) {
+  std::unique_lock lk(mtx);
+  if (!im)
+im = std::make_unique();
+}
+return im.get();
+  }
+  /* !\brief mutex used to lock interactive_print() and check_value() */
+  std::mutex mutex_;
+  /* !\brief skip all interactive prints */
+  bool interactive_print_skip_all_ = false;
+  /* !\brief skip all value checks */
+  bool check_value_skip_all_ = false;
+  /* !\brief visit count for interactive print tags */
+  std::unordered_map interactive_print_tag_counter_;
+  /* !\brief visit count for check value tags */
+  std::unordered_map check_value_tag_counter_;
+  /* !\brief visit count for dump value tags */
+  std::unordered_map dump_value_tag_counter_;
+};
+
+/*!
+ * \brief Enum for building value checkers for TensorInspector::check_value()
+ */
+enum CheckerType {
+  NegativeChecker,  // check if is negative
+  PositiveChecker,  // check if is positive
+  ZeroChecker,  // check if is zero
+  NaNChecker,  // check if is NaN, will always return false if DType is not a 
float type
+  InfChecker,  // check if is infinity, will always return false if DType is 
not a float type
+  PositiveInfChecker,  // check if is positive infinity,
+   // will always return false if DType is not a float type
+  NegativeInfChecker,  // check if is nagative infinity,
+   // will always return false if DType is not a float type
+  FiniteChecker,  // check if is finite, will always return false if DType is 
not a float type
+  NormalChecker,  // check if is neither infinity nor NaN
+  AbnormalChecker,  // chekck if is infinity or nan
+};
+
+/**
+ *  ___  _   _ 
+ * |__   __||_   _| | |
+ *| | ___ _ __  ___  ___  _ __| |  _ __  ___ _ __   ___  ___| |_ ___  _ __ 
+ *| |/ _ \ '_ \/ __|/ _ \| '__| | | '_ \/ __| '_ \ / _ \/ __| __/ _ \| '__|
+ *| |  __/ | | \__ \ (_) | | _| |_| | | \__ \ |_) |  __/ (__| || (_) | |   
+ *|_|\___|_| |_|___/\___/|_||_|_| |_|___/ .__/ \___|\___|\__\___/|_|   
+ *  | |
+ *  |_|   
+ */
+
+/*!
+ * \brief This class provides a unified interface to inspect the value of all 
data types
+ * including Tensor, TBlob, and NDArray. If the tensor resides on GPU, then it 
will be
+ * copied from GPU memory back to CPU memory to be operated on. Internally, 
all data types
+ * are stored as a TBlob object tb_.
+ */
+class TensorInspector {
+ private:
+  /*!
+   * \brief generate the tensor info, including data type and shape 
+   * \tparam DType the data type
+   * \tparam StreamType the type of the stream object
+   * \param os stream object to output to
+   */
+  template
+  inline void tensor_info_to_string(StreamType* os) {
+int dimension = tb_.ndim();
+*os << "<" << typeid(tb_.dptr()[0]).name() << " Tensor ";
+*os << tb_.shape_[0];
+for (int i = 1; i < dimension; i++) {
 
 Review comment:
   I remember compiler will optimize this to ++i? Anyways, I will make the 
change myself

-

[GitHub] [incubator-mxnet] Zha0q1 commented on a change in pull request #15490: Utility to help developers debug operators: Tensor Inspector

2019-07-12 Thread GitBox
Zha0q1 commented on a change in pull request #15490: Utility to help developers 
debug operators: Tensor Inspector
URL: https://github.com/apache/incubator-mxnet/pull/15490#discussion_r303081013
 
 

 ##
 File path: src/common/tensor_inspector.h
 ##
 @@ -0,0 +1,733 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*!
+ * Copyright (c) 2019 by Contributors
+ * \file tensor_inspector.h
+ * \brief utility to inspect tensor objects
+ * \author Zhaoqi Zhu
+ */
+
+#ifndef MXNET_COMMON_TENSOR_INSPECTOR_H_
+#define MXNET_COMMON_TENSOR_INSPECTOR_H_
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "../../3rdparty/mshadow/mshadow/base.h"
+#include "../../tests/cpp/include/test_util.h"
+
+namespace mxnet {
+
+/*!
+ * \brief this singleton struct mediates individual TensorInspector objects
+ * so that we can control the global behavior from each of them
+ */
+struct InspectorManager {
+  static InspectorManager* get() {
+static std::mutex mtx;
+static std::unique_ptr im = nullptr;
+if (!im) {
+  std::unique_lock lk(mtx);
+  if (!im)
+im = std::make_unique();
+}
+return im.get();
+  }
+  /* !\brief mutex used to lock interactive_print() and check_value() */
+  std::mutex mutex_;
+  /* !\brief skip all interactive prints */
+  bool interactive_print_skip_all_ = false;
+  /* !\brief skip all value checks */
+  bool check_value_skip_all_ = false;
+  /* !\brief visit count for interactive print tags */
+  std::unordered_map interactive_print_tag_counter_;
+  /* !\brief visit count for check value tags */
+  std::unordered_map check_value_tag_counter_;
+  /* !\brief visit count for dump value tags */
+  std::unordered_map dump_value_tag_counter_;
+};
+
+/*!
+ * \brief Enum for building value checkers for TensorInspector::check_value()
+ */
+enum CheckerType {
+  NegativeChecker,  // check if is negative
+  PositiveChecker,  // check if is positive
+  ZeroChecker,  // check if is zero
+  NaNChecker,  // check if is NaN, will always return false if DType is not a 
float type
+  InfChecker,  // check if is infinity, will always return false if DType is 
not a float type
+  PositiveInfChecker,  // check if is positive infinity,
+   // will always return false if DType is not a float type
+  NegativeInfChecker,  // check if is nagative infinity,
+   // will always return false if DType is not a float type
+  FiniteChecker,  // check if is finite, will always return false if DType is 
not a float type
+  NormalChecker,  // check if is neither infinity nor NaN
+  AbnormalChecker,  // chekck if is infinity or nan
+};
+
+/**
+ *  ___  _   _ 
+ * |__   __||_   _| | |
+ *| | ___ _ __  ___  ___  _ __| |  _ __  ___ _ __   ___  ___| |_ ___  _ __ 
+ *| |/ _ \ '_ \/ __|/ _ \| '__| | | '_ \/ __| '_ \ / _ \/ __| __/ _ \| '__|
+ *| |  __/ | | \__ \ (_) | | _| |_| | | \__ \ |_) |  __/ (__| || (_) | |   
+ *|_|\___|_| |_|___/\___/|_||_|_| |_|___/ .__/ \___|\___|\__\___/|_|   
+ *  | |
+ *  |_|   
+ */
+
+/*!
+ * \brief This class provides a unified interface to inspect the value of all 
data types
+ * including Tensor, TBlob, and NDArray. If the tensor resides on GPU, then it 
will be
+ * copied from GPU memory back to CPU memory to be operated on. Internally, 
all data types
+ * are stored as a TBlob object tb_.
+ */
+class TensorInspector {
+ private:
+  /*!
+   * \brief generate the tensor info, including data type and shape 
+   * \tparam DType the data type
+   * \tparam StreamType the type of the stream object
+   * \param os stream object to output to
+   */
+  template
+  inline void tensor_info_to_string(StreamType* os) {
+int dimension = tb_.ndim();
+*os << "<" << typeid(tb_.dptr()[0]).name() << " Tensor ";
+*os << tb_.shape_[0];
+for (int i = 1; i < dimension; i++) {
+  *os << 'x' << tb_.shape_[i];
+}
+*os << ">" << std::endl;
+  }
+
+  /*!
+   * \brief output the tensor info, inc

[GitHub] [incubator-mxnet] Zha0q1 commented on a change in pull request #15490: Utility to help developers debug operators: Tensor Inspector

2019-07-12 Thread GitBox
Zha0q1 commented on a change in pull request #15490: Utility to help developers 
debug operators: Tensor Inspector
URL: https://github.com/apache/incubator-mxnet/pull/15490#discussion_r303081013
 
 

 ##
 File path: src/common/tensor_inspector.h
 ##
 @@ -0,0 +1,733 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*!
+ * Copyright (c) 2019 by Contributors
+ * \file tensor_inspector.h
+ * \brief utility to inspect tensor objects
+ * \author Zhaoqi Zhu
+ */
+
+#ifndef MXNET_COMMON_TENSOR_INSPECTOR_H_
+#define MXNET_COMMON_TENSOR_INSPECTOR_H_
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "../../3rdparty/mshadow/mshadow/base.h"
+#include "../../tests/cpp/include/test_util.h"
+
+namespace mxnet {
+
+/*!
+ * \brief this singleton struct mediates individual TensorInspector objects
+ * so that we can control the global behavior from each of them
+ */
+struct InspectorManager {
+  static InspectorManager* get() {
+static std::mutex mtx;
+static std::unique_ptr im = nullptr;
+if (!im) {
+  std::unique_lock lk(mtx);
+  if (!im)
+im = std::make_unique();
+}
+return im.get();
+  }
+  /* !\brief mutex used to lock interactive_print() and check_value() */
+  std::mutex mutex_;
+  /* !\brief skip all interactive prints */
+  bool interactive_print_skip_all_ = false;
+  /* !\brief skip all value checks */
+  bool check_value_skip_all_ = false;
+  /* !\brief visit count for interactive print tags */
+  std::unordered_map interactive_print_tag_counter_;
+  /* !\brief visit count for check value tags */
+  std::unordered_map check_value_tag_counter_;
+  /* !\brief visit count for dump value tags */
+  std::unordered_map dump_value_tag_counter_;
+};
+
+/*!
+ * \brief Enum for building value checkers for TensorInspector::check_value()
+ */
+enum CheckerType {
+  NegativeChecker,  // check if is negative
+  PositiveChecker,  // check if is positive
+  ZeroChecker,  // check if is zero
+  NaNChecker,  // check if is NaN, will always return false if DType is not a 
float type
+  InfChecker,  // check if is infinity, will always return false if DType is 
not a float type
+  PositiveInfChecker,  // check if is positive infinity,
+   // will always return false if DType is not a float type
+  NegativeInfChecker,  // check if is nagative infinity,
+   // will always return false if DType is not a float type
+  FiniteChecker,  // check if is finite, will always return false if DType is 
not a float type
+  NormalChecker,  // check if is neither infinity nor NaN
+  AbnormalChecker,  // chekck if is infinity or nan
+};
+
+/**
+ *  ___  _   _ 
+ * |__   __||_   _| | |
+ *| | ___ _ __  ___  ___  _ __| |  _ __  ___ _ __   ___  ___| |_ ___  _ __ 
+ *| |/ _ \ '_ \/ __|/ _ \| '__| | | '_ \/ __| '_ \ / _ \/ __| __/ _ \| '__|
+ *| |  __/ | | \__ \ (_) | | _| |_| | | \__ \ |_) |  __/ (__| || (_) | |   
+ *|_|\___|_| |_|___/\___/|_||_|_| |_|___/ .__/ \___|\___|\__\___/|_|   
+ *  | |
+ *  |_|   
+ */
+
+/*!
+ * \brief This class provides a unified interface to inspect the value of all 
data types
+ * including Tensor, TBlob, and NDArray. If the tensor resides on GPU, then it 
will be
+ * copied from GPU memory back to CPU memory to be operated on. Internally, 
all data types
+ * are stored as a TBlob object tb_.
+ */
+class TensorInspector {
+ private:
+  /*!
+   * \brief generate the tensor info, including data type and shape 
+   * \tparam DType the data type
+   * \tparam StreamType the type of the stream object
+   * \param os stream object to output to
+   */
+  template
+  inline void tensor_info_to_string(StreamType* os) {
+int dimension = tb_.ndim();
+*os << "<" << typeid(tb_.dptr()[0]).name() << " Tensor ";
+*os << tb_.shape_[0];
+for (int i = 1; i < dimension; i++) {
+  *os << 'x' << tb_.shape_[i];
+}
+*os << ">" << std::endl;
+  }
+
+  /*!
+   * \brief output the tensor info, inc

[GitHub] [incubator-mxnet] Zha0q1 commented on a change in pull request #15490: Utility to help developers debug operators: Tensor Inspector

2019-07-12 Thread GitBox
Zha0q1 commented on a change in pull request #15490: Utility to help developers 
debug operators: Tensor Inspector
URL: https://github.com/apache/incubator-mxnet/pull/15490#discussion_r303082695
 
 

 ##
 File path: src/common/tensor_inspector.h
 ##
 @@ -0,0 +1,733 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*!
+ * Copyright (c) 2019 by Contributors
+ * \file tensor_inspector.h
+ * \brief utility to inspect tensor objects
+ * \author Zhaoqi Zhu
+ */
+
+#ifndef MXNET_COMMON_TENSOR_INSPECTOR_H_
+#define MXNET_COMMON_TENSOR_INSPECTOR_H_
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "../../3rdparty/mshadow/mshadow/base.h"
+#include "../../tests/cpp/include/test_util.h"
+
+namespace mxnet {
+
+/*!
+ * \brief this singleton struct mediates individual TensorInspector objects
+ * so that we can control the global behavior from each of them
+ */
+struct InspectorManager {
+  static InspectorManager* get() {
+static std::mutex mtx;
+static std::unique_ptr im = nullptr;
+if (!im) {
+  std::unique_lock lk(mtx);
+  if (!im)
+im = std::make_unique();
+}
+return im.get();
+  }
+  /* !\brief mutex used to lock interactive_print() and check_value() */
+  std::mutex mutex_;
+  /* !\brief skip all interactive prints */
+  bool interactive_print_skip_all_ = false;
+  /* !\brief skip all value checks */
+  bool check_value_skip_all_ = false;
+  /* !\brief visit count for interactive print tags */
+  std::unordered_map interactive_print_tag_counter_;
+  /* !\brief visit count for check value tags */
+  std::unordered_map check_value_tag_counter_;
+  /* !\brief visit count for dump value tags */
+  std::unordered_map dump_value_tag_counter_;
+};
+
+/*!
+ * \brief Enum for building value checkers for TensorInspector::check_value()
+ */
+enum CheckerType {
+  NegativeChecker,  // check if is negative
+  PositiveChecker,  // check if is positive
+  ZeroChecker,  // check if is zero
+  NaNChecker,  // check if is NaN, will always return false if DType is not a 
float type
+  InfChecker,  // check if is infinity, will always return false if DType is 
not a float type
+  PositiveInfChecker,  // check if is positive infinity,
+   // will always return false if DType is not a float type
+  NegativeInfChecker,  // check if is nagative infinity,
+   // will always return false if DType is not a float type
+  FiniteChecker,  // check if is finite, will always return false if DType is 
not a float type
+  NormalChecker,  // check if is neither infinity nor NaN
+  AbnormalChecker,  // chekck if is infinity or nan
+};
+
+/**
+ *  ___  _   _ 
+ * |__   __||_   _| | |
+ *| | ___ _ __  ___  ___  _ __| |  _ __  ___ _ __   ___  ___| |_ ___  _ __ 
+ *| |/ _ \ '_ \/ __|/ _ \| '__| | | '_ \/ __| '_ \ / _ \/ __| __/ _ \| '__|
+ *| |  __/ | | \__ \ (_) | | _| |_| | | \__ \ |_) |  __/ (__| || (_) | |   
+ *|_|\___|_| |_|___/\___/|_||_|_| |_|___/ .__/ \___|\___|\__\___/|_|   
+ *  | |
+ *  |_|   
+ */
+
+/*!
+ * \brief This class provides a unified interface to inspect the value of all 
data types
+ * including Tensor, TBlob, and NDArray. If the tensor resides on GPU, then it 
will be
+ * copied from GPU memory back to CPU memory to be operated on. Internally, 
all data types
+ * are stored as a TBlob object tb_.
+ */
+class TensorInspector {
+ private:
+  /*!
+   * \brief generate the tensor info, including data type and shape 
+   * \tparam DType the data type
+   * \tparam StreamType the type of the stream object
+   * \param os stream object to output to
+   */
+  template
+  inline void tensor_info_to_string(StreamType* os) {
+int dimension = tb_.ndim();
+*os << "<" << typeid(tb_.dptr()[0]).name() << " Tensor ";
+*os << tb_.shape_[0];
+for (int i = 1; i < dimension; i++) {
+  *os << 'x' << tb_.shape_[i];
+}
+*os << ">" << std::endl;
+  }
+
+  /*!
+   * \brief output the tensor info, inc

[GitHub] [incubator-mxnet] Zha0q1 commented on a change in pull request #15490: Utility to help developers debug operators: Tensor Inspector

2019-07-12 Thread GitBox
Zha0q1 commented on a change in pull request #15490: Utility to help developers 
debug operators: Tensor Inspector
URL: https://github.com/apache/incubator-mxnet/pull/15490#discussion_r303082645
 
 

 ##
 File path: src/common/tensor_inspector.h
 ##
 @@ -0,0 +1,733 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*!
+ * Copyright (c) 2019 by Contributors
+ * \file tensor_inspector.h
+ * \brief utility to inspect tensor objects
+ * \author Zhaoqi Zhu
+ */
+
+#ifndef MXNET_COMMON_TENSOR_INSPECTOR_H_
+#define MXNET_COMMON_TENSOR_INSPECTOR_H_
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "../../3rdparty/mshadow/mshadow/base.h"
+#include "../../tests/cpp/include/test_util.h"
+
+namespace mxnet {
+
+/*!
+ * \brief this singleton struct mediates individual TensorInspector objects
+ * so that we can control the global behavior from each of them
+ */
+struct InspectorManager {
+  static InspectorManager* get() {
+static std::mutex mtx;
+static std::unique_ptr im = nullptr;
+if (!im) {
+  std::unique_lock lk(mtx);
+  if (!im)
+im = std::make_unique();
+}
+return im.get();
+  }
+  /* !\brief mutex used to lock interactive_print() and check_value() */
+  std::mutex mutex_;
+  /* !\brief skip all interactive prints */
+  bool interactive_print_skip_all_ = false;
+  /* !\brief skip all value checks */
+  bool check_value_skip_all_ = false;
+  /* !\brief visit count for interactive print tags */
+  std::unordered_map interactive_print_tag_counter_;
+  /* !\brief visit count for check value tags */
+  std::unordered_map check_value_tag_counter_;
+  /* !\brief visit count for dump value tags */
+  std::unordered_map dump_value_tag_counter_;
+};
+
+/*!
+ * \brief Enum for building value checkers for TensorInspector::check_value()
+ */
+enum CheckerType {
+  NegativeChecker,  // check if is negative
+  PositiveChecker,  // check if is positive
+  ZeroChecker,  // check if is zero
+  NaNChecker,  // check if is NaN, will always return false if DType is not a 
float type
+  InfChecker,  // check if is infinity, will always return false if DType is 
not a float type
+  PositiveInfChecker,  // check if is positive infinity,
+   // will always return false if DType is not a float type
+  NegativeInfChecker,  // check if is nagative infinity,
+   // will always return false if DType is not a float type
+  FiniteChecker,  // check if is finite, will always return false if DType is 
not a float type
+  NormalChecker,  // check if is neither infinity nor NaN
+  AbnormalChecker,  // chekck if is infinity or nan
+};
+
+/**
+ *  ___  _   _ 
+ * |__   __||_   _| | |
+ *| | ___ _ __  ___  ___  _ __| |  _ __  ___ _ __   ___  ___| |_ ___  _ __ 
+ *| |/ _ \ '_ \/ __|/ _ \| '__| | | '_ \/ __| '_ \ / _ \/ __| __/ _ \| '__|
+ *| |  __/ | | \__ \ (_) | | _| |_| | | \__ \ |_) |  __/ (__| || (_) | |   
+ *|_|\___|_| |_|___/\___/|_||_|_| |_|___/ .__/ \___|\___|\__\___/|_|   
+ *  | |
+ *  |_|   
+ */
+
+/*!
+ * \brief This class provides a unified interface to inspect the value of all 
data types
+ * including Tensor, TBlob, and NDArray. If the tensor resides on GPU, then it 
will be
+ * copied from GPU memory back to CPU memory to be operated on. Internally, 
all data types
+ * are stored as a TBlob object tb_.
+ */
+class TensorInspector {
+ private:
+  /*!
+   * \brief generate the tensor info, including data type and shape 
+   * \tparam DType the data type
+   * \tparam StreamType the type of the stream object
+   * \param os stream object to output to
+   */
+  template
+  inline void tensor_info_to_string(StreamType* os) {
+int dimension = tb_.ndim();
+*os << "<" << typeid(tb_.dptr()[0]).name() << " Tensor ";
+*os << tb_.shape_[0];
+for (int i = 1; i < dimension; i++) {
 
 Review comment:
   fixed


This is an automated message from

[GitHub] [incubator-mxnet] ChaiBapchya opened a new pull request #15522: Add optimizer update operator benchmarks to opperf

2019-07-12 Thread GitBox
ChaiBapchya opened a new pull request #15522: Add  optimizer update operator 
benchmarks to opperf
URL: https://github.com/apache/incubator-mxnet/pull/15522
 
 
   ## Description ##
   Added neural network optimizer (Adam, sgd, etc) update operators to the 
existing set of opperf benchmarks
   
   ## Checklist ##
   ### Essentials ###
   Please feel free to remove inapplicable items for your PR.
   - [X] Changes are complete (i.e. I finished coding on this PR)
   - [X] All changes have test coverage:
   - [X] Code is well-documented: 
   - [X] To the my best knowledge, examples are either not affected by this 
change, or have been fixed to be compatible with this change
   
   ### Changes ###
   - [ ] Added optimizer update ops to opperf
   
   @sandeep-krishnamurthy @apeforest 


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] aaronmarkham opened a new pull request #15523: add julia env settings

2019-07-12 Thread GitBox
aaronmarkham opened a new pull request #15523: add julia env settings
URL: https://github.com/apache/incubator-mxnet/pull/15523
 
 
   ## Description ##
   I missed this env var requirement in the Julia docs PR, #15454. 
   
   ## Comment
   We should probably add some CI test for the website publish routine so this 
kind of thing doesn't get overlooked until after a merge.
   


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] marcoabreu commented on issue #15426: Add -R option to ci/build.py to avoid rebuilding containers

2019-07-12 Thread GitBox
marcoabreu commented on issue #15426: Add -R option to ci/build.py to avoid 
rebuilding containers
URL: https://github.com/apache/incubator-mxnet/pull/15426#issuecomment-510979685
 
 
   Ye it's probably user id - for whatever reason docker cares about that...


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] marcoabreu merged pull request #15426: Add -R option to ci/build.py to avoid rebuilding containers

2019-07-12 Thread GitBox
marcoabreu merged pull request #15426: Add -R option to ci/build.py to avoid 
rebuilding containers
URL: https://github.com/apache/incubator-mxnet/pull/15426
 
 
   


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:
us...@infra.apache.org


With regards,
Apache Git Services


[incubator-mxnet] branch master updated (6a564be -> 9ff6c46)

2019-07-12 Thread marcoabreu
This is an automated email from the ASF dual-hosted git repository.

marcoabreu pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-mxnet.git.


from 6a564be  cuda/cuDNN lib version checking.  Force cuDNN v7 usage. 
(#15449)
 add 9ff6c46  Add -R option to ci/build.py to avoid rebuilding containers 
(#15426)

No new revisions were added by this update.

Summary of changes:
 ci/build.py | 10 +-
 1 file changed, 9 insertions(+), 1 deletion(-)



[GitHub] [incubator-mxnet] aaronmarkham opened a new pull request #15524: refine Nano setup directions

2019-07-12 Thread GitBox
aaronmarkham opened a new pull request #15524: refine Nano setup directions
URL: https://github.com/apache/incubator-mxnet/pull/15524
 
 
   ## Description ##
   After another run-through on a fresh Nano, plus trying out these new pip 
wheels, we found some refinements that should make the setup go a little more 
cleanly.
   


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] haojin2 commented on a change in pull request #15349: Numpy Tensordot Operator

2019-07-12 Thread GitBox
haojin2 commented on a change in pull request #15349: Numpy Tensordot Operator 
URL: https://github.com/apache/incubator-mxnet/pull/15349#discussion_r303094358
 
 

 ##
 File path: tests/python/unittest/test_numpy_op.py
 ##
 @@ -26,6 +26,151 @@
 from mxnet.test_utils import check_numeric_gradient
 from common import assertRaises, with_seed
 import random
+import collections
+
 
 Review comment:
   one more blank line.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] haojin2 commented on a change in pull request #15349: Numpy Tensordot Operator

2019-07-12 Thread GitBox
haojin2 commented on a change in pull request #15349: Numpy Tensordot Operator 
URL: https://github.com/apache/incubator-mxnet/pull/15349#discussion_r303094273
 
 

 ##
 File path: src/operator/numpy/np_tensordot_op.cc
 ##
 @@ -0,0 +1,222 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*!
+ * \file np_tensordot_op.cc
+ * \brief CPU Implementation of numpy-compatible tensordot
+ */
+
+#include 
+#include "np_tensordot_op-inl.h"
+
+namespace mxnet {
+namespace op {
+
+bool TensordotOpShape(const nnvm::NodeAttrs& attrs,
+  mxnet::ShapeVector *in_attrs,
+  mxnet::ShapeVector *out_attrs) {
+  CHECK_EQ(in_attrs->size(), 2U);
+  CHECK_EQ(out_attrs->size(), 1U);
+
+  const mxnet::TShape& a_shape = in_attrs->at(0);
+  const mxnet::TShape& b_shape = in_attrs->at(1);
+
+  if (!ndim_is_known(a_shape) || !ndim_is_known(b_shape)) {
+return false;
+  }
+
+  if ((a_shape.ndim() < 1) || (b_shape.ndim() < 1)) {
+return false;
+  }
+
+  const TensordotParam& param = nnvm::get(attrs.parsed);
+  const Tuple& a_axes_summed = param.a_axes_summed;
+  const Tuple& b_axes_summed = param.b_axes_summed;
+
+  Tuple a_axes_remained;
+  Tuple b_axes_remained;
+  Tuple a_axes;
+  Tuple b_axes;
+  GetReorderedAxes(a_axes_summed, &a_axes_remained, &a_axes, b_axes_summed, 
&b_axes_remained,
+   &b_axes, a_shape, b_shape);
+
+  CHECK_EQ(a_axes_summed.ndim(), b_axes_summed.ndim());
+
+  mxnet::TShape out_shape(a_axes_remained.ndim() + b_axes_remained.ndim(), -1);
+  for (int i = 0; i < a_axes_remained.ndim(); i++) {
+out_shape[i] = a_shape[a_axes_remained[i]];
+  }
+  for (int i = 0; i < b_axes_remained.ndim(); i++) {
+out_shape[a_axes_remained.ndim() + i] = b_shape[b_axes_remained[i]];
+  }
+  SHAPE_ASSIGN_CHECK(*out_attrs, 0, out_shape);
+
+  mxnet::TShape tem_shape1(a_axes.ndim(), -1);
+  for (int i = 0; i < a_axes_remained.ndim(); i++) {
+tem_shape1[a_axes_remained[i]] = out_shape[i];
+  }
+  for (int i = 0; i < a_axes_summed.ndim(); i++) {
+tem_shape1[a_axes_summed[i]] = b_shape[b_axes_summed[i]];
+  }
+  SHAPE_ASSIGN_CHECK(*in_attrs, 0, tem_shape1);
+
+  mxnet::TShape tem_shape2(b_axes.ndim(), -1);
+  for (int i = 0; i < b_axes_remained.ndim(); i++) {
+tem_shape2[b_axes_remained[i]] = out_shape[a_axes_remained.ndim() + i];
+  }
+  for (int i = 0; i < b_axes_summed.ndim(); i++) {
+tem_shape2[b_axes_summed[i]] = a_shape[a_axes_summed[i]];
+  }
+  SHAPE_ASSIGN_CHECK(*in_attrs, 1, tem_shape2);
+
+  return shape_is_known(*in_attrs) && shape_is_known(*out_attrs);
+}
+
+DMLC_REGISTER_PARAMETER(TensordotParam);
+
+NNVM_REGISTER_OP(_npi_tensordot)
+.set_attr_parser(mxnet::op::ParamParser)
+.set_num_inputs(2)
+.set_num_outputs(1)
+.set_attr("FListInputNames",
+  [](const NodeAttrs& attrs) {
+return std::vector{"a", "b"};
+  })
+.set_attr("FInferShape", TensordotOpShape)
+.set_attr("FInferType", mxnet::op::ElemwiseType<2, 1>)
+.set_attr("FResourceRequest",
+  [](const NodeAttrs& attrs) {
+return std::vector{ResourceRequest::kTempSpace};
+  })
+.set_attr("FCompute", TensordotOpForward)
+.set_attr("FGradient", 
mxnet::op::ElemwiseGradUseIn{"_backward_npi_tensordot"})
+.add_argument("a", "NDArray-or-Symbol", "First input")
+.add_argument("b", "NDArray-or-Symbol", "Second input")
+.add_arguments(TensordotParam::__FIELDS__());
+
+NNVM_REGISTER_OP(_backward_npi_tensordot)
+.set_attr_parser(mxnet::op::ParamParser)
+.set_num_inputs(3)
+.set_num_outputs(2)
+.set_attr("TIsBackward", true)
+.set_attr("FResourceRequest",
+  [](const NodeAttrs& attrs) {
+return std::vector{ResourceRequest::kTempSpace};
+  })
+.set_attr("FCompute", TensordotOpBackward);
+
+bool TensordotIntAxesOpShape(const nnvm::NodeAttrs& attrs,
+ mxnet::ShapeVector *in_attrs,
+ mxnet::ShapeVector *out_attrs) {
+  CHECK_EQ(in_attrs->size(), 2U);
+  CHECK_EQ(out_attrs->size(), 1U);
+
+  const mxnet::TShape& a_shape = in_attrs->at(0);
+  const mxnet::TShape& b_shape = in_attrs->at(1);
+
+  if (!ndim_is_known(a_shape) || !ndim_is_known(b_shape)) {
+return false;
+  }
+
+  if ((a_shape.ndim() < 1) || (b_shape.ndim() < 1)) {
+return false;
+  }
+
+  c

[GitHub] [incubator-mxnet] sandeep-krishnamurthy opened a new issue #15525: Nightly tests / integration tests in PRs are not tested before merging

2019-07-12 Thread GitBox
sandeep-krishnamurthy opened a new issue #15525: Nightly tests / integration 
tests in PRs are not tested before merging
URL: https://github.com/apache/incubator-mxnet/issues/15525
 
 
   We do not test nightly/integration tests added in a PR at PR CI stage. This 
leads to a PR with failing integration test to get merged and all our nightly 
CI jobs starts failing.
   
   We need to make sure everything in the PR is tested before merge. For this 
particular problem, one suggested solution could be - If there are nightly 
tests in the PR, it needs to be executed as part of PR validation.
   
   Suggestions? 
   @roywei @marcoabreu @lanking520 


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] mxnet-label-bot commented on issue #15525: Nightly tests / integration tests in PRs are not tested before merging

2019-07-12 Thread GitBox
mxnet-label-bot commented on issue #15525: Nightly tests / integration tests in 
PRs are not tested before merging
URL: 
https://github.com/apache/incubator-mxnet/issues/15525#issuecomment-510983068
 
 
   Hey, this is the MXNet Label Bot. 
Thank you for submitting the issue! I will try and suggest some labels so 
that the appropriate MXNet community members can help resolve it. 
Here are my recommended labels: Test


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] Zha0q1 commented on a change in pull request #15490: Utility to help developers debug operators: Tensor Inspector

2019-07-12 Thread GitBox
Zha0q1 commented on a change in pull request #15490: Utility to help developers 
debug operators: Tensor Inspector
URL: https://github.com/apache/incubator-mxnet/pull/15490#discussion_r303081013
 
 

 ##
 File path: src/common/tensor_inspector.h
 ##
 @@ -0,0 +1,733 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*!
+ * Copyright (c) 2019 by Contributors
+ * \file tensor_inspector.h
+ * \brief utility to inspect tensor objects
+ * \author Zhaoqi Zhu
+ */
+
+#ifndef MXNET_COMMON_TENSOR_INSPECTOR_H_
+#define MXNET_COMMON_TENSOR_INSPECTOR_H_
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "../../3rdparty/mshadow/mshadow/base.h"
+#include "../../tests/cpp/include/test_util.h"
+
+namespace mxnet {
+
+/*!
+ * \brief this singleton struct mediates individual TensorInspector objects
+ * so that we can control the global behavior from each of them
+ */
+struct InspectorManager {
+  static InspectorManager* get() {
+static std::mutex mtx;
+static std::unique_ptr im = nullptr;
+if (!im) {
+  std::unique_lock lk(mtx);
+  if (!im)
+im = std::make_unique();
+}
+return im.get();
+  }
+  /* !\brief mutex used to lock interactive_print() and check_value() */
+  std::mutex mutex_;
+  /* !\brief skip all interactive prints */
+  bool interactive_print_skip_all_ = false;
+  /* !\brief skip all value checks */
+  bool check_value_skip_all_ = false;
+  /* !\brief visit count for interactive print tags */
+  std::unordered_map interactive_print_tag_counter_;
+  /* !\brief visit count for check value tags */
+  std::unordered_map check_value_tag_counter_;
+  /* !\brief visit count for dump value tags */
+  std::unordered_map dump_value_tag_counter_;
+};
+
+/*!
+ * \brief Enum for building value checkers for TensorInspector::check_value()
+ */
+enum CheckerType {
+  NegativeChecker,  // check if is negative
+  PositiveChecker,  // check if is positive
+  ZeroChecker,  // check if is zero
+  NaNChecker,  // check if is NaN, will always return false if DType is not a 
float type
+  InfChecker,  // check if is infinity, will always return false if DType is 
not a float type
+  PositiveInfChecker,  // check if is positive infinity,
+   // will always return false if DType is not a float type
+  NegativeInfChecker,  // check if is nagative infinity,
+   // will always return false if DType is not a float type
+  FiniteChecker,  // check if is finite, will always return false if DType is 
not a float type
+  NormalChecker,  // check if is neither infinity nor NaN
+  AbnormalChecker,  // chekck if is infinity or nan
+};
+
+/**
+ *  ___  _   _ 
+ * |__   __||_   _| | |
+ *| | ___ _ __  ___  ___  _ __| |  _ __  ___ _ __   ___  ___| |_ ___  _ __ 
+ *| |/ _ \ '_ \/ __|/ _ \| '__| | | '_ \/ __| '_ \ / _ \/ __| __/ _ \| '__|
+ *| |  __/ | | \__ \ (_) | | _| |_| | | \__ \ |_) |  __/ (__| || (_) | |   
+ *|_|\___|_| |_|___/\___/|_||_|_| |_|___/ .__/ \___|\___|\__\___/|_|   
+ *  | |
+ *  |_|   
+ */
+
+/*!
+ * \brief This class provides a unified interface to inspect the value of all 
data types
+ * including Tensor, TBlob, and NDArray. If the tensor resides on GPU, then it 
will be
+ * copied from GPU memory back to CPU memory to be operated on. Internally, 
all data types
+ * are stored as a TBlob object tb_.
+ */
+class TensorInspector {
+ private:
+  /*!
+   * \brief generate the tensor info, including data type and shape 
+   * \tparam DType the data type
+   * \tparam StreamType the type of the stream object
+   * \param os stream object to output to
+   */
+  template
+  inline void tensor_info_to_string(StreamType* os) {
+int dimension = tb_.ndim();
+*os << "<" << typeid(tb_.dptr()[0]).name() << " Tensor ";
+*os << tb_.shape_[0];
+for (int i = 1; i < dimension; i++) {
+  *os << 'x' << tb_.shape_[i];
+}
+*os << ">" << std::endl;
+  }
+
+  /*!
+   * \brief output the tensor info, inc

[GitHub] [incubator-mxnet] marcoabreu commented on issue #15525: Nightly tests / integration tests in PRs are not tested before merging

2019-07-12 Thread GitBox
marcoabreu commented on issue #15525: Nightly tests / integration tests in PRs 
are not tested before merging
URL: 
https://github.com/apache/incubator-mxnet/issues/15525#issuecomment-510985789
 
 
   I'd love to have context sensitive validations. Unfortunately, this feature 
doesn't exist out of the box.
   
   In general I think that we consider master bleeding edge. Thus, it's okay to 
have less coverage for the sake of speed and costs. If a PR breaks something, 
we usually revert it and get back to the original author.
   


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] roywei commented on issue #15525: Nightly tests / integration tests in PRs are not tested before merging

2019-07-12 Thread GitBox
roywei commented on issue #15525: Nightly tests / integration tests in PRs are 
not tested before merging
URL: 
https://github.com/apache/incubator-mxnet/issues/15525#issuecomment-510993342
 
 
   - Nightly tests are supposed to fail and we can revert whichever PR caused 
it, other wise it's too costly to run even for PR validation, imagine each 
commit will trigger a big job.
   - Most of the time, when contributors are changing nightly test 
configurations and adding nightly tests, they test it anyway, it's not likely 
to fail.
   - Test tuorials is a special case as many people are contributing to 
tutorials. But most of them don't know they have to add any dependency in CI 
and warnings are considered as failure. That's most of the reasons for CI 
failure.
   
   To start with, without any new features been added, maybe some way to 
enforce contributors to test tutorials locally before merging PR.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] roywei edited a comment on issue #15525: Nightly tests / integration tests in PRs are not tested before merging

2019-07-12 Thread GitBox
roywei edited a comment on issue #15525: Nightly tests / integration tests in 
PRs are not tested before merging
URL: 
https://github.com/apache/incubator-mxnet/issues/15525#issuecomment-510993342
 
 
   - Nightly tests are supposed to fail and we can revert whichever PR caused 
it, other wise it's too costly to run even selected jobs only for PR 
validation, imagine each commit will trigger a big job.
   - Most of the time, when contributors are changing nightly test 
configurations and adding nightly tests, they test it anyway, it's not likely 
to fail.
   - Test tuorials is a special case as many people are contributing to 
tutorials. But most of them don't know they have to add any dependency in CI 
and warnings are considered as failure. That's most of the reasons for CI 
failure.
   
   To start with, without any new features been added, maybe some way to 
enforce contributors to test tutorials locally before merging PR.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] roywei edited a comment on issue #15525: Nightly tests / integration tests in PRs are not tested before merging

2019-07-12 Thread GitBox
roywei edited a comment on issue #15525: Nightly tests / integration tests in 
PRs are not tested before merging
URL: 
https://github.com/apache/incubator-mxnet/issues/15525#issuecomment-510993342
 
 
   - Nightly tests are supposed to fail and we can revert whichever PR caused 
it, other wise it's too costly to run even selected jobs only for PR 
validation, imagine each commit will trigger a big job.
   - Most of the time, when contributors are changing nightly test 
configurations and adding nightly tests, they test it anyway, it's not likely 
to fail.
   - Test tuorials is a special case as many people are contributing to 
tutorials. But most of them don't know they have to add any dependency package 
used in tutorial in CI docker file and warnings are considered as failure. 
That's most of the reasons for CI failure.
   
   To start with, without any new features been added, maybe some way to 
enforce contributors to test tutorials locally before merging PR.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] roywei edited a comment on issue #15525: Nightly tests / integration tests in PRs are not tested before merging

2019-07-12 Thread GitBox
roywei edited a comment on issue #15525: Nightly tests / integration tests in 
PRs are not tested before merging
URL: 
https://github.com/apache/incubator-mxnet/issues/15525#issuecomment-510993342
 
 
   - Nightly tests are supposed to fail and we can revert whichever PR caused 
it, other wise it's too costly to run even selected jobs only for PR 
validation, imagine each commit will trigger a big job.
   - Most of the time, when contributors are changing nightly test 
configurations and adding nightly tests, they test it anyway, it's not likely 
to fail.
   - Test tuorials is a special case as many people are contributing to 
tutorials. But most of them don't know they have to add any dependency package 
used in tutorial in CI docker file and warnings generated are considered as 
failure. That's most of the reasons for CI failure.
   
   To start with, without any new features been added, maybe some way to 
enforce contributors to test tutorials locally before merging PR.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] roywei edited a comment on issue #15525: Nightly tests / integration tests in PRs are not tested before merging

2019-07-12 Thread GitBox
roywei edited a comment on issue #15525: Nightly tests / integration tests in 
PRs are not tested before merging
URL: 
https://github.com/apache/incubator-mxnet/issues/15525#issuecomment-510993342
 
 
   - Nightly tests are supposed to fail and we can revert whichever PR caused 
it, other wise it's too costly to run even selected jobs only for PR 
validation, imagine each commit will trigger a big job.
   - Most of the time, when contributors are changing nightly test 
configurations and adding nightly tests, they test it anyway, it's not likely 
to fail.
   - Test tuorials is a special case as many people are contributing to 
tutorials. But most of them don't know they have to add any dependency package 
used in tutorial in CI docker file and warnings generated are considered as 
failure. That's most of the reasons for CI failure.
   
   To start with, without any new features been added, maybe some way to 
enforce contributors to test locally before merging PR.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] roywei edited a comment on issue #15525: Nightly tests / integration tests in PRs are not tested before merging

2019-07-12 Thread GitBox
roywei edited a comment on issue #15525: Nightly tests / integration tests in 
PRs are not tested before merging
URL: 
https://github.com/apache/incubator-mxnet/issues/15525#issuecomment-510993342
 
 
   - Nightly tests are supposed to fail and we can revert whichever PR caused 
it, other wise it's too costly to run even selected jobs only for PR 
validation, imagine each commit will trigger a big job.
   - Most of the time, when contributors are changing nightly test 
configurations and adding nightly tests, they test it anyway, it's not likely 
to fail.
   - Test tuorials is a special case as many people are contributing to 
tutorials. But most of them don't know they have to add any dependency package 
used in tutorial in CI docker file and warnings generated are considered as 
failure. That's most of the reasons for CI failure.
   
   To start with, without any new features been added, maybe some way to 
enforce contributors to test locally before merging PR.  (Having label bot to 
leave a message if nightly test change detected?)


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] roywei edited a comment on issue #15525: Nightly tests / integration tests in PRs are not tested before merging

2019-07-12 Thread GitBox
roywei edited a comment on issue #15525: Nightly tests / integration tests in 
PRs are not tested before merging
URL: 
https://github.com/apache/incubator-mxnet/issues/15525#issuecomment-510993342
 
 
   - Nightly tests are supposed to fail and we can revert whichever PR caused 
it, other wise it's too costly to run even selected jobs only for PR 
validation, imagine each commit will trigger a big job.
   - Most of the time, when contributors are changing nightly test 
configurations and adding nightly tests, they test it anyway, it's not likely 
to fail.
   - Test tuorials is a special case as many people are contributing to 
tutorials. But most of them don't know they have to add any dependency package 
used in tutorial in CI docker file and warnings generated are considered as 
failure. That's most of the reasons for CI failure.
   
   To start with, without any new features been added to CI, maybe some way to 
enforce contributors to test locally before merging PR.  (Having label bot to 
leave a message if nightly test change detected?)


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] anirudh2290 commented on a change in pull request #15245: FP16 Support for C Predict API

2019-07-12 Thread GitBox
anirudh2290 commented on a change in pull request #15245: FP16 Support for C 
Predict API
URL: https://github.com/apache/incubator-mxnet/pull/15245#discussion_r303110259
 
 

 ##
 File path: amalgamation/python/mxnet_predict.py
 ##
 @@ -160,10 +249,18 @@ def forward(self, **kwargs):
 >>> predictor.forward(data=mydata)
 >>> out = predictor.get_output(0)
 """
+if self.type_dict and len(self.type_dict) != len(kwargs.items()):
+raise ValueError("number of kwargs should be same as len of 
type_dict" \
+ "Please check your forward pass inputs" \
+ "or type_dict passed to Predictor instantiation")
+
 for k, v in kwargs.items():
 if not isinstance(v, np.ndarray):
 raise ValueError("Expect numpy ndarray as input")
-v = np.asarray(v, dtype=np.float32, order='C')
+if self.type_dict and k in self.type_dict:
+v = np.asarray(v, dtype=self.type_dict[k], order='C')
+else:
+v = np.asarray(v, dtype=np.float32, order='C')
 
 Review comment:
   we use the lookup table to map the dtype int, which comes from mxnet backend 
to numpy dtype. For cases, we are not determining it from backend dtype I think 
it is better to use np.float32 rather than _DTYPE_MX_TO_NP[0].


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] larroy commented on issue #15426: Add -R option to ci/build.py to avoid rebuilding containers

2019-07-12 Thread GitBox
larroy commented on issue #15426: Add -R option to ci/build.py to avoid 
rebuilding containers
URL: https://github.com/apache/incubator-mxnet/pull/15426#issuecomment-510997277
 
 
   Danke fuer die merge.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] larroy edited a comment on issue #15426: Add -R option to ci/build.py to avoid rebuilding containers

2019-07-12 Thread GitBox
larroy edited a comment on issue #15426: Add -R option to ci/build.py to avoid 
rebuilding containers
URL: https://github.com/apache/incubator-mxnet/pull/15426#issuecomment-510997277
 
 
   Danke für die merge.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] larroy commented on issue #15270: Fix warnings in CLang.

2019-07-12 Thread GitBox
larroy commented on issue #15270: Fix warnings in CLang.
URL: https://github.com/apache/incubator-mxnet/pull/15270#issuecomment-510997782
 
 
   Done, could we get those small PRs that fix warnings merged?


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] marcoabreu commented on issue #15525: Nightly tests / integration tests in PRs are not tested before merging

2019-07-12 Thread GitBox
marcoabreu commented on issue #15525: Nightly tests / integration tests in PRs 
are not tested before merging
URL: 
https://github.com/apache/incubator-mxnet/issues/15525#issuecomment-510999095
 
 
   I'm certainly in favour of a context sensitive bot that gives certain 
comments if certain types of changes are detected. But enforcing directly isn't 
possible besides adding actual checks.
   
   For example, we asked people in the past to run make lint locally. I could 
give you statistics about how often linting fails in ci, but trust me that 
something that simple isn't even followed most of the time. So basically we 
can't request anything from people unless we enforce it, which I'm opposed to 
in this particular case


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] larroy commented on issue #15465: [RFC] Integrate TVM into Apache MXNet

2019-07-12 Thread GitBox
larroy commented on issue #15465: [RFC] Integrate TVM into Apache MXNet
URL: 
https://github.com/apache/incubator-mxnet/issues/15465#issuecomment-510999368
 
 
   Could we add more information on how will it impact the build systems and 
dependencies? While integrating TVM is exciting, I think is fair to gauge the 
increase of complexity, build and release implications. Would it be possible to 
load operators compiled with TVM dynamically? This would open a path to 
modularize MXNet and reduce the library size / target inference only version in 
a more streamlined way than with amalgamation hacks.


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] larroy commented on a change in pull request #15490: Utility to help developers debug operators: Tensor Inspector

2019-07-12 Thread GitBox
larroy commented on a change in pull request #15490: Utility to help developers 
debug operators: Tensor Inspector
URL: https://github.com/apache/incubator-mxnet/pull/15490#discussion_r303115908
 
 

 ##
 File path: src/common/tensor_inspector.h
 ##
 @@ -0,0 +1,733 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*!
+ * Copyright (c) 2019 by Contributors
+ * \file tensor_inspector.h
+ * \brief utility to inspect tensor objects
+ * \author Zhaoqi Zhu
+ */
+
+#ifndef MXNET_COMMON_TENSOR_INSPECTOR_H_
+#define MXNET_COMMON_TENSOR_INSPECTOR_H_
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "../../3rdparty/mshadow/mshadow/base.h"
+#include "../../tests/cpp/include/test_util.h"
+
+namespace mxnet {
+
+/*!
+ * \brief this singleton struct mediates individual TensorInspector objects
+ * so that we can control the global behavior from each of them
+ */
+struct InspectorManager {
+  static InspectorManager* get() {
+static std::mutex mtx;
+static std::unique_ptr im = nullptr;
+if (!im) {
+  std::unique_lock lk(mtx);
+  if (!im)
+im = std::make_unique();
+}
+return im.get();
+  }
+  /* !\brief mutex used to lock interactive_print() and check_value() */
+  std::mutex mutex_;
+  /* !\brief skip all interactive prints */
+  bool interactive_print_skip_all_ = false;
+  /* !\brief skip all value checks */
+  bool check_value_skip_all_ = false;
+  /* !\brief visit count for interactive print tags */
+  std::unordered_map interactive_print_tag_counter_;
+  /* !\brief visit count for check value tags */
+  std::unordered_map check_value_tag_counter_;
+  /* !\brief visit count for dump value tags */
+  std::unordered_map dump_value_tag_counter_;
+};
+
+/*!
+ * \brief Enum for building value checkers for TensorInspector::check_value()
+ */
+enum CheckerType {
+  NegativeChecker,  // check if is negative
+  PositiveChecker,  // check if is positive
+  ZeroChecker,  // check if is zero
+  NaNChecker,  // check if is NaN, will always return false if DType is not a 
float type
+  InfChecker,  // check if is infinity, will always return false if DType is 
not a float type
+  PositiveInfChecker,  // check if is positive infinity,
+   // will always return false if DType is not a float type
+  NegativeInfChecker,  // check if is nagative infinity,
+   // will always return false if DType is not a float type
+  FiniteChecker,  // check if is finite, will always return false if DType is 
not a float type
+  NormalChecker,  // check if is neither infinity nor NaN
+  AbnormalChecker,  // chekck if is infinity or nan
+};
+
+/**
+ *  ___  _   _ 
+ * |__   __||_   _| | |
+ *| | ___ _ __  ___  ___  _ __| |  _ __  ___ _ __   ___  ___| |_ ___  _ __ 
+ *| |/ _ \ '_ \/ __|/ _ \| '__| | | '_ \/ __| '_ \ / _ \/ __| __/ _ \| '__|
+ *| |  __/ | | \__ \ (_) | | _| |_| | | \__ \ |_) |  __/ (__| || (_) | |   
+ *|_|\___|_| |_|___/\___/|_||_|_| |_|___/ .__/ \___|\___|\__\___/|_|   
+ *  | |
+ *  |_|   
+ */
+
+/*!
+ * \brief This class provides a unified interface to inspect the value of all 
data types
+ * including Tensor, TBlob, and NDArray. If the tensor resides on GPU, then it 
will be
+ * copied from GPU memory back to CPU memory to be operated on. Internally, 
all data types
+ * are stored as a TBlob object tb_.
+ */
+class TensorInspector {
+ private:
+  /*!
+   * \brief generate the tensor info, including data type and shape 
+   * \tparam DType the data type
+   * \tparam StreamType the type of the stream object
+   * \param os stream object to output to
+   */
+  template
+  inline void tensor_info_to_string(StreamType* os) {
+int dimension = tb_.ndim();
+*os << "<" << typeid(tb_.dptr()[0]).name() << " Tensor ";
+*os << tb_.shape_[0];
+for (int i = 1; i < dimension; ++i) {
+  *os << 'x' << tb_.shape_[i];
+}
+*os << ">" << std::endl;
+  }
+
+  /*!
+   * \brief output the tensor info, inc

[GitHub] [incubator-mxnet] larroy commented on a change in pull request #15490: Utility to help developers debug operators: Tensor Inspector

2019-07-12 Thread GitBox
larroy commented on a change in pull request #15490: Utility to help developers 
debug operators: Tensor Inspector
URL: https://github.com/apache/incubator-mxnet/pull/15490#discussion_r303119170
 
 

 ##
 File path: src/common/tensor_inspector.h
 ##
 @@ -0,0 +1,733 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*!
+ * Copyright (c) 2019 by Contributors
+ * \file tensor_inspector.h
+ * \brief utility to inspect tensor objects
+ * \author Zhaoqi Zhu
+ */
+
+#ifndef MXNET_COMMON_TENSOR_INSPECTOR_H_
+#define MXNET_COMMON_TENSOR_INSPECTOR_H_
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "../../3rdparty/mshadow/mshadow/base.h"
+#include "../../tests/cpp/include/test_util.h"
+
+namespace mxnet {
+
+/*!
+ * \brief this singleton struct mediates individual TensorInspector objects
+ * so that we can control the global behavior from each of them
+ */
+struct InspectorManager {
+  static InspectorManager* get() {
+static std::mutex mtx;
+static std::unique_ptr im = nullptr;
+if (!im) {
+  std::unique_lock lk(mtx);
+  if (!im)
+im = std::make_unique();
+}
+return im.get();
+  }
+  /* !\brief mutex used to lock interactive_print() and check_value() */
+  std::mutex mutex_;
+  /* !\brief skip all interactive prints */
+  bool interactive_print_skip_all_ = false;
+  /* !\brief skip all value checks */
+  bool check_value_skip_all_ = false;
+  /* !\brief visit count for interactive print tags */
+  std::unordered_map interactive_print_tag_counter_;
+  /* !\brief visit count for check value tags */
+  std::unordered_map check_value_tag_counter_;
+  /* !\brief visit count for dump value tags */
+  std::unordered_map dump_value_tag_counter_;
+};
+
+/*!
+ * \brief Enum for building value checkers for TensorInspector::check_value()
+ */
+enum CheckerType {
+  NegativeChecker,  // check if is negative
+  PositiveChecker,  // check if is positive
+  ZeroChecker,  // check if is zero
+  NaNChecker,  // check if is NaN, will always return false if DType is not a 
float type
+  InfChecker,  // check if is infinity, will always return false if DType is 
not a float type
+  PositiveInfChecker,  // check if is positive infinity,
+   // will always return false if DType is not a float type
+  NegativeInfChecker,  // check if is nagative infinity,
+   // will always return false if DType is not a float type
+  FiniteChecker,  // check if is finite, will always return false if DType is 
not a float type
+  NormalChecker,  // check if is neither infinity nor NaN
+  AbnormalChecker,  // chekck if is infinity or nan
+};
+
+/**
+ *  ___  _   _ 
+ * |__   __||_   _| | |
+ *| | ___ _ __  ___  ___  _ __| |  _ __  ___ _ __   ___  ___| |_ ___  _ __ 
+ *| |/ _ \ '_ \/ __|/ _ \| '__| | | '_ \/ __| '_ \ / _ \/ __| __/ _ \| '__|
+ *| |  __/ | | \__ \ (_) | | _| |_| | | \__ \ |_) |  __/ (__| || (_) | |   
+ *|_|\___|_| |_|___/\___/|_||_|_| |_|___/ .__/ \___|\___|\__\___/|_|   
+ *  | |
+ *  |_|   
+ */
+
+/*!
+ * \brief This class provides a unified interface to inspect the value of all 
data types
+ * including Tensor, TBlob, and NDArray. If the tensor resides on GPU, then it 
will be
+ * copied from GPU memory back to CPU memory to be operated on. Internally, 
all data types
+ * are stored as a TBlob object tb_.
+ */
+class TensorInspector {
+ private:
+  /*!
+   * \brief generate the tensor info, including data type and shape 
+   * \tparam DType the data type
+   * \tparam StreamType the type of the stream object
+   * \param os stream object to output to
+   */
+  template
+  inline void tensor_info_to_string(StreamType* os) {
+int dimension = tb_.ndim();
+*os << "<" << typeid(tb_.dptr()[0]).name() << " Tensor ";
+*os << tb_.shape_[0];
+for (int i = 1; i < dimension; ++i) {
+  *os << 'x' << tb_.shape_[i];
+}
+*os << ">" << std::endl;
+  }
+
+  /*!
+   * \brief output the tensor info, inc

[GitHub] [incubator-mxnet] larroy commented on a change in pull request #15490: Utility to help developers debug operators: Tensor Inspector

2019-07-12 Thread GitBox
larroy commented on a change in pull request #15490: Utility to help developers 
debug operators: Tensor Inspector
URL: https://github.com/apache/incubator-mxnet/pull/15490#discussion_r303117010
 
 

 ##
 File path: src/common/tensor_inspector.h
 ##
 @@ -0,0 +1,733 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*!
+ * Copyright (c) 2019 by Contributors
+ * \file tensor_inspector.h
+ * \brief utility to inspect tensor objects
+ * \author Zhaoqi Zhu
+ */
+
+#ifndef MXNET_COMMON_TENSOR_INSPECTOR_H_
+#define MXNET_COMMON_TENSOR_INSPECTOR_H_
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "../../3rdparty/mshadow/mshadow/base.h"
+#include "../../tests/cpp/include/test_util.h"
+
+namespace mxnet {
+
+/*!
+ * \brief this singleton struct mediates individual TensorInspector objects
+ * so that we can control the global behavior from each of them
+ */
+struct InspectorManager {
+  static InspectorManager* get() {
+static std::mutex mtx;
+static std::unique_ptr im = nullptr;
+if (!im) {
+  std::unique_lock lk(mtx);
+  if (!im)
+im = std::make_unique();
+}
+return im.get();
+  }
+  /* !\brief mutex used to lock interactive_print() and check_value() */
+  std::mutex mutex_;
+  /* !\brief skip all interactive prints */
+  bool interactive_print_skip_all_ = false;
+  /* !\brief skip all value checks */
+  bool check_value_skip_all_ = false;
+  /* !\brief visit count for interactive print tags */
+  std::unordered_map interactive_print_tag_counter_;
+  /* !\brief visit count for check value tags */
+  std::unordered_map check_value_tag_counter_;
+  /* !\brief visit count for dump value tags */
+  std::unordered_map dump_value_tag_counter_;
+};
+
+/*!
+ * \brief Enum for building value checkers for TensorInspector::check_value()
+ */
+enum CheckerType {
+  NegativeChecker,  // check if is negative
+  PositiveChecker,  // check if is positive
+  ZeroChecker,  // check if is zero
+  NaNChecker,  // check if is NaN, will always return false if DType is not a 
float type
+  InfChecker,  // check if is infinity, will always return false if DType is 
not a float type
+  PositiveInfChecker,  // check if is positive infinity,
+   // will always return false if DType is not a float type
+  NegativeInfChecker,  // check if is nagative infinity,
+   // will always return false if DType is not a float type
+  FiniteChecker,  // check if is finite, will always return false if DType is 
not a float type
+  NormalChecker,  // check if is neither infinity nor NaN
+  AbnormalChecker,  // chekck if is infinity or nan
+};
+
+/**
+ *  ___  _   _ 
+ * |__   __||_   _| | |
+ *| | ___ _ __  ___  ___  _ __| |  _ __  ___ _ __   ___  ___| |_ ___  _ __ 
+ *| |/ _ \ '_ \/ __|/ _ \| '__| | | '_ \/ __| '_ \ / _ \/ __| __/ _ \| '__|
+ *| |  __/ | | \__ \ (_) | | _| |_| | | \__ \ |_) |  __/ (__| || (_) | |   
+ *|_|\___|_| |_|___/\___/|_||_|_| |_|___/ .__/ \___|\___|\__\___/|_|   
+ *  | |
+ *  |_|   
+ */
+
+/*!
+ * \brief This class provides a unified interface to inspect the value of all 
data types
+ * including Tensor, TBlob, and NDArray. If the tensor resides on GPU, then it 
will be
+ * copied from GPU memory back to CPU memory to be operated on. Internally, 
all data types
+ * are stored as a TBlob object tb_.
+ */
+class TensorInspector {
+ private:
+  /*!
+   * \brief generate the tensor info, including data type and shape 
+   * \tparam DType the data type
+   * \tparam StreamType the type of the stream object
+   * \param os stream object to output to
+   */
+  template
+  inline void tensor_info_to_string(StreamType* os) {
+int dimension = tb_.ndim();
+*os << "<" << typeid(tb_.dptr()[0]).name() << " Tensor ";
+*os << tb_.shape_[0];
+for (int i = 1; i < dimension; ++i) {
+  *os << 'x' << tb_.shape_[i];
+}
+*os << ">" << std::endl;
+  }
+
+  /*!
+   * \brief output the tensor info, inc

[GitHub] [incubator-mxnet] larroy commented on a change in pull request #15490: Utility to help developers debug operators: Tensor Inspector

2019-07-12 Thread GitBox
larroy commented on a change in pull request #15490: Utility to help developers 
debug operators: Tensor Inspector
URL: https://github.com/apache/incubator-mxnet/pull/15490#discussion_r303118403
 
 

 ##
 File path: src/common/tensor_inspector.h
 ##
 @@ -0,0 +1,733 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*!
+ * Copyright (c) 2019 by Contributors
+ * \file tensor_inspector.h
+ * \brief utility to inspect tensor objects
+ * \author Zhaoqi Zhu
+ */
+
+#ifndef MXNET_COMMON_TENSOR_INSPECTOR_H_
+#define MXNET_COMMON_TENSOR_INSPECTOR_H_
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "../../3rdparty/mshadow/mshadow/base.h"
+#include "../../tests/cpp/include/test_util.h"
+
+namespace mxnet {
+
+/*!
+ * \brief this singleton struct mediates individual TensorInspector objects
+ * so that we can control the global behavior from each of them
+ */
+struct InspectorManager {
+  static InspectorManager* get() {
+static std::mutex mtx;
+static std::unique_ptr im = nullptr;
+if (!im) {
+  std::unique_lock lk(mtx);
+  if (!im)
+im = std::make_unique();
+}
+return im.get();
+  }
+  /* !\brief mutex used to lock interactive_print() and check_value() */
+  std::mutex mutex_;
+  /* !\brief skip all interactive prints */
+  bool interactive_print_skip_all_ = false;
+  /* !\brief skip all value checks */
+  bool check_value_skip_all_ = false;
+  /* !\brief visit count for interactive print tags */
+  std::unordered_map interactive_print_tag_counter_;
+  /* !\brief visit count for check value tags */
+  std::unordered_map check_value_tag_counter_;
+  /* !\brief visit count for dump value tags */
+  std::unordered_map dump_value_tag_counter_;
+};
+
+/*!
+ * \brief Enum for building value checkers for TensorInspector::check_value()
+ */
+enum CheckerType {
+  NegativeChecker,  // check if is negative
+  PositiveChecker,  // check if is positive
+  ZeroChecker,  // check if is zero
+  NaNChecker,  // check if is NaN, will always return false if DType is not a 
float type
+  InfChecker,  // check if is infinity, will always return false if DType is 
not a float type
+  PositiveInfChecker,  // check if is positive infinity,
+   // will always return false if DType is not a float type
+  NegativeInfChecker,  // check if is nagative infinity,
+   // will always return false if DType is not a float type
+  FiniteChecker,  // check if is finite, will always return false if DType is 
not a float type
+  NormalChecker,  // check if is neither infinity nor NaN
+  AbnormalChecker,  // chekck if is infinity or nan
+};
+
+/**
+ *  ___  _   _ 
+ * |__   __||_   _| | |
+ *| | ___ _ __  ___  ___  _ __| |  _ __  ___ _ __   ___  ___| |_ ___  _ __ 
+ *| |/ _ \ '_ \/ __|/ _ \| '__| | | '_ \/ __| '_ \ / _ \/ __| __/ _ \| '__|
+ *| |  __/ | | \__ \ (_) | | _| |_| | | \__ \ |_) |  __/ (__| || (_) | |   
+ *|_|\___|_| |_|___/\___/|_||_|_| |_|___/ .__/ \___|\___|\__\___/|_|   
+ *  | |
+ *  |_|   
+ */
+
+/*!
+ * \brief This class provides a unified interface to inspect the value of all 
data types
+ * including Tensor, TBlob, and NDArray. If the tensor resides on GPU, then it 
will be
+ * copied from GPU memory back to CPU memory to be operated on. Internally, 
all data types
+ * are stored as a TBlob object tb_.
+ */
+class TensorInspector {
+ private:
+  /*!
+   * \brief generate the tensor info, including data type and shape 
+   * \tparam DType the data type
+   * \tparam StreamType the type of the stream object
+   * \param os stream object to output to
+   */
+  template
+  inline void tensor_info_to_string(StreamType* os) {
+int dimension = tb_.ndim();
+*os << "<" << typeid(tb_.dptr()[0]).name() << " Tensor ";
+*os << tb_.shape_[0];
+for (int i = 1; i < dimension; ++i) {
+  *os << 'x' << tb_.shape_[i];
+}
+*os << ">" << std::endl;
+  }
+
+  /*!
+   * \brief output the tensor info, inc

[GitHub] [incubator-mxnet] larroy commented on a change in pull request #15490: Utility to help developers debug operators: Tensor Inspector

2019-07-12 Thread GitBox
larroy commented on a change in pull request #15490: Utility to help developers 
debug operators: Tensor Inspector
URL: https://github.com/apache/incubator-mxnet/pull/15490#discussion_r303113524
 
 

 ##
 File path: src/common/tensor_inspector.h
 ##
 @@ -0,0 +1,733 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*!
+ * Copyright (c) 2019 by Contributors
+ * \file tensor_inspector.h
+ * \brief utility to inspect tensor objects
+ * \author Zhaoqi Zhu
+ */
+
+#ifndef MXNET_COMMON_TENSOR_INSPECTOR_H_
+#define MXNET_COMMON_TENSOR_INSPECTOR_H_
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "../../3rdparty/mshadow/mshadow/base.h"
+#include "../../tests/cpp/include/test_util.h"
+
+namespace mxnet {
+
+/*!
+ * \brief this singleton struct mediates individual TensorInspector objects
+ * so that we can control the global behavior from each of them
+ */
+struct InspectorManager {
+  static InspectorManager* get() {
+static std::mutex mtx;
+static std::unique_ptr im = nullptr;
+if (!im) {
+  std::unique_lock lk(mtx);
+  if (!im)
+im = std::make_unique();
+}
+return im.get();
+  }
+  /* !\brief mutex used to lock interactive_print() and check_value() */
+  std::mutex mutex_;
+  /* !\brief skip all interactive prints */
+  bool interactive_print_skip_all_ = false;
+  /* !\brief skip all value checks */
+  bool check_value_skip_all_ = false;
+  /* !\brief visit count for interactive print tags */
+  std::unordered_map interactive_print_tag_counter_;
+  /* !\brief visit count for check value tags */
+  std::unordered_map check_value_tag_counter_;
+  /* !\brief visit count for dump value tags */
+  std::unordered_map dump_value_tag_counter_;
+};
+
+/*!
+ * \brief Enum for building value checkers for TensorInspector::check_value()
+ */
+enum CheckerType {
+  NegativeChecker,  // check if is negative
+  PositiveChecker,  // check if is positive
+  ZeroChecker,  // check if is zero
+  NaNChecker,  // check if is NaN, will always return false if DType is not a 
float type
+  InfChecker,  // check if is infinity, will always return false if DType is 
not a float type
+  PositiveInfChecker,  // check if is positive infinity,
+   // will always return false if DType is not a float type
+  NegativeInfChecker,  // check if is nagative infinity,
+   // will always return false if DType is not a float type
+  FiniteChecker,  // check if is finite, will always return false if DType is 
not a float type
+  NormalChecker,  // check if is neither infinity nor NaN
+  AbnormalChecker,  // chekck if is infinity or nan
+};
+
+/**
+ *  ___  _   _ 
+ * |__   __||_   _| | |
+ *| | ___ _ __  ___  ___  _ __| |  _ __  ___ _ __   ___  ___| |_ ___  _ __ 
+ *| |/ _ \ '_ \/ __|/ _ \| '__| | | '_ \/ __| '_ \ / _ \/ __| __/ _ \| '__|
+ *| |  __/ | | \__ \ (_) | | _| |_| | | \__ \ |_) |  __/ (__| || (_) | |   
+ *|_|\___|_| |_|___/\___/|_||_|_| |_|___/ .__/ \___|\___|\__\___/|_|   
+ *  | |
+ *  |_|   
+ */
+
+/*!
+ * \brief This class provides a unified interface to inspect the value of all 
data types
+ * including Tensor, TBlob, and NDArray. If the tensor resides on GPU, then it 
will be
+ * copied from GPU memory back to CPU memory to be operated on. Internally, 
all data types
+ * are stored as a TBlob object tb_.
+ */
+class TensorInspector {
+ private:
+  /*!
+   * \brief generate the tensor info, including data type and shape 
+   * \tparam DType the data type
+   * \tparam StreamType the type of the stream object
+   * \param os stream object to output to
+   */
+  template
+  inline void tensor_info_to_string(StreamType* os) {
+int dimension = tb_.ndim();
 
 Review comment:
   const?


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.
 
F

[GitHub] [incubator-mxnet] larroy commented on a change in pull request #15490: Utility to help developers debug operators: Tensor Inspector

2019-07-12 Thread GitBox
larroy commented on a change in pull request #15490: Utility to help developers 
debug operators: Tensor Inspector
URL: https://github.com/apache/incubator-mxnet/pull/15490#discussion_r303113874
 
 

 ##
 File path: src/common/tensor_inspector.h
 ##
 @@ -0,0 +1,733 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*!
+ * Copyright (c) 2019 by Contributors
+ * \file tensor_inspector.h
+ * \brief utility to inspect tensor objects
+ * \author Zhaoqi Zhu
+ */
+
+#ifndef MXNET_COMMON_TENSOR_INSPECTOR_H_
+#define MXNET_COMMON_TENSOR_INSPECTOR_H_
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "../../3rdparty/mshadow/mshadow/base.h"
+#include "../../tests/cpp/include/test_util.h"
+
+namespace mxnet {
+
+/*!
+ * \brief this singleton struct mediates individual TensorInspector objects
+ * so that we can control the global behavior from each of them
+ */
+struct InspectorManager {
+  static InspectorManager* get() {
+static std::mutex mtx;
+static std::unique_ptr im = nullptr;
+if (!im) {
+  std::unique_lock lk(mtx);
+  if (!im)
+im = std::make_unique();
+}
+return im.get();
+  }
+  /* !\brief mutex used to lock interactive_print() and check_value() */
+  std::mutex mutex_;
+  /* !\brief skip all interactive prints */
+  bool interactive_print_skip_all_ = false;
+  /* !\brief skip all value checks */
+  bool check_value_skip_all_ = false;
+  /* !\brief visit count for interactive print tags */
+  std::unordered_map interactive_print_tag_counter_;
+  /* !\brief visit count for check value tags */
+  std::unordered_map check_value_tag_counter_;
+  /* !\brief visit count for dump value tags */
+  std::unordered_map dump_value_tag_counter_;
+};
+
+/*!
+ * \brief Enum for building value checkers for TensorInspector::check_value()
+ */
+enum CheckerType {
+  NegativeChecker,  // check if is negative
+  PositiveChecker,  // check if is positive
+  ZeroChecker,  // check if is zero
+  NaNChecker,  // check if is NaN, will always return false if DType is not a 
float type
+  InfChecker,  // check if is infinity, will always return false if DType is 
not a float type
+  PositiveInfChecker,  // check if is positive infinity,
+   // will always return false if DType is not a float type
+  NegativeInfChecker,  // check if is nagative infinity,
+   // will always return false if DType is not a float type
+  FiniteChecker,  // check if is finite, will always return false if DType is 
not a float type
+  NormalChecker,  // check if is neither infinity nor NaN
+  AbnormalChecker,  // chekck if is infinity or nan
+};
+
+/**
+ *  ___  _   _ 
+ * |__   __||_   _| | |
+ *| | ___ _ __  ___  ___  _ __| |  _ __  ___ _ __   ___  ___| |_ ___  _ __ 
+ *| |/ _ \ '_ \/ __|/ _ \| '__| | | '_ \/ __| '_ \ / _ \/ __| __/ _ \| '__|
+ *| |  __/ | | \__ \ (_) | | _| |_| | | \__ \ |_) |  __/ (__| || (_) | |   
+ *|_|\___|_| |_|___/\___/|_||_|_| |_|___/ .__/ \___|\___|\__\___/|_|   
+ *  | |
+ *  |_|   
+ */
+
+/*!
+ * \brief This class provides a unified interface to inspect the value of all 
data types
+ * including Tensor, TBlob, and NDArray. If the tensor resides on GPU, then it 
will be
+ * copied from GPU memory back to CPU memory to be operated on. Internally, 
all data types
+ * are stored as a TBlob object tb_.
+ */
+class TensorInspector {
+ private:
+  /*!
+   * \brief generate the tensor info, including data type and shape 
+   * \tparam DType the data type
+   * \tparam StreamType the type of the stream object
+   * \param os stream object to output to
+   */
+  template
+  inline void tensor_info_to_string(StreamType* os) {
+int dimension = tb_.ndim();
+*os << "<" << typeid(tb_.dptr()[0]).name() << " Tensor ";
+*os << tb_.shape_[0];
+for (int i = 1; i < dimension; ++i) {
+  *os << 'x' << tb_.shape_[i];
+}
+*os << ">" << std::endl;
+  }
+
+  /*!
+   * \brief output the tensor info, inc

[GitHub] [incubator-mxnet] larroy commented on a change in pull request #15490: Utility to help developers debug operators: Tensor Inspector

2019-07-12 Thread GitBox
larroy commented on a change in pull request #15490: Utility to help developers 
debug operators: Tensor Inspector
URL: https://github.com/apache/incubator-mxnet/pull/15490#discussion_r303118876
 
 

 ##
 File path: src/common/tensor_inspector.h
 ##
 @@ -0,0 +1,733 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*!
+ * Copyright (c) 2019 by Contributors
+ * \file tensor_inspector.h
+ * \brief utility to inspect tensor objects
+ * \author Zhaoqi Zhu
+ */
+
+#ifndef MXNET_COMMON_TENSOR_INSPECTOR_H_
+#define MXNET_COMMON_TENSOR_INSPECTOR_H_
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "../../3rdparty/mshadow/mshadow/base.h"
+#include "../../tests/cpp/include/test_util.h"
+
+namespace mxnet {
+
+/*!
+ * \brief this singleton struct mediates individual TensorInspector objects
+ * so that we can control the global behavior from each of them
+ */
+struct InspectorManager {
+  static InspectorManager* get() {
+static std::mutex mtx;
+static std::unique_ptr im = nullptr;
+if (!im) {
+  std::unique_lock lk(mtx);
+  if (!im)
+im = std::make_unique();
+}
+return im.get();
+  }
+  /* !\brief mutex used to lock interactive_print() and check_value() */
+  std::mutex mutex_;
+  /* !\brief skip all interactive prints */
+  bool interactive_print_skip_all_ = false;
+  /* !\brief skip all value checks */
+  bool check_value_skip_all_ = false;
+  /* !\brief visit count for interactive print tags */
+  std::unordered_map interactive_print_tag_counter_;
+  /* !\brief visit count for check value tags */
+  std::unordered_map check_value_tag_counter_;
+  /* !\brief visit count for dump value tags */
+  std::unordered_map dump_value_tag_counter_;
+};
+
+/*!
+ * \brief Enum for building value checkers for TensorInspector::check_value()
+ */
+enum CheckerType {
+  NegativeChecker,  // check if is negative
+  PositiveChecker,  // check if is positive
+  ZeroChecker,  // check if is zero
+  NaNChecker,  // check if is NaN, will always return false if DType is not a 
float type
+  InfChecker,  // check if is infinity, will always return false if DType is 
not a float type
+  PositiveInfChecker,  // check if is positive infinity,
+   // will always return false if DType is not a float type
+  NegativeInfChecker,  // check if is nagative infinity,
+   // will always return false if DType is not a float type
+  FiniteChecker,  // check if is finite, will always return false if DType is 
not a float type
+  NormalChecker,  // check if is neither infinity nor NaN
+  AbnormalChecker,  // chekck if is infinity or nan
+};
+
+/**
+ *  ___  _   _ 
+ * |__   __||_   _| | |
+ *| | ___ _ __  ___  ___  _ __| |  _ __  ___ _ __   ___  ___| |_ ___  _ __ 
+ *| |/ _ \ '_ \/ __|/ _ \| '__| | | '_ \/ __| '_ \ / _ \/ __| __/ _ \| '__|
+ *| |  __/ | | \__ \ (_) | | _| |_| | | \__ \ |_) |  __/ (__| || (_) | |   
+ *|_|\___|_| |_|___/\___/|_||_|_| |_|___/ .__/ \___|\___|\__\___/|_|   
+ *  | |
+ *  |_|   
+ */
+
+/*!
+ * \brief This class provides a unified interface to inspect the value of all 
data types
+ * including Tensor, TBlob, and NDArray. If the tensor resides on GPU, then it 
will be
+ * copied from GPU memory back to CPU memory to be operated on. Internally, 
all data types
+ * are stored as a TBlob object tb_.
+ */
+class TensorInspector {
+ private:
+  /*!
+   * \brief generate the tensor info, including data type and shape 
+   * \tparam DType the data type
+   * \tparam StreamType the type of the stream object
+   * \param os stream object to output to
+   */
+  template
+  inline void tensor_info_to_string(StreamType* os) {
+int dimension = tb_.ndim();
+*os << "<" << typeid(tb_.dptr()[0]).name() << " Tensor ";
+*os << tb_.shape_[0];
+for (int i = 1; i < dimension; ++i) {
+  *os << 'x' << tb_.shape_[i];
+}
+*os << ">" << std::endl;
+  }
+
+  /*!
+   * \brief output the tensor info, inc

[GitHub] [incubator-mxnet] larroy commented on a change in pull request #15490: Utility to help developers debug operators: Tensor Inspector

2019-07-12 Thread GitBox
larroy commented on a change in pull request #15490: Utility to help developers 
debug operators: Tensor Inspector
URL: https://github.com/apache/incubator-mxnet/pull/15490#discussion_r303119928
 
 

 ##
 File path: src/common/tensor_inspector.h
 ##
 @@ -0,0 +1,733 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*!
+ * Copyright (c) 2019 by Contributors
+ * \file tensor_inspector.h
+ * \brief utility to inspect tensor objects
+ * \author Zhaoqi Zhu
+ */
+
+#ifndef MXNET_COMMON_TENSOR_INSPECTOR_H_
+#define MXNET_COMMON_TENSOR_INSPECTOR_H_
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "../../3rdparty/mshadow/mshadow/base.h"
+#include "../../tests/cpp/include/test_util.h"
+
+namespace mxnet {
+
+/*!
+ * \brief this singleton struct mediates individual TensorInspector objects
+ * so that we can control the global behavior from each of them
+ */
+struct InspectorManager {
+  static InspectorManager* get() {
+static std::mutex mtx;
+static std::unique_ptr im = nullptr;
+if (!im) {
+  std::unique_lock lk(mtx);
+  if (!im)
+im = std::make_unique();
+}
+return im.get();
+  }
+  /* !\brief mutex used to lock interactive_print() and check_value() */
+  std::mutex mutex_;
+  /* !\brief skip all interactive prints */
+  bool interactive_print_skip_all_ = false;
+  /* !\brief skip all value checks */
+  bool check_value_skip_all_ = false;
+  /* !\brief visit count for interactive print tags */
+  std::unordered_map interactive_print_tag_counter_;
+  /* !\brief visit count for check value tags */
+  std::unordered_map check_value_tag_counter_;
+  /* !\brief visit count for dump value tags */
+  std::unordered_map dump_value_tag_counter_;
+};
+
+/*!
+ * \brief Enum for building value checkers for TensorInspector::check_value()
+ */
+enum CheckerType {
+  NegativeChecker,  // check if is negative
+  PositiveChecker,  // check if is positive
+  ZeroChecker,  // check if is zero
+  NaNChecker,  // check if is NaN, will always return false if DType is not a 
float type
+  InfChecker,  // check if is infinity, will always return false if DType is 
not a float type
+  PositiveInfChecker,  // check if is positive infinity,
+   // will always return false if DType is not a float type
+  NegativeInfChecker,  // check if is nagative infinity,
+   // will always return false if DType is not a float type
+  FiniteChecker,  // check if is finite, will always return false if DType is 
not a float type
+  NormalChecker,  // check if is neither infinity nor NaN
+  AbnormalChecker,  // chekck if is infinity or nan
+};
+
+/**
+ *  ___  _   _ 
+ * |__   __||_   _| | |
+ *| | ___ _ __  ___  ___  _ __| |  _ __  ___ _ __   ___  ___| |_ ___  _ __ 
+ *| |/ _ \ '_ \/ __|/ _ \| '__| | | '_ \/ __| '_ \ / _ \/ __| __/ _ \| '__|
+ *| |  __/ | | \__ \ (_) | | _| |_| | | \__ \ |_) |  __/ (__| || (_) | |   
+ *|_|\___|_| |_|___/\___/|_||_|_| |_|___/ .__/ \___|\___|\__\___/|_|   
+ *  | |
+ *  |_|   
+ */
+
+/*!
+ * \brief This class provides a unified interface to inspect the value of all 
data types
+ * including Tensor, TBlob, and NDArray. If the tensor resides on GPU, then it 
will be
+ * copied from GPU memory back to CPU memory to be operated on. Internally, 
all data types
+ * are stored as a TBlob object tb_.
+ */
+class TensorInspector {
+ private:
+  /*!
+   * \brief generate the tensor info, including data type and shape 
+   * \tparam DType the data type
+   * \tparam StreamType the type of the stream object
+   * \param os stream object to output to
+   */
+  template
+  inline void tensor_info_to_string(StreamType* os) {
+int dimension = tb_.ndim();
+*os << "<" << typeid(tb_.dptr()[0]).name() << " Tensor ";
+*os << tb_.shape_[0];
+for (int i = 1; i < dimension; ++i) {
+  *os << 'x' << tb_.shape_[i];
+}
+*os << ">" << std::endl;
+  }
+
+  /*!
+   * \brief output the tensor info, inc

[GitHub] [incubator-mxnet] larroy commented on a change in pull request #15490: Utility to help developers debug operators: Tensor Inspector

2019-07-12 Thread GitBox
larroy commented on a change in pull request #15490: Utility to help developers 
debug operators: Tensor Inspector
URL: https://github.com/apache/incubator-mxnet/pull/15490#discussion_r303118036
 
 

 ##
 File path: src/common/tensor_inspector.h
 ##
 @@ -0,0 +1,733 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*!
+ * Copyright (c) 2019 by Contributors
+ * \file tensor_inspector.h
+ * \brief utility to inspect tensor objects
+ * \author Zhaoqi Zhu
+ */
+
+#ifndef MXNET_COMMON_TENSOR_INSPECTOR_H_
+#define MXNET_COMMON_TENSOR_INSPECTOR_H_
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "../../3rdparty/mshadow/mshadow/base.h"
+#include "../../tests/cpp/include/test_util.h"
+
+namespace mxnet {
+
+/*!
+ * \brief this singleton struct mediates individual TensorInspector objects
+ * so that we can control the global behavior from each of them
+ */
+struct InspectorManager {
+  static InspectorManager* get() {
+static std::mutex mtx;
+static std::unique_ptr im = nullptr;
+if (!im) {
+  std::unique_lock lk(mtx);
+  if (!im)
+im = std::make_unique();
+}
+return im.get();
+  }
+  /* !\brief mutex used to lock interactive_print() and check_value() */
+  std::mutex mutex_;
+  /* !\brief skip all interactive prints */
+  bool interactive_print_skip_all_ = false;
+  /* !\brief skip all value checks */
+  bool check_value_skip_all_ = false;
+  /* !\brief visit count for interactive print tags */
+  std::unordered_map interactive_print_tag_counter_;
+  /* !\brief visit count for check value tags */
+  std::unordered_map check_value_tag_counter_;
+  /* !\brief visit count for dump value tags */
+  std::unordered_map dump_value_tag_counter_;
+};
+
+/*!
+ * \brief Enum for building value checkers for TensorInspector::check_value()
+ */
+enum CheckerType {
+  NegativeChecker,  // check if is negative
+  PositiveChecker,  // check if is positive
+  ZeroChecker,  // check if is zero
+  NaNChecker,  // check if is NaN, will always return false if DType is not a 
float type
+  InfChecker,  // check if is infinity, will always return false if DType is 
not a float type
+  PositiveInfChecker,  // check if is positive infinity,
+   // will always return false if DType is not a float type
+  NegativeInfChecker,  // check if is nagative infinity,
+   // will always return false if DType is not a float type
+  FiniteChecker,  // check if is finite, will always return false if DType is 
not a float type
+  NormalChecker,  // check if is neither infinity nor NaN
+  AbnormalChecker,  // chekck if is infinity or nan
+};
+
+/**
+ *  ___  _   _ 
+ * |__   __||_   _| | |
+ *| | ___ _ __  ___  ___  _ __| |  _ __  ___ _ __   ___  ___| |_ ___  _ __ 
+ *| |/ _ \ '_ \/ __|/ _ \| '__| | | '_ \/ __| '_ \ / _ \/ __| __/ _ \| '__|
+ *| |  __/ | | \__ \ (_) | | _| |_| | | \__ \ |_) |  __/ (__| || (_) | |   
+ *|_|\___|_| |_|___/\___/|_||_|_| |_|___/ .__/ \___|\___|\__\___/|_|   
+ *  | |
+ *  |_|   
+ */
+
+/*!
+ * \brief This class provides a unified interface to inspect the value of all 
data types
+ * including Tensor, TBlob, and NDArray. If the tensor resides on GPU, then it 
will be
+ * copied from GPU memory back to CPU memory to be operated on. Internally, 
all data types
+ * are stored as a TBlob object tb_.
+ */
+class TensorInspector {
+ private:
+  /*!
+   * \brief generate the tensor info, including data type and shape 
+   * \tparam DType the data type
+   * \tparam StreamType the type of the stream object
+   * \param os stream object to output to
+   */
+  template
+  inline void tensor_info_to_string(StreamType* os) {
+int dimension = tb_.ndim();
+*os << "<" << typeid(tb_.dptr()[0]).name() << " Tensor ";
+*os << tb_.shape_[0];
+for (int i = 1; i < dimension; ++i) {
+  *os << 'x' << tb_.shape_[i];
+}
+*os << ">" << std::endl;
+  }
+
+  /*!
+   * \brief output the tensor info, inc

[GitHub] [incubator-mxnet] larroy commented on a change in pull request #15490: Utility to help developers debug operators: Tensor Inspector

2019-07-12 Thread GitBox
larroy commented on a change in pull request #15490: Utility to help developers 
debug operators: Tensor Inspector
URL: https://github.com/apache/incubator-mxnet/pull/15490#discussion_r303119597
 
 

 ##
 File path: src/common/tensor_inspector.h
 ##
 @@ -0,0 +1,733 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*!
+ * Copyright (c) 2019 by Contributors
+ * \file tensor_inspector.h
+ * \brief utility to inspect tensor objects
+ * \author Zhaoqi Zhu
+ */
+
+#ifndef MXNET_COMMON_TENSOR_INSPECTOR_H_
+#define MXNET_COMMON_TENSOR_INSPECTOR_H_
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "../../3rdparty/mshadow/mshadow/base.h"
+#include "../../tests/cpp/include/test_util.h"
+
+namespace mxnet {
+
+/*!
+ * \brief this singleton struct mediates individual TensorInspector objects
+ * so that we can control the global behavior from each of them
+ */
+struct InspectorManager {
+  static InspectorManager* get() {
+static std::mutex mtx;
+static std::unique_ptr im = nullptr;
+if (!im) {
+  std::unique_lock lk(mtx);
+  if (!im)
+im = std::make_unique();
+}
+return im.get();
+  }
+  /* !\brief mutex used to lock interactive_print() and check_value() */
+  std::mutex mutex_;
+  /* !\brief skip all interactive prints */
+  bool interactive_print_skip_all_ = false;
+  /* !\brief skip all value checks */
+  bool check_value_skip_all_ = false;
+  /* !\brief visit count for interactive print tags */
+  std::unordered_map interactive_print_tag_counter_;
+  /* !\brief visit count for check value tags */
+  std::unordered_map check_value_tag_counter_;
+  /* !\brief visit count for dump value tags */
+  std::unordered_map dump_value_tag_counter_;
+};
+
+/*!
+ * \brief Enum for building value checkers for TensorInspector::check_value()
+ */
+enum CheckerType {
+  NegativeChecker,  // check if is negative
+  PositiveChecker,  // check if is positive
+  ZeroChecker,  // check if is zero
+  NaNChecker,  // check if is NaN, will always return false if DType is not a 
float type
+  InfChecker,  // check if is infinity, will always return false if DType is 
not a float type
+  PositiveInfChecker,  // check if is positive infinity,
+   // will always return false if DType is not a float type
+  NegativeInfChecker,  // check if is nagative infinity,
+   // will always return false if DType is not a float type
+  FiniteChecker,  // check if is finite, will always return false if DType is 
not a float type
+  NormalChecker,  // check if is neither infinity nor NaN
+  AbnormalChecker,  // chekck if is infinity or nan
+};
+
+/**
+ *  ___  _   _ 
+ * |__   __||_   _| | |
+ *| | ___ _ __  ___  ___  _ __| |  _ __  ___ _ __   ___  ___| |_ ___  _ __ 
+ *| |/ _ \ '_ \/ __|/ _ \| '__| | | '_ \/ __| '_ \ / _ \/ __| __/ _ \| '__|
+ *| |  __/ | | \__ \ (_) | | _| |_| | | \__ \ |_) |  __/ (__| || (_) | |   
+ *|_|\___|_| |_|___/\___/|_||_|_| |_|___/ .__/ \___|\___|\__\___/|_|   
+ *  | |
+ *  |_|   
+ */
+
+/*!
+ * \brief This class provides a unified interface to inspect the value of all 
data types
+ * including Tensor, TBlob, and NDArray. If the tensor resides on GPU, then it 
will be
+ * copied from GPU memory back to CPU memory to be operated on. Internally, 
all data types
+ * are stored as a TBlob object tb_.
+ */
+class TensorInspector {
+ private:
+  /*!
+   * \brief generate the tensor info, including data type and shape 
+   * \tparam DType the data type
+   * \tparam StreamType the type of the stream object
+   * \param os stream object to output to
+   */
+  template
+  inline void tensor_info_to_string(StreamType* os) {
+int dimension = tb_.ndim();
+*os << "<" << typeid(tb_.dptr()[0]).name() << " Tensor ";
+*os << tb_.shape_[0];
+for (int i = 1; i < dimension; ++i) {
+  *os << 'x' << tb_.shape_[i];
+}
+*os << ">" << std::endl;
+  }
+
+  /*!
+   * \brief output the tensor info, inc

[GitHub] [incubator-mxnet] larroy commented on a change in pull request #15490: Utility to help developers debug operators: Tensor Inspector

2019-07-12 Thread GitBox
larroy commented on a change in pull request #15490: Utility to help developers 
debug operators: Tensor Inspector
URL: https://github.com/apache/incubator-mxnet/pull/15490#discussion_r303113816
 
 

 ##
 File path: src/common/tensor_inspector.h
 ##
 @@ -0,0 +1,733 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*!
+ * Copyright (c) 2019 by Contributors
+ * \file tensor_inspector.h
+ * \brief utility to inspect tensor objects
+ * \author Zhaoqi Zhu
+ */
+
+#ifndef MXNET_COMMON_TENSOR_INSPECTOR_H_
+#define MXNET_COMMON_TENSOR_INSPECTOR_H_
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "../../3rdparty/mshadow/mshadow/base.h"
+#include "../../tests/cpp/include/test_util.h"
+
+namespace mxnet {
+
+/*!
+ * \brief this singleton struct mediates individual TensorInspector objects
+ * so that we can control the global behavior from each of them
+ */
+struct InspectorManager {
+  static InspectorManager* get() {
+static std::mutex mtx;
+static std::unique_ptr im = nullptr;
+if (!im) {
+  std::unique_lock lk(mtx);
+  if (!im)
+im = std::make_unique();
+}
+return im.get();
+  }
+  /* !\brief mutex used to lock interactive_print() and check_value() */
+  std::mutex mutex_;
+  /* !\brief skip all interactive prints */
+  bool interactive_print_skip_all_ = false;
+  /* !\brief skip all value checks */
+  bool check_value_skip_all_ = false;
+  /* !\brief visit count for interactive print tags */
+  std::unordered_map interactive_print_tag_counter_;
+  /* !\brief visit count for check value tags */
+  std::unordered_map check_value_tag_counter_;
+  /* !\brief visit count for dump value tags */
+  std::unordered_map dump_value_tag_counter_;
+};
+
+/*!
+ * \brief Enum for building value checkers for TensorInspector::check_value()
+ */
+enum CheckerType {
+  NegativeChecker,  // check if is negative
+  PositiveChecker,  // check if is positive
+  ZeroChecker,  // check if is zero
+  NaNChecker,  // check if is NaN, will always return false if DType is not a 
float type
+  InfChecker,  // check if is infinity, will always return false if DType is 
not a float type
+  PositiveInfChecker,  // check if is positive infinity,
+   // will always return false if DType is not a float type
+  NegativeInfChecker,  // check if is nagative infinity,
+   // will always return false if DType is not a float type
+  FiniteChecker,  // check if is finite, will always return false if DType is 
not a float type
+  NormalChecker,  // check if is neither infinity nor NaN
+  AbnormalChecker,  // chekck if is infinity or nan
+};
+
+/**
+ *  ___  _   _ 
+ * |__   __||_   _| | |
+ *| | ___ _ __  ___  ___  _ __| |  _ __  ___ _ __   ___  ___| |_ ___  _ __ 
+ *| |/ _ \ '_ \/ __|/ _ \| '__| | | '_ \/ __| '_ \ / _ \/ __| __/ _ \| '__|
+ *| |  __/ | | \__ \ (_) | | _| |_| | | \__ \ |_) |  __/ (__| || (_) | |   
+ *|_|\___|_| |_|___/\___/|_||_|_| |_|___/ .__/ \___|\___|\__\___/|_|   
+ *  | |
+ *  |_|   
+ */
+
+/*!
+ * \brief This class provides a unified interface to inspect the value of all 
data types
+ * including Tensor, TBlob, and NDArray. If the tensor resides on GPU, then it 
will be
+ * copied from GPU memory back to CPU memory to be operated on. Internally, 
all data types
+ * are stored as a TBlob object tb_.
+ */
+class TensorInspector {
+ private:
+  /*!
+   * \brief generate the tensor info, including data type and shape 
+   * \tparam DType the data type
+   * \tparam StreamType the type of the stream object
+   * \param os stream object to output to
+   */
+  template
+  inline void tensor_info_to_string(StreamType* os) {
+int dimension = tb_.ndim();
+*os << "<" << typeid(tb_.dptr()[0]).name() << " Tensor ";
+*os << tb_.shape_[0];
+for (int i = 1; i < dimension; ++i) {
+  *os << 'x' << tb_.shape_[i];
+}
+*os << ">" << std::endl;
+  }
+
+  /*!
+   * \brief output the tensor info, inc

[GitHub] [incubator-mxnet] Zha0q1 commented on issue #15490: Utility to help developers debug operators: Tensor Inspector

2019-07-12 Thread GitBox
Zha0q1 commented on issue #15490: Utility to help developers debug operators: 
Tensor Inspector
URL: https://github.com/apache/incubator-mxnet/pull/15490#issuecomment-511013592
 
 
   > Nice work, just a few comments, looks good.
   
   Thank you for the detailed advices!


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [incubator-mxnet] Zha0q1 commented on a change in pull request #15490: Utility to help developers debug operators: Tensor Inspector

2019-07-12 Thread GitBox
Zha0q1 commented on a change in pull request #15490: Utility to help developers 
debug operators: Tensor Inspector
URL: https://github.com/apache/incubator-mxnet/pull/15490#discussion_r303129096
 
 

 ##
 File path: src/common/tensor_inspector.h
 ##
 @@ -0,0 +1,733 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/*!
+ * Copyright (c) 2019 by Contributors
+ * \file tensor_inspector.h
+ * \brief utility to inspect tensor objects
+ * \author Zhaoqi Zhu
+ */
+
+#ifndef MXNET_COMMON_TENSOR_INSPECTOR_H_
+#define MXNET_COMMON_TENSOR_INSPECTOR_H_
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "../../3rdparty/mshadow/mshadow/base.h"
+#include "../../tests/cpp/include/test_util.h"
+
+namespace mxnet {
+
+/*!
+ * \brief this singleton struct mediates individual TensorInspector objects
+ * so that we can control the global behavior from each of them
+ */
+struct InspectorManager {
+  static InspectorManager* get() {
+static std::mutex mtx;
+static std::unique_ptr im = nullptr;
+if (!im) {
+  std::unique_lock lk(mtx);
+  if (!im)
+im = std::make_unique();
+}
+return im.get();
+  }
+  /* !\brief mutex used to lock interactive_print() and check_value() */
+  std::mutex mutex_;
+  /* !\brief skip all interactive prints */
+  bool interactive_print_skip_all_ = false;
+  /* !\brief skip all value checks */
+  bool check_value_skip_all_ = false;
+  /* !\brief visit count for interactive print tags */
+  std::unordered_map interactive_print_tag_counter_;
+  /* !\brief visit count for check value tags */
+  std::unordered_map check_value_tag_counter_;
+  /* !\brief visit count for dump value tags */
+  std::unordered_map dump_value_tag_counter_;
+};
+
+/*!
+ * \brief Enum for building value checkers for TensorInspector::check_value()
+ */
+enum CheckerType {
+  NegativeChecker,  // check if is negative
+  PositiveChecker,  // check if is positive
+  ZeroChecker,  // check if is zero
+  NaNChecker,  // check if is NaN, will always return false if DType is not a 
float type
+  InfChecker,  // check if is infinity, will always return false if DType is 
not a float type
+  PositiveInfChecker,  // check if is positive infinity,
+   // will always return false if DType is not a float type
+  NegativeInfChecker,  // check if is nagative infinity,
+   // will always return false if DType is not a float type
+  FiniteChecker,  // check if is finite, will always return false if DType is 
not a float type
+  NormalChecker,  // check if is neither infinity nor NaN
+  AbnormalChecker,  // chekck if is infinity or nan
+};
+
+/**
+ *  ___  _   _ 
+ * |__   __||_   _| | |
+ *| | ___ _ __  ___  ___  _ __| |  _ __  ___ _ __   ___  ___| |_ ___  _ __ 
+ *| |/ _ \ '_ \/ __|/ _ \| '__| | | '_ \/ __| '_ \ / _ \/ __| __/ _ \| '__|
+ *| |  __/ | | \__ \ (_) | | _| |_| | | \__ \ |_) |  __/ (__| || (_) | |   
+ *|_|\___|_| |_|___/\___/|_||_|_| |_|___/ .__/ \___|\___|\__\___/|_|   
+ *  | |
+ *  |_|   
+ */
+
+/*!
+ * \brief This class provides a unified interface to inspect the value of all 
data types
+ * including Tensor, TBlob, and NDArray. If the tensor resides on GPU, then it 
will be
+ * copied from GPU memory back to CPU memory to be operated on. Internally, 
all data types
+ * are stored as a TBlob object tb_.
+ */
+class TensorInspector {
+ private:
+  /*!
+   * \brief generate the tensor info, including data type and shape 
+   * \tparam DType the data type
+   * \tparam StreamType the type of the stream object
+   * \param os stream object to output to
+   */
+  template
+  inline void tensor_info_to_string(StreamType* os) {
+int dimension = tb_.ndim();
+*os << "<" << typeid(tb_.dptr()[0]).name() << " Tensor ";
+*os << tb_.shape_[0];
+for (int i = 1; i < dimension; ++i) {
+  *os << 'x' << tb_.shape_[i];
+}
+*os << ">" << std::endl;
+  }
+
+  /*!
+   * \brief output the tensor info, inc

  1   2   >