From 48f926f202e960fd946c4c02dbe74643c0ebd0b7 Mon Sep 17 00:00:00 2001 From: Chaitanya Prakash Bapat Date: Sat, 23 Feb 2019 17:41:48 -0500 Subject: [PATCH 01/13] fix commands to make doc consistent --- src/operator/nn/concat.cc | 34 ++++---- src/operator/swapaxis.cc | 30 +++++--- src/operator/tensor/control_flow_op.cc | 23 +++--- .../tensor/elemwise_unary_op_basic.cc | 77 +++++++++++++++---- src/operator/tensor/init_op.cc | 14 ++-- src/operator/tensor/ravel.cc | 7 +- 6 files changed, 126 insertions(+), 59 deletions(-) diff --git a/src/operator/nn/concat.cc b/src/operator/nn/concat.cc index 711fe9c49fa4..cf16976ac654 100644 --- a/src/operator/nn/concat.cc +++ b/src/operator/nn/concat.cc @@ -345,25 +345,29 @@ The storage type of ``concat`` output depends on storage types of inputs Example:: - x = [[1,1],[2,2]] - y = [[3,3],[4,4],[5,5]] - z = [[6,6], [7,7],[8,8]] - - concat(x,y,z,dim=0) = [[ 1., 1.], - [ 2., 2.], - [ 3., 3.], - [ 4., 4.], - [ 5., 5.], - [ 6., 6.], - [ 7., 7.], - [ 8., 8.]] + >>> x = mx.nd.array([[1,1],[2,2]]) + >>> y = mx.nd.array([[3,3],[4,4],[5,5]]) + >>> z = mx.nd.array([[6,6], [7,7],[8,8]]) + + >>> mx.nd.concat(x,y,z,dim=0) + [[1. 1.] + [2. 2.] + [3. 3.] + [4. 4.] + [5. 5.] + [6. 6.] + [7. 7.] + [8. 8.]] + Note that you cannot concat x,y,z along dimension 1 since dimension 0 is not the same for all the input arrays. - concat(y,z,dim=1) = [[ 3., 3., 6., 6.], - [ 4., 4., 7., 7.], - [ 5., 5., 8., 8.]] + >>> mx.nd.concat(y,z,dim=1) + [[3. 3. 6. 6.] + [4. 4. 7. 7.] + [5. 5. 8. 8.]] + )code" ADD_FILELINE) #if MXNET_USE_MKLDNN == 1 diff --git a/src/operator/swapaxis.cc b/src/operator/swapaxis.cc index b78062fde8be..1348c5ed6e52 100644 --- a/src/operator/swapaxis.cc +++ b/src/operator/swapaxis.cc @@ -53,20 +53,26 @@ MXNET_REGISTER_OP_PROPERTY(SwapAxis, SwapAxisProp) Examples:: - x = [[1, 2, 3]]) - swapaxes(x, 0, 1) = [[ 1], - [ 2], - [ 3]] + >>> x = mx.nd.array([[1, 2, 3]]) //(1,3) array + >>> mx.nd.swapaxes(x, 0, 1) + [[1.] + [2.] + [3.]] - x = [[[ 0, 1], - [ 2, 3]], - [[ 4, 5], - [ 6, 7]]] // (2,2,2) array + >>> x = mx.nd.array([[[ 0, 1],[ 2, 3]],[[ 4, 5],[ 6, 7]]]) // (2,2,2) array + >>> x + [[[0. 1.] + [2. 3.]] + [[4. 5.] + [6. 7.]]] + + >>> mx.nd.swapaxes(x, 0, 2) + [[[0. 4.] + [2. 6.]] + [[1. 5.] + [3. 7.]]] + - swapaxes(x, 0, 2) = [[[ 0, 4], - [ 2, 6]], - [[ 1, 5], - [ 3, 7]]] )code" ADD_FILELINE); NNVM_REGISTER_OP(SwapAxis).add_alias("swapaxes"); diff --git a/src/operator/tensor/control_flow_op.cc b/src/operator/tensor/control_flow_op.cc index 164fd6a66ac7..1c33a53e72ce 100644 --- a/src/operator/tensor/control_flow_op.cc +++ b/src/operator/tensor/control_flow_op.cc @@ -44,15 +44,20 @@ Note that all non-zero values are interpreted as ``True`` in condition. Examples:: - x = [[1, 2], [3, 4]] - y = [[5, 6], [7, 8]] - cond = [[0, 1], [-1, 0]] - - where(cond, x, y) = [[5, 2], [3, 8]] - - csr_cond = cast_storage(cond, 'csr') - - where(csr_cond, x, y) = [[5, 2], [3, 8]] + >>> x = mx.nd.array([[1, 2], [3, 4]]) + >>> y = mx.nd.array([[5, 6], [7, 8]]) + + >>> cond = mx.nd.array([[0, 1], [-1, 0]]) + >>> mx.nd.where(cond, x, y) + [[5. 2.] + [3. 8.]] + + + >>> csr_cond = mx.nd.sparse.cast_storage(cond, 'csr') + >>> mx.nd.sparse.where(csr_cond, x, y) + [[5. 2.] + [3. 8.]] + )code" ADD_FILELINE) .set_num_inputs(3) diff --git a/src/operator/tensor/elemwise_unary_op_basic.cc b/src/operator/tensor/elemwise_unary_op_basic.cc index d0079b545dd8..94576e67ec6d 100644 --- a/src/operator/tensor/elemwise_unary_op_basic.cc +++ b/src/operator/tensor/elemwise_unary_op_basic.cc @@ -447,9 +447,13 @@ Returns a **view** of the `lhs` array with a new shape without altering any data Example:: - x = [1, 2, 3, 4, 5, 6] - y = [[0, -4], [3, 2], [2, 2]] - reshape_like(x, y) = [[1, 2], [3, 4], [5, 6]] + >>> x = mx.nd.array([1, 2, 3, 4, 5, 6]) + >>> y = mx.nd.array([[0, -4], [3, 2], [2, 2]]) + >>> mx.nd.reshape_like(x, y) + [[1. 2.] + [3. 4.] + [5. 6.]] + More precise control over how dimensions are inherited is achieved by specifying \ slices over the `lhs` and `rhs` array dimensions. Only the sliced `lhs` dimensions \ @@ -515,7 +519,10 @@ NNVM_REGISTER_OP(shape_array) Example:: - shape_array([[1,2,3,4], [5,6,7,8]]) = [2,4] + >>> x = mx.nd.array([[1,2,3,4], [5,6,7,8]]) + >>> mx.nd.shape_array(x) + [2 4] + )code" ADD_FILELINE) .set_num_inputs(1) @@ -567,7 +574,10 @@ NNVM_REGISTER_OP(size_array) Example:: - size_array([[1,2,3,4], [5,6,7,8]]) = [8] + >>> x = mx.nd.array([[1,2,3,4], [5,6,7,8]]) + >>> mx.nd.size_array(x) + [8] + )code" ADD_FILELINE) .set_num_inputs(1) @@ -603,9 +613,20 @@ NNVM_REGISTER_OP(Cast) Example:: - cast([0.9, 1.3], dtype='int32') = [0, 1] - cast([1e20, 11.1], dtype='float16') = [inf, 11.09375] - cast([300, 11.1, 10.9, -1, -3], dtype='uint8') = [44, 11, 10, 255, 253] + >>> x = mx.nd.array([0.9, 1.3]) + >>> mx.nd.cast(x, dtype='int32') + [0 1] + + + >>> x = mx.nd.array([1e20, 11.1]) + >>> mx.nd.cast(x, dtype='float16') + [ inf 11.1] + + + >>> x = mx.nd.array([300, 11.1, 10.9, -1, -3]) + >>> mx.nd.cast(x, dtype='uint8') + [ 44 11 10 255 253] + )code" ADD_FILELINE) .set_attr_parser(ParamParser) @@ -649,7 +670,10 @@ Calculates 1/x. Example:: - reciprocal([-2, 1, 3, 1.6, 0.2]) = [-0.5, 1.0, 0.33333334, 0.625, 5.0] + >>> x = mx.nd.array([-2, 1, 3, 1.6, 0.2]) + >>> mx.nd.reciprocal(x) + [-0.5 1. 0.33333334 0.625 5. ] + )code" ADD_FILELINE) .set_attr("FCompute", UnaryOp::Compute) @@ -665,7 +689,10 @@ MXNET_OPERATOR_REGISTER_UNARY_WITH_RSP_CSR(abs, cpu, mshadow_op::abs) Example:: - abs([-2, 0, 3]) = [2, 0, 3] + >>> x = mx.nd.array([-2, 0, 3]) + >>> mx.nd.abs(x) + [2. 0. 3.] + The storage type of ``abs`` output depends upon the input storage type: @@ -684,7 +711,10 @@ MXNET_OPERATOR_REGISTER_UNARY_WITH_RSP_CSR(sign, cpu, mshadow_op::sign) Example:: - sign([-2, 0, 3]) = [-1, 0, 1] + >>> x = mx.nd.array([-2, 0, 3]) + >>> mx.nd.sign(x) + [-1. 0. 1.] + The storage type of ``sign`` output depends upon the input storage type: @@ -703,7 +733,10 @@ MXNET_OPERATOR_REGISTER_UNARY_WITH_RSP_CSR(round, cpu, mshadow_op::round) Example:: - round([-1.5, 1.5, -1.9, 1.9, 2.1]) = [-2., 2., -2., 2., 2.] + >>> x = mx.nd.array([-2.1, -1.9, 1.5, 1.9, 2.1]) + >>> mx.nd.round(x) + [-2. -2. 2. 2. 2.] + The storage type of ``round`` output depends upon the input storage type: @@ -724,7 +757,10 @@ MXNET_OPERATOR_REGISTER_UNARY_WITH_RSP_CSR(rint, cpu, mshadow_op::rint) Example:: - rint([-1.5, 1.5, -1.9, 1.9, 2.1]) = [-2., 1., -2., 2., 2.] + >>> x = mx.nd.array([-2.1, -1.9, 1.5, 1.9, 2.1]) + >>> mx.nd.rint(x) + [-2. -2. 1. 2. 2.] + The storage type of ``rint`` output depends upon the input storage type: @@ -743,7 +779,10 @@ The ceil of the scalar x is the smallest integer i, such that i >= x. Example:: - ceil([-2.1, -1.9, 1.5, 1.9, 2.1]) = [-2., -1., 2., 2., 3.] + >>> x = mx.nd.array([-2.1, -1.9, 1.5, 1.9, 2.1]) + >>> mx.nd.ceil(x) + [-2. -1. 2. 2. 3.] + The storage type of ``ceil`` output depends upon the input storage type: @@ -762,7 +801,10 @@ The floor of the scalar x is the largest integer i, such that i <= x. Example:: - floor([-2.1, -1.9, 1.5, 1.9, 2.1]) = [-3., -2., 1., 1., 2.] + >>> x = mx.nd.array([-2.1, -1.9, 1.5, 1.9, 2.1]) + >>> mx.nd.floor(x) + [-3. -2. 1. 1. 2.] + The storage type of ``floor`` output depends upon the input storage type: @@ -782,7 +824,10 @@ zero than x is. In short, the fractional part of the signed number x is discarde Example:: - trunc([-2.1, -1.9, 1.5, 1.9, 2.1]) = [-2., -1., 1., 1., 2.] + >>> x = mx.nd.array([-2.1, -1.9, 1.5, 1.9, 2.1]) + >>> mx.nd.trunc(x) + [-2. -1. 1. 1. 2.] + The storage type of ``trunc`` output depends upon the input storage type: diff --git a/src/operator/tensor/init_op.cc b/src/operator/tensor/init_op.cc index 8554ba854178..a1d43eac3ec0 100644 --- a/src/operator/tensor/init_op.cc +++ b/src/operator/tensor/init_op.cc @@ -112,11 +112,15 @@ The storage type of ``zeros_like`` output depends on the storage type of the inp Examples:: - x = [[ 1., 1., 1.], - [ 1., 1., 1.]] - - zeros_like(x) = [[ 0., 0., 0.], - [ 0., 0., 0.]] + >>> x = mx.nd.array([[ 1., 1., 1.],[ 1., 1., 1.]]) + >>> x + [[1. 1. 1.] + [1. 1. 1.]] + + >>> mx.nd.zeros_like(x) + [[0. 0. 0.] + [0. 0. 0.]] + )code") .set_num_inputs(1) diff --git a/src/operator/tensor/ravel.cc b/src/operator/tensor/ravel.cc index 7bbfac5d58c0..8c32614ba4c8 100644 --- a/src/operator/tensor/ravel.cc +++ b/src/operator/tensor/ravel.cc @@ -59,8 +59,11 @@ NNVM_REGISTER_OP(_unravel_index) Examples:: - A = [22,41,37] - unravel(A, shape=(7,6)) = [[3,6,6],[4,5,1]] + >>> a = mx.nd.array([22,41,37]) + >>> mx.nd.unravel_index(a, shape=(7,6)) + [[3. 6. 6.] + [4. 5. 1.]] + )code" ADD_FILELINE) .set_num_inputs(1) From f54b3211f5dc7112767d7b89959c34e18cd0bbc3 Mon Sep 17 00:00:00 2001 From: Chaitanya Prakash Bapat Date: Tue, 9 Apr 2019 01:59:46 -0400 Subject: [PATCH 02/13] Revert "fix commands to make doc consistent" This reverts commit 48f926f202e960fd946c4c02dbe74643c0ebd0b7. --- src/operator/nn/concat.cc | 34 ++++---- src/operator/swapaxis.cc | 30 +++----- src/operator/tensor/control_flow_op.cc | 23 +++--- .../tensor/elemwise_unary_op_basic.cc | 77 ++++--------------- src/operator/tensor/init_op.cc | 14 ++-- src/operator/tensor/ravel.cc | 7 +- 6 files changed, 59 insertions(+), 126 deletions(-) diff --git a/src/operator/nn/concat.cc b/src/operator/nn/concat.cc index cf16976ac654..711fe9c49fa4 100644 --- a/src/operator/nn/concat.cc +++ b/src/operator/nn/concat.cc @@ -345,29 +345,25 @@ The storage type of ``concat`` output depends on storage types of inputs Example:: - >>> x = mx.nd.array([[1,1],[2,2]]) - >>> y = mx.nd.array([[3,3],[4,4],[5,5]]) - >>> z = mx.nd.array([[6,6], [7,7],[8,8]]) - - >>> mx.nd.concat(x,y,z,dim=0) - [[1. 1.] - [2. 2.] - [3. 3.] - [4. 4.] - [5. 5.] - [6. 6.] - [7. 7.] - [8. 8.]] - + x = [[1,1],[2,2]] + y = [[3,3],[4,4],[5,5]] + z = [[6,6], [7,7],[8,8]] + + concat(x,y,z,dim=0) = [[ 1., 1.], + [ 2., 2.], + [ 3., 3.], + [ 4., 4.], + [ 5., 5.], + [ 6., 6.], + [ 7., 7.], + [ 8., 8.]] Note that you cannot concat x,y,z along dimension 1 since dimension 0 is not the same for all the input arrays. - >>> mx.nd.concat(y,z,dim=1) - [[3. 3. 6. 6.] - [4. 4. 7. 7.] - [5. 5. 8. 8.]] - + concat(y,z,dim=1) = [[ 3., 3., 6., 6.], + [ 4., 4., 7., 7.], + [ 5., 5., 8., 8.]] )code" ADD_FILELINE) #if MXNET_USE_MKLDNN == 1 diff --git a/src/operator/swapaxis.cc b/src/operator/swapaxis.cc index 1348c5ed6e52..b78062fde8be 100644 --- a/src/operator/swapaxis.cc +++ b/src/operator/swapaxis.cc @@ -53,26 +53,20 @@ MXNET_REGISTER_OP_PROPERTY(SwapAxis, SwapAxisProp) Examples:: - >>> x = mx.nd.array([[1, 2, 3]]) //(1,3) array - >>> mx.nd.swapaxes(x, 0, 1) - [[1.] - [2.] - [3.]] + x = [[1, 2, 3]]) + swapaxes(x, 0, 1) = [[ 1], + [ 2], + [ 3]] - >>> x = mx.nd.array([[[ 0, 1],[ 2, 3]],[[ 4, 5],[ 6, 7]]]) // (2,2,2) array - >>> x - [[[0. 1.] - [2. 3.]] - [[4. 5.] - [6. 7.]]] - - >>> mx.nd.swapaxes(x, 0, 2) - [[[0. 4.] - [2. 6.]] - [[1. 5.] - [3. 7.]]] - + x = [[[ 0, 1], + [ 2, 3]], + [[ 4, 5], + [ 6, 7]]] // (2,2,2) array + swapaxes(x, 0, 2) = [[[ 0, 4], + [ 2, 6]], + [[ 1, 5], + [ 3, 7]]] )code" ADD_FILELINE); NNVM_REGISTER_OP(SwapAxis).add_alias("swapaxes"); diff --git a/src/operator/tensor/control_flow_op.cc b/src/operator/tensor/control_flow_op.cc index 1c33a53e72ce..164fd6a66ac7 100644 --- a/src/operator/tensor/control_flow_op.cc +++ b/src/operator/tensor/control_flow_op.cc @@ -44,20 +44,15 @@ Note that all non-zero values are interpreted as ``True`` in condition. Examples:: - >>> x = mx.nd.array([[1, 2], [3, 4]]) - >>> y = mx.nd.array([[5, 6], [7, 8]]) - - >>> cond = mx.nd.array([[0, 1], [-1, 0]]) - >>> mx.nd.where(cond, x, y) - [[5. 2.] - [3. 8.]] - - - >>> csr_cond = mx.nd.sparse.cast_storage(cond, 'csr') - >>> mx.nd.sparse.where(csr_cond, x, y) - [[5. 2.] - [3. 8.]] - + x = [[1, 2], [3, 4]] + y = [[5, 6], [7, 8]] + cond = [[0, 1], [-1, 0]] + + where(cond, x, y) = [[5, 2], [3, 8]] + + csr_cond = cast_storage(cond, 'csr') + + where(csr_cond, x, y) = [[5, 2], [3, 8]] )code" ADD_FILELINE) .set_num_inputs(3) diff --git a/src/operator/tensor/elemwise_unary_op_basic.cc b/src/operator/tensor/elemwise_unary_op_basic.cc index 94576e67ec6d..d0079b545dd8 100644 --- a/src/operator/tensor/elemwise_unary_op_basic.cc +++ b/src/operator/tensor/elemwise_unary_op_basic.cc @@ -447,13 +447,9 @@ Returns a **view** of the `lhs` array with a new shape without altering any data Example:: - >>> x = mx.nd.array([1, 2, 3, 4, 5, 6]) - >>> y = mx.nd.array([[0, -4], [3, 2], [2, 2]]) - >>> mx.nd.reshape_like(x, y) - [[1. 2.] - [3. 4.] - [5. 6.]] - + x = [1, 2, 3, 4, 5, 6] + y = [[0, -4], [3, 2], [2, 2]] + reshape_like(x, y) = [[1, 2], [3, 4], [5, 6]] More precise control over how dimensions are inherited is achieved by specifying \ slices over the `lhs` and `rhs` array dimensions. Only the sliced `lhs` dimensions \ @@ -519,10 +515,7 @@ NNVM_REGISTER_OP(shape_array) Example:: - >>> x = mx.nd.array([[1,2,3,4], [5,6,7,8]]) - >>> mx.nd.shape_array(x) - [2 4] - + shape_array([[1,2,3,4], [5,6,7,8]]) = [2,4] )code" ADD_FILELINE) .set_num_inputs(1) @@ -574,10 +567,7 @@ NNVM_REGISTER_OP(size_array) Example:: - >>> x = mx.nd.array([[1,2,3,4], [5,6,7,8]]) - >>> mx.nd.size_array(x) - [8] - + size_array([[1,2,3,4], [5,6,7,8]]) = [8] )code" ADD_FILELINE) .set_num_inputs(1) @@ -613,20 +603,9 @@ NNVM_REGISTER_OP(Cast) Example:: - >>> x = mx.nd.array([0.9, 1.3]) - >>> mx.nd.cast(x, dtype='int32') - [0 1] - - - >>> x = mx.nd.array([1e20, 11.1]) - >>> mx.nd.cast(x, dtype='float16') - [ inf 11.1] - - - >>> x = mx.nd.array([300, 11.1, 10.9, -1, -3]) - >>> mx.nd.cast(x, dtype='uint8') - [ 44 11 10 255 253] - + cast([0.9, 1.3], dtype='int32') = [0, 1] + cast([1e20, 11.1], dtype='float16') = [inf, 11.09375] + cast([300, 11.1, 10.9, -1, -3], dtype='uint8') = [44, 11, 10, 255, 253] )code" ADD_FILELINE) .set_attr_parser(ParamParser) @@ -670,10 +649,7 @@ Calculates 1/x. Example:: - >>> x = mx.nd.array([-2, 1, 3, 1.6, 0.2]) - >>> mx.nd.reciprocal(x) - [-0.5 1. 0.33333334 0.625 5. ] - + reciprocal([-2, 1, 3, 1.6, 0.2]) = [-0.5, 1.0, 0.33333334, 0.625, 5.0] )code" ADD_FILELINE) .set_attr("FCompute", UnaryOp::Compute) @@ -689,10 +665,7 @@ MXNET_OPERATOR_REGISTER_UNARY_WITH_RSP_CSR(abs, cpu, mshadow_op::abs) Example:: - >>> x = mx.nd.array([-2, 0, 3]) - >>> mx.nd.abs(x) - [2. 0. 3.] - + abs([-2, 0, 3]) = [2, 0, 3] The storage type of ``abs`` output depends upon the input storage type: @@ -711,10 +684,7 @@ MXNET_OPERATOR_REGISTER_UNARY_WITH_RSP_CSR(sign, cpu, mshadow_op::sign) Example:: - >>> x = mx.nd.array([-2, 0, 3]) - >>> mx.nd.sign(x) - [-1. 0. 1.] - + sign([-2, 0, 3]) = [-1, 0, 1] The storage type of ``sign`` output depends upon the input storage type: @@ -733,10 +703,7 @@ MXNET_OPERATOR_REGISTER_UNARY_WITH_RSP_CSR(round, cpu, mshadow_op::round) Example:: - >>> x = mx.nd.array([-2.1, -1.9, 1.5, 1.9, 2.1]) - >>> mx.nd.round(x) - [-2. -2. 2. 2. 2.] - + round([-1.5, 1.5, -1.9, 1.9, 2.1]) = [-2., 2., -2., 2., 2.] The storage type of ``round`` output depends upon the input storage type: @@ -757,10 +724,7 @@ MXNET_OPERATOR_REGISTER_UNARY_WITH_RSP_CSR(rint, cpu, mshadow_op::rint) Example:: - >>> x = mx.nd.array([-2.1, -1.9, 1.5, 1.9, 2.1]) - >>> mx.nd.rint(x) - [-2. -2. 1. 2. 2.] - + rint([-1.5, 1.5, -1.9, 1.9, 2.1]) = [-2., 1., -2., 2., 2.] The storage type of ``rint`` output depends upon the input storage type: @@ -779,10 +743,7 @@ The ceil of the scalar x is the smallest integer i, such that i >= x. Example:: - >>> x = mx.nd.array([-2.1, -1.9, 1.5, 1.9, 2.1]) - >>> mx.nd.ceil(x) - [-2. -1. 2. 2. 3.] - + ceil([-2.1, -1.9, 1.5, 1.9, 2.1]) = [-2., -1., 2., 2., 3.] The storage type of ``ceil`` output depends upon the input storage type: @@ -801,10 +762,7 @@ The floor of the scalar x is the largest integer i, such that i <= x. Example:: - >>> x = mx.nd.array([-2.1, -1.9, 1.5, 1.9, 2.1]) - >>> mx.nd.floor(x) - [-3. -2. 1. 1. 2.] - + floor([-2.1, -1.9, 1.5, 1.9, 2.1]) = [-3., -2., 1., 1., 2.] The storage type of ``floor`` output depends upon the input storage type: @@ -824,10 +782,7 @@ zero than x is. In short, the fractional part of the signed number x is discarde Example:: - >>> x = mx.nd.array([-2.1, -1.9, 1.5, 1.9, 2.1]) - >>> mx.nd.trunc(x) - [-2. -1. 1. 1. 2.] - + trunc([-2.1, -1.9, 1.5, 1.9, 2.1]) = [-2., -1., 1., 1., 2.] The storage type of ``trunc`` output depends upon the input storage type: diff --git a/src/operator/tensor/init_op.cc b/src/operator/tensor/init_op.cc index a1d43eac3ec0..8554ba854178 100644 --- a/src/operator/tensor/init_op.cc +++ b/src/operator/tensor/init_op.cc @@ -112,15 +112,11 @@ The storage type of ``zeros_like`` output depends on the storage type of the inp Examples:: - >>> x = mx.nd.array([[ 1., 1., 1.],[ 1., 1., 1.]]) - >>> x - [[1. 1. 1.] - [1. 1. 1.]] - - >>> mx.nd.zeros_like(x) - [[0. 0. 0.] - [0. 0. 0.]] - + x = [[ 1., 1., 1.], + [ 1., 1., 1.]] + + zeros_like(x) = [[ 0., 0., 0.], + [ 0., 0., 0.]] )code") .set_num_inputs(1) diff --git a/src/operator/tensor/ravel.cc b/src/operator/tensor/ravel.cc index 8c32614ba4c8..7bbfac5d58c0 100644 --- a/src/operator/tensor/ravel.cc +++ b/src/operator/tensor/ravel.cc @@ -59,11 +59,8 @@ NNVM_REGISTER_OP(_unravel_index) Examples:: - >>> a = mx.nd.array([22,41,37]) - >>> mx.nd.unravel_index(a, shape=(7,6)) - [[3. 6. 6.] - [4. 5. 1.]] - + A = [22,41,37] + unravel(A, shape=(7,6)) = [[3,6,6],[4,5,1]] )code" ADD_FILELINE) .set_num_inputs(1) From 3d33bc62c4f54aee6f260ea75e01f665a65611d6 Mon Sep 17 00:00:00 2001 From: Chaitanya Prakash Bapat Date: Wed, 10 Apr 2019 05:15:14 -0400 Subject: [PATCH 03/13] updated python doc --- python/mxnet/ndarray_doc.py | 261 ++++++++++++++++++++++++++++++++++++ 1 file changed, 261 insertions(+) diff --git a/python/mxnet/ndarray_doc.py b/python/mxnet/ndarray_doc.py index 9d6258a89a3d..b1b971774261 100644 --- a/python/mxnet/ndarray_doc.py +++ b/python/mxnet/ndarray_doc.py @@ -54,6 +54,267 @@ class ReshapeDoc(NDArrayDoc): (4L, 3L, 2L) """ +class ConcatDoc(NDArrayDoc): + """ + Examples + -------- + Joins input arrays along a given axis. + >>> x = mx.nd.array([[1,1],[2,2]]) + >>> y = mx.nd.array([[3,3],[4,4],[5,5]]) + >>> z = mx.nd.array([[6,6], [7,7],[8,8]]) + + >>> mx.nd.concat(x,y,z,dim=0) + [[1. 1.] + [2. 2.] + [3. 3.] + [4. 4.] + [5. 5.] + [6. 6.] + [7. 7.] + [8. 8.]] + + + >>> mx.nd.concat(y,z,dim=1) + [[3. 3. 6. 6.] + [4. 4. 7. 7.] + [5. 5. 8. 8.]] + + """ + +class SwapAxisDoc(NDArrayDoc): + """ + Examples + -------- + Interchanges two axes of an array. + >>> x = mx.nd.array([[1, 2, 3]]) + >>> mx.nd.swapaxes(x, 0, 1) + [[1.] + [2.] + [3.]] + + >>> x = mx.nd.array([[[ 0, 1],[ 2, 3]],[[ 4, 5],[ 6, 7]]]) + >>> x + [[[0. 1.] + [2. 3.]] + [[4. 5.] + [6. 7.]]] + + >>> mx.nd.swapaxes(x, 0, 2) + [[[0. 4.] + [2. 6.]] + [[1. 5.] + [3. 7.]]] + + """ + +class whereDoc(NDArrayDoc): + """ + Examples + -------- + Return the elements, either from x or y, depending on the condition. + >>> x = mx.nd.array([[1, 2], [3, 4]]) + >>> y = mx.nd.array([[5, 6], [7, 8]]) + + >>> cond = mx.nd.array([[0, 1], [-1, 0]]) + >>> mx.nd.where(cond, x, y) + [[5. 2.] + [3. 8.]] + + + >>> csr_cond = mx.nd.sparse.cast_storage(cond, 'csr') + >>> mx.nd.sparse.where(csr_cond, x, y) + [[5. 2.] + [3. 8.]] + + """ + +class ReshapeLikeDoc(NDArrayDoc): + """ + Reshape some or all dimensions of `lhs` to have the same shape as some or all dimensions of `rhs`. + Example + ------- + + >>> x = mx.nd.array([1, 2, 3, 4, 5, 6]) + >>> y = mx.nd.array([[0, -4], [3, 2], [2, 2]]) + >>> mx.nd.reshape_like(x, y) + [[1. 2.] + [3. 4.] + [5. 6.]] + + """ + +class shape_arrayDoc(NDArrayDoc): + """ + Returns a 1D int64 array containing the shape of data. + Example + ------- + + >>> x = mx.nd.array([[1,2,3,4], [5,6,7,8]]) + >>> mx.nd.shape_array(x) + [2 4] + + """ + +class size_arrayDoc(NDArrayDoc): + """ + Returns a 1D int64 array containing the size of data. + Example + ------- + + >>> x = mx.nd.array([[1,2,3,4], [5,6,7,8]]) + >>> mx.nd.size_array(x) + [8] + + """ + +class CastDoc(NDArrayDoc): + """ + Casts all elements of the input to a new type. + Example + ------- + + >>> x = mx.nd.array([0.9, 1.3]) + >>> mx.nd.cast(x, dtype='int32') + [0 1] + + + >>> x = mx.nd.array([1e20, 11.1]) + >>> mx.nd.cast(x, dtype='float16') + [ inf 11.1] + + + >>> x = mx.nd.array([300, 11.1, 10.9, -1, -3]) + >>> mx.nd.cast(x, dtype='uint8') + [ 44 11 10 255 253] + + """ + +class reciprocalDoc(NDArrayDoc): + """ + Returns the reciprocal of the argument, element-wise. + Example + ------- + + >>> x = mx.nd.array([-2, 1, 3, 1.6, 0.2]) + >>> mx.nd.reciprocal(x) + [-0.5 1. 0.33333334 0.625 5. ] + + """ + +class absDoc(NDArrayDoc): + """ + Returns element-wise absolute value of the input. + Example + ------- + + >>> x = mx.nd.array([-2, 0, 3]) + >>> mx.nd.abs(x) + [2. 0. 3.] + + """ + +class signDoc(NDArrayDoc): + """ + Returns element-wise sign of the input. + Example + ------- + + >>> x = mx.nd.array([-2, 0, 3]) + >>> mx.nd.sign(x) + [-1. 0. 1.] + + """ + +class roundDoc(NDArrayDoc): + """ + Returns element-wise rounded value to the nearest integer of the input. + Example + ------- + + >>> x = mx.nd.array([-2.1, -1.9, 1.5, 1.9, 2.1]) + >>> mx.nd.round(x) + [-2. -2. 2. 2. 2.] + + """ + +class rintDoc(NDArrayDoc): + """ + Returns element-wise rounded value to the nearest integer of the input. + Example + ------- + + >>> x = mx.nd.array([-2.1, -1.9, 1.5, 1.9, 2.1]) + >>> mx.nd.rint(x) + [-2. -2. 1. 2. 2.] + + """ + +class ceilDoc(NDArrayDoc): + """ + Returns element-wise ceiling of the input. + Example + ------- + + >>> x = mx.nd.array([-2.1, -1.9, 1.5, 1.9, 2.1]) + >>> mx.nd.ceil(x) + [-2. -1. 2. 2. 3.] + + """ + +class floorDoc(NDArrayDoc): + """ + Returns element-wise floor of the input. + Example + ------- + + >>> x = mx.nd.array([-2.1, -1.9, 1.5, 1.9, 2.1]) + >>> mx.nd.floor(x) + [-3. -2. 1. 1. 2.] + + """ + +class truncDoc(NDArrayDoc): + """ + Return the element-wise truncated value of the input. + Example + ------- + + >>> x = mx.nd.array([-2.1, -1.9, 1.5, 1.9, 2.1]) + >>> mx.nd.trunc(x) + [-2. -1. 1. 1. 2.] + + """ + +class zeros_likeDoc(NDArrayDoc): + """ + Return an array of zeros with the same shape, type and storage type + Example + ------- + + >>> x = mx.nd.array([[ 1., 1., 1.],[ 1., 1., 1.]]) + >>> x + [[1. 1. 1.] + [1. 1. 1.]] + + >>> mx.nd.zeros_like(x) + [[0. 0. 0.] + [0. 0. 0.]] + + """ + +class unravel_indexDoc(NDArrayDoc): + """ + Converts an array of flat indices into a batch of index arrays. The operator follows numpy conventions so a single multi index is given by a column of the output matrix. + Example + ------- + + >>> a = mx.nd.array([22,41,37]) + >>> mx.nd.unravel_index(a, shape=(7,6)) + [[3. 6. 6.] + [4. 5. 1.]] + + """ + class elemwise_addDoc(NDArrayDoc): """ Example From 4dced8cfe26d02d467e35771a34581df284dc0a7 Mon Sep 17 00:00:00 2001 From: Chaitanya Prakash Bapat Date: Wed, 10 Apr 2019 14:25:00 -0400 Subject: [PATCH 04/13] line-too-long fix --- python/mxnet/ndarray_doc.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/python/mxnet/ndarray_doc.py b/python/mxnet/ndarray_doc.py index b1b971774261..fe01a1aab317 100644 --- a/python/mxnet/ndarray_doc.py +++ b/python/mxnet/ndarray_doc.py @@ -304,7 +304,8 @@ class zeros_likeDoc(NDArrayDoc): class unravel_indexDoc(NDArrayDoc): """ - Converts an array of flat indices into a batch of index arrays. The operator follows numpy conventions so a single multi index is given by a column of the output matrix. + Converts an array of flat indices into a batch of index arrays. + The operator follows numpy conventions so a single multi index is given by a column of the output matrix. Example ------- From bbcba2b16e167f6de42a15135b6ac753fc38120b Mon Sep 17 00:00:00 2001 From: Chaitanya Prakash Bapat Date: Sat, 13 Apr 2019 02:27:20 -0400 Subject: [PATCH 05/13] add empty line to render --- python/mxnet/ndarray_doc.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/python/mxnet/ndarray_doc.py b/python/mxnet/ndarray_doc.py index fe01a1aab317..9b9912f20ed8 100644 --- a/python/mxnet/ndarray_doc.py +++ b/python/mxnet/ndarray_doc.py @@ -31,6 +31,7 @@ class ReshapeDoc(NDArrayDoc): """ Examples -------- + Reshapes the input array into a new shape. >>> x = mx.nd.array([1, 2, 3, 4]) @@ -58,6 +59,7 @@ class ConcatDoc(NDArrayDoc): """ Examples -------- + Joins input arrays along a given axis. >>> x = mx.nd.array([[1,1],[2,2]]) >>> y = mx.nd.array([[3,3],[4,4],[5,5]]) @@ -85,6 +87,7 @@ class SwapAxisDoc(NDArrayDoc): """ Examples -------- + Interchanges two axes of an array. >>> x = mx.nd.array([[1, 2, 3]]) >>> mx.nd.swapaxes(x, 0, 1) @@ -111,6 +114,7 @@ class whereDoc(NDArrayDoc): """ Examples -------- + Return the elements, either from x or y, depending on the condition. >>> x = mx.nd.array([[1, 2], [3, 4]]) >>> y = mx.nd.array([[5, 6], [7, 8]]) @@ -331,6 +335,7 @@ class BroadcastToDoc(NDArrayDoc): """ Examples -------- + Broadcasts the input array into a new shape. >>> a = mx.nd.array(np.arange(6).reshape(6,1)) >>> b = a.broadcast_to((6,2)) @@ -371,6 +376,7 @@ class StackDoc(NDArrayDoc): """ Example -------- + Join a sequence of arrays along a new axis. >>> x = mx.nd.array([1, 2]) >>> y = mx.nd.array([3, 4]) @@ -386,6 +392,7 @@ class CustomDoc(NDArrayDoc): """ Example ------- + Applies a custom operator named `my_custom_operator` to `input`. >>> output = mx.symbol.Custom(op_type='my_custom_operator', data=input) From d231b8894cabae7bcaa4324b3d4f7150748baae3 Mon Sep 17 00:00:00 2001 From: Chaitanya Prakash Bapat Date: Wed, 17 Apr 2019 02:15:33 -0400 Subject: [PATCH 06/13] rendering issue fix --- python/mxnet/ndarray_doc.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/python/mxnet/ndarray_doc.py b/python/mxnet/ndarray_doc.py index 9b9912f20ed8..d298a73cc861 100644 --- a/python/mxnet/ndarray_doc.py +++ b/python/mxnet/ndarray_doc.py @@ -61,6 +61,7 @@ class ConcatDoc(NDArrayDoc): -------- Joins input arrays along a given axis. + >>> x = mx.nd.array([[1,1],[2,2]]) >>> y = mx.nd.array([[3,3],[4,4],[5,5]]) >>> z = mx.nd.array([[6,6], [7,7],[8,8]]) @@ -89,6 +90,7 @@ class SwapAxisDoc(NDArrayDoc): -------- Interchanges two axes of an array. + >>> x = mx.nd.array([[1, 2, 3]]) >>> mx.nd.swapaxes(x, 0, 1) [[1.] @@ -116,6 +118,7 @@ class whereDoc(NDArrayDoc): -------- Return the elements, either from x or y, depending on the condition. + >>> x = mx.nd.array([[1, 2], [3, 4]]) >>> y = mx.nd.array([[5, 6], [7, 8]]) @@ -337,6 +340,7 @@ class BroadcastToDoc(NDArrayDoc): -------- Broadcasts the input array into a new shape. + >>> a = mx.nd.array(np.arange(6).reshape(6,1)) >>> b = a.broadcast_to((6,2)) >>> a.shape @@ -378,6 +382,7 @@ class StackDoc(NDArrayDoc): -------- Join a sequence of arrays along a new axis. + >>> x = mx.nd.array([1, 2]) >>> y = mx.nd.array([3, 4]) >>> stack(x, y) From 8b50f9602324cb250037ca3526f1777fa4c76fa0 Mon Sep 17 00:00:00 2001 From: Chaitanya Prakash Bapat Date: Thu, 18 Apr 2019 15:49:23 -0400 Subject: [PATCH 07/13] Trigger notification From 975ed0b1d35cb2f47772dc9d4109874525bac74d Mon Sep 17 00:00:00 2001 From: Chaitanya Prakash Bapat Date: Tue, 30 Apr 2019 16:49:53 -0400 Subject: [PATCH 08/13] Concat deprecated hence concatDoc --- python/mxnet/ndarray_doc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/mxnet/ndarray_doc.py b/python/mxnet/ndarray_doc.py index d298a73cc861..43a755d2f994 100644 --- a/python/mxnet/ndarray_doc.py +++ b/python/mxnet/ndarray_doc.py @@ -55,7 +55,7 @@ class ReshapeDoc(NDArrayDoc): (4L, 3L, 2L) """ -class ConcatDoc(NDArrayDoc): +class concatDoc(NDArrayDoc): """ Examples -------- From 1dde088173e412c6ca128ef33f648da9b98d4cab Mon Sep 17 00:00:00 2001 From: Chaitanya Prakash Bapat Date: Thu, 2 May 2019 01:51:13 -0400 Subject: [PATCH 09/13] Trigger notification From 6bab23abe64d14383ebfa80c2eb0abbf4fc8efc4 Mon Sep 17 00:00:00 2001 From: Chaitanya Prakash Bapat Date: Wed, 8 May 2019 14:35:07 -0400 Subject: [PATCH 10/13] Trigger notification From ab412a29a0f7aa909d8065a85ab0dd5ac7e22934 Mon Sep 17 00:00:00 2001 From: ChaiBapchya Date: Fri, 12 Jul 2019 14:36:29 -0700 Subject: [PATCH 11/13] Trigger notification From 83c5488efb64bbca7cea72b98d4a851a95e83a85 Mon Sep 17 00:00:00 2001 From: ChaiBapchya Date: Thu, 18 Jul 2019 11:28:59 -0700 Subject: [PATCH 12/13] Trigger notification From e208c2595bd9d8ba83c8ffd9223e4d86d450fcff Mon Sep 17 00:00:00 2001 From: ChaiBapchya Date: Mon, 29 Jul 2019 15:35:27 -0700 Subject: [PATCH 13/13] Trigger notification