You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2020/03/25 07:02:31 UTC

[GitHub] [incubator-mxnet] BenjaminCHEN2016 opened a new pull request #17904: [Numpy] add: numpy op trilindices

BenjaminCHEN2016 opened a new pull request #17904: [Numpy] add: numpy op trilindices
URL: https://github.com/apache/incubator-mxnet/pull/17904
 
 
   ## Description ##
   (Brief description on what this PR is about)
   
   ## 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 https://mxnet-ci-doc.s3-accelerate.dualstack.amazonaws.com/PR-$PR_ID/$BUILD_ID/index.html
   - [ ] To the best of my 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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] haojin2 commented on a change in pull request #17904: [Numpy] add: numpy op trilindices

Posted by GitBox <gi...@apache.org>.
haojin2 commented on a change in pull request #17904: [Numpy] add: numpy op trilindices
URL: https://github.com/apache/incubator-mxnet/pull/17904#discussion_r400589755
 
 

 ##########
 File path: python/mxnet/numpy/multiarray.py
 ##########
 @@ -5533,6 +5533,87 @@ def tril(m, k=0):
     """
     return _mx_nd_np.tril(m, k)
 
+@set_module('mxnet.numpy')
+def tril_indices(n, k=0, m=None):
+    """
+    Return the indices for the lower-triangle of an (n, m) array.
+
+    Parameters
+    ----------
+    n : int
+        The row dimension of the arrays for which the returned
+        indices will be valid.
+    k : int, optional
+        Diagonal offset (see `tril` for details).
+    m : int, optional
+        .. versionadded:: 1.9.0
+
+        The column dimension of the arrays for which the returned
+        arrays will be valid.
+        By default `m` is taken equal to `n`.
+
+
+    Returns
+    -------
+    inds : tuple of arrays
+        The indices for the triangle. The returned tuple contains two arrays,
+        each with the indices along one dimension of the array.
+
+    See also
+    --------
+    triu_indices : similar function, for upper-triangular.
+    mask_indices : generic function accepting an arbitrary mask function.
+    tril, triu
+
+    Notes
+    -----
+    .. versionadded:: 1.4.0
 
 Review comment:
   no need for `Notes` section

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


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] BenjaminCHEN2016 commented on issue #17904: [Numpy] add: numpy op trilindices

Posted by GitBox <gi...@apache.org>.
BenjaminCHEN2016 commented on issue #17904: [Numpy] add: numpy op trilindices
URL: https://github.com/apache/incubator-mxnet/pull/17904#issuecomment-611355191
 
 
   @mxnet-bot run ci [macosx]

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


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] haojin2 merged pull request #17904: [Numpy] add: numpy op trilindices

Posted by GitBox <gi...@apache.org>.
haojin2 merged pull request #17904: [Numpy] add: numpy op trilindices
URL: https://github.com/apache/incubator-mxnet/pull/17904
 
 
   

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


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] mxnet-bot commented on issue #17904: [Numpy] add: numpy op trilindices

Posted by GitBox <gi...@apache.org>.
mxnet-bot commented on issue #17904: [Numpy] add: numpy op trilindices
URL: https://github.com/apache/incubator-mxnet/pull/17904#issuecomment-604270721
 
 
   Jenkins CI successfully triggered : [centos-gpu, unix-cpu, clang, unix-gpu, windows-cpu, edge, centos-cpu, miscellaneous, website, windows-gpu, sanity]

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


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] BenjaminCHEN2016 commented on issue #17904: [Numpy] add: numpy op trilindices

Posted by GitBox <gi...@apache.org>.
BenjaminCHEN2016 commented on issue #17904: [Numpy] add: numpy op trilindices
URL: https://github.com/apache/incubator-mxnet/pull/17904#issuecomment-611464212
 
 
   @mxnet-bot run ci [unix-gpu]

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


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] haojin2 commented on a change in pull request #17904: [Numpy] add: numpy op trilindices

Posted by GitBox <gi...@apache.org>.
haojin2 commented on a change in pull request #17904: [Numpy] add: numpy op trilindices
URL: https://github.com/apache/incubator-mxnet/pull/17904#discussion_r400589859
 
 

 ##########
 File path: python/mxnet/numpy/multiarray.py
 ##########
 @@ -5533,6 +5533,87 @@ def tril(m, k=0):
     """
     return _mx_nd_np.tril(m, k)
 
+@set_module('mxnet.numpy')
+def tril_indices(n, k=0, m=None):
+    """
+    Return the indices for the lower-triangle of an (n, m) array.
+
+    Parameters
+    ----------
+    n : int
+        The row dimension of the arrays for which the returned
+        indices will be valid.
+    k : int, optional
+        Diagonal offset (see `tril` for details).
+    m : int, optional
+        .. versionadded:: 1.9.0
+
+        The column dimension of the arrays for which the returned
+        arrays will be valid.
+        By default `m` is taken equal to `n`.
+
+
+    Returns
+    -------
+    inds : tuple of arrays
+        The indices for the triangle. The returned tuple contains two arrays,
+        each with the indices along one dimension of the array.
+
+    See also
+    --------
+    triu_indices : similar function, for upper-triangular.
+    mask_indices : generic function accepting an arbitrary mask function.
+    tril, triu
+
+    Notes
+    -----
+    .. versionadded:: 1.4.0
+
+    Examples
+    --------
+    Compute two different sets of indices to access 4x4 arrays, one for the
+    lower triangular part starting at the main diagonal, and one starting two
+    diagonals further right:
+
+    >>> il1 = np.tril_indices(4)
+    >>> il2 = np.tril_indices(4, 2)
+
+    Here is how they can be used with a sample array:
+
+    >>> a = np.arange(16).reshape(4, 4)
+    >>> a
+    array([[ 0,  1,  2,  3],
+           [ 4,  5,  6,  7],
+           [ 8,  9, 10, 11],
+           [12, 13, 14, 15]])
+
+    Both for indexing:
+
+    >>> a[il1]
+    array([ 0,  4,  5,  8,  9, 10, 12, 13, 14, 15])
+
+    And for assigning values:
+
+    >>> a[il1] = -1
+    >>> a
+    array([[-1,  1,  2,  3],
+           [-1, -1,  6,  7],
+           [-1, -1, -1, 11],
+           [-1, -1, -1, -1]])
+
+    These cover almost the whole array (two diagonals right of the main one):
+
+    >>> a[il2] = -10
+    >>> a
+    array([[-10, -10, -10,   3],
+           [-10, -10, -10, -10],
 
 Review comment:
   remember to verify all of those examples work for your implementation.

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


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] haojin2 commented on issue #17904: [Numpy] add: numpy op trilindices

Posted by GitBox <gi...@apache.org>.
haojin2 commented on issue #17904: [Numpy] add: numpy op trilindices
URL: https://github.com/apache/incubator-mxnet/pull/17904#issuecomment-606338215
 
 
   @BenjaminCHEN2016 please remember to do `git submodule update --init --recursive` after you rebase to get rid of the change to `3rdparty/mkldnn`

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


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] haojin2 commented on a change in pull request #17904: [Numpy] add: numpy op trilindices

Posted by GitBox <gi...@apache.org>.
haojin2 commented on a change in pull request #17904: [Numpy] add: numpy op trilindices
URL: https://github.com/apache/incubator-mxnet/pull/17904#discussion_r400590050
 
 

 ##########
 File path: python/mxnet/symbol/numpy/_symbol.py
 ##########
 @@ -2197,6 +2197,87 @@ def tril(m, k=0):
     """
     return _npi.tril(m, k)
 
+@set_module('mxnet.symbol.numpy')
+def tril_indices(n, k=0, m=None):
+    """
+    Return the indices for the lower-triangle of an (n, m) array.
+
+    Parameters
+    ----------
+    n : int
+        The row dimension of the arrays for which the returned
+        indices will be valid.
+    k : int, optional
+        Diagonal offset (see `tril` for details).
+    m : int, optional
+        .. versionadded:: 1.9.0
+
+        The column dimension of the arrays for which the returned
+        arrays will be valid.
+        By default `m` is taken equal to `n`.
+
+
+    Returns
+    -------
+    inds : tuple of arrays
 
 Review comment:
   here it should be `tuple of _Symbol` I guess

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


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] BenjaminCHEN2016 commented on a change in pull request #17904: [Numpy] add: numpy op trilindices

Posted by GitBox <gi...@apache.org>.
BenjaminCHEN2016 commented on a change in pull request #17904: [Numpy] add: numpy op trilindices
URL: https://github.com/apache/incubator-mxnet/pull/17904#discussion_r400737486
 
 

 ##########
 File path: python/mxnet/numpy/multiarray.py
 ##########
 @@ -5533,6 +5533,87 @@ def tril(m, k=0):
     """
     return _mx_nd_np.tril(m, k)
 
+@set_module('mxnet.numpy')
+def tril_indices(n, k=0, m=None):
+    """
+    Return the indices for the lower-triangle of an (n, m) array.
+
+    Parameters
+    ----------
+    n : int
+        The row dimension of the arrays for which the returned
+        indices will be valid.
+    k : int, optional
+        Diagonal offset (see `tril` for details).
+    m : int, optional
+        .. versionadded:: 1.9.0
+
+        The column dimension of the arrays for which the returned
+        arrays will be valid.
+        By default `m` is taken equal to `n`.
+
+
+    Returns
+    -------
+    inds : tuple of arrays
+        The indices for the triangle. The returned tuple contains two arrays,
+        each with the indices along one dimension of the array.
+
+    See also
+    --------
+    triu_indices : similar function, for upper-triangular.
+    mask_indices : generic function accepting an arbitrary mask function.
+    tril, triu
+
+    Notes
+    -----
+    .. versionadded:: 1.4.0
+
+    Examples
+    --------
+    Compute two different sets of indices to access 4x4 arrays, one for the
+    lower triangular part starting at the main diagonal, and one starting two
+    diagonals further right:
+
+    >>> il1 = np.tril_indices(4)
+    >>> il2 = np.tril_indices(4, 2)
+
+    Here is how they can be used with a sample array:
+
+    >>> a = np.arange(16).reshape(4, 4)
+    >>> a
+    array([[ 0,  1,  2,  3],
+           [ 4,  5,  6,  7],
+           [ 8,  9, 10, 11],
+           [12, 13, 14, 15]])
+
+    Both for indexing:
+
+    >>> a[il1]
+    array([ 0,  4,  5,  8,  9, 10, 12, 13, 14, 15])
+
+    And for assigning values:
+
+    >>> a[il1] = -1
+    >>> a
+    array([[-1,  1,  2,  3],
+           [-1, -1,  6,  7],
+           [-1, -1, -1, 11],
+           [-1, -1, -1, -1]])
+
+    These cover almost the whole array (two diagonals right of the main one):
+
+    >>> a[il2] = -10
+    >>> a
+    array([[-10, -10, -10,   3],
+           [-10, -10, -10, -10],
 
 Review comment:
   I have added more tests.

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


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] haojin2 commented on a change in pull request #17904: [Numpy] add: numpy op trilindices

Posted by GitBox <gi...@apache.org>.
haojin2 commented on a change in pull request #17904: [Numpy] add: numpy op trilindices
URL: https://github.com/apache/incubator-mxnet/pull/17904#discussion_r400586031
 
 

 ##########
 File path: tests/python/unittest/test_numpy_op.py
 ##########
 @@ -6693,6 +6693,35 @@ def test_np_builtin_op_signature():
         assert op is not None
         assert str(op.__signature__) == str(inspect.signature(_op_from_doc))
 
+@with_seed()
 
 Review comment:
   an extra blank line above

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


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] haojin2 commented on a change in pull request #17904: [Numpy] add: numpy op trilindices

Posted by GitBox <gi...@apache.org>.
haojin2 commented on a change in pull request #17904: [Numpy] add: numpy op trilindices
URL: https://github.com/apache/incubator-mxnet/pull/17904#discussion_r405196267
 
 

 ##########
 File path: src/operator/numpy/np_matrix_op-inl.h
 ##########
 @@ -287,6 +287,106 @@ void NumpyVstackBackward(const nnvm::NodeAttrs& attrs,
   });
 }
 
+struct NumpyTrilindicesParam : public dmlc::Parameter<NumpyTrilindicesParam> {
+  int n;
+  int k;
+  int m;
+  DMLC_DECLARE_PARAMETER(NumpyTrilindicesParam) {
+    DMLC_DECLARE_FIELD(n)
+      .describe("The row dimension of the arrays for which"
+                "the returned indices will be valid.");
+    DMLC_DECLARE_FIELD(k)
+      .set_default(0)
+      .describe("Diagonal offset");
+    DMLC_DECLARE_FIELD(m)
+      .describe("The column dimension of the arrays for "
+                "which the returned arrays will be valid."
+                "By default m is taken equal to n.");
+  }
+  void SetAttrDict(std::unordered_map<std::string, std::string>* dict) {
+    std::ostringstream n_s, k_s, m_s;
+    n_s << n;
+    k_s << k;
+    m_s << m;
+    (*dict)["n"] = n_s.str();
+    (*dict)["k"] = k_s.str();
+    (*dict)["m"] = m_s.str();
+  }
+};
+
+template<int req>
+struct TrilindicesOpForwardImpl {
+  template<typename DType>
+  MSHADOW_XINLINE static void Map(int i, DType* out_data0, DType* out_data1,
+                                  int* data, int length) {
+    KERNEL_ASSIGN(out_data0[i], req, data[i]);
+    KERNEL_ASSIGN(out_data1[i], req, data[i + length]);
+  }
+};
+
+template<typename xpu>
+void TrilindicesOpForward(const nnvm::NodeAttrs& attrs,
+                    const OpContext& ctx,
 
 Review comment:
   alignment

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


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] haojin2 commented on a change in pull request #17904: [Numpy] add: numpy op trilindices

Posted by GitBox <gi...@apache.org>.
haojin2 commented on a change in pull request #17904: [Numpy] add: numpy op trilindices
URL: https://github.com/apache/incubator-mxnet/pull/17904#discussion_r400587705
 
 

 ##########
 File path: src/operator/numpy/np_tril_indices_op.cc
 ##########
 @@ -0,0 +1,46 @@
+/*
 
 Review comment:
   move this op to `np_matrix_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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] haojin2 commented on a change in pull request #17904: [Numpy] add: numpy op trilindices

Posted by GitBox <gi...@apache.org>.
haojin2 commented on a change in pull request #17904: [Numpy] add: numpy op trilindices
URL: https://github.com/apache/incubator-mxnet/pull/17904#discussion_r405196087
 
 

 ##########
 File path: src/operator/numpy/np_matrix_op.cc
 ##########
 @@ -1115,6 +1115,66 @@ NNVM_REGISTER_OP(_backward_np_dstack)
 .set_attr<nnvm::TIsBackward>("TIsBackward", true)
 .set_attr<FCompute>("FCompute<cpu>", DStackGradCompute<cpu>);
 
+DMLC_REGISTER_PARAMETER(NumpyTrilindicesParam);
+
+inline bool TrilindicesOpType(const nnvm::NodeAttrs& attrs,
+                                std::vector<int> *in_attrs,
+                                std::vector<int> *out_attrs) {
+  CHECK_EQ(in_attrs->size(), 0U);
+  CHECK_EQ(out_attrs->size(), 2U);
+
+  TYPE_ASSIGN_CHECK(*out_attrs, 0, mshadow::kInt64);
+  TYPE_ASSIGN_CHECK(*out_attrs, 1, mshadow::kInt64);
+
+  return true;
+}
+
+inline bool TrilindicesOpShape(const nnvm::NodeAttrs& attrs,
+                            mxnet::ShapeVector* in_attrs,
 
 Review comment:
   alignment

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


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] haojin2 commented on a change in pull request #17904: [Numpy] add: numpy op trilindices

Posted by GitBox <gi...@apache.org>.
haojin2 commented on a change in pull request #17904: [Numpy] add: numpy op trilindices
URL: https://github.com/apache/incubator-mxnet/pull/17904#discussion_r400589672
 
 

 ##########
 File path: python/mxnet/numpy/multiarray.py
 ##########
 @@ -5533,6 +5533,87 @@ def tril(m, k=0):
     """
     return _mx_nd_np.tril(m, k)
 
+@set_module('mxnet.numpy')
+def tril_indices(n, k=0, m=None):
+    """
+    Return the indices for the lower-triangle of an (n, m) array.
+
+    Parameters
+    ----------
+    n : int
+        The row dimension of the arrays for which the returned
+        indices will be valid.
+    k : int, optional
+        Diagonal offset (see `tril` for details).
+    m : int, optional
+        .. versionadded:: 1.9.0
+
+        The column dimension of the arrays for which the returned
+        arrays will be valid.
+        By default `m` is taken equal to `n`.
+
 
 Review comment:
   get rid of this 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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] BenjaminCHEN2016 commented on issue #17904: [Numpy] add: numpy op trilindices

Posted by GitBox <gi...@apache.org>.
BenjaminCHEN2016 commented on issue #17904: [Numpy] add: numpy op trilindices
URL: https://github.com/apache/incubator-mxnet/pull/17904#issuecomment-604270633
 
 
   @mxnet-bot run ci [all]

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


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] haojin2 commented on a change in pull request #17904: [Numpy] add: numpy op trilindices

Posted by GitBox <gi...@apache.org>.
haojin2 commented on a change in pull request #17904: [Numpy] add: numpy op trilindices
URL: https://github.com/apache/incubator-mxnet/pull/17904#discussion_r400587794
 
 

 ##########
 File path: python/mxnet/symbol/numpy/_symbol.py
 ##########
 @@ -2197,6 +2197,87 @@ def tril(m, k=0):
     """
     return _npi.tril(m, k)
 
+@set_module('mxnet.symbol.numpy')
 
 Review comment:
   one more blank line above.

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


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] BenjaminCHEN2016 commented on issue #17904: [Numpy] add: numpy op trilindices

Posted by GitBox <gi...@apache.org>.
BenjaminCHEN2016 commented on issue #17904: [Numpy] add: numpy op trilindices
URL: https://github.com/apache/incubator-mxnet/pull/17904#issuecomment-611859882
 
 
   @mxnet-bot run ci [unix-gpu]

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


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] mxnet-bot commented on issue #17904: [Numpy] add: numpy op trilindices

Posted by GitBox <gi...@apache.org>.
mxnet-bot commented on issue #17904: [Numpy] add: numpy op trilindices
URL: https://github.com/apache/incubator-mxnet/pull/17904#issuecomment-611464248
 
 
   Jenkins CI successfully triggered : [unix-gpu]

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


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] haojin2 commented on a change in pull request #17904: [Numpy] add: numpy op trilindices

Posted by GitBox <gi...@apache.org>.
haojin2 commented on a change in pull request #17904: [Numpy] add: numpy op trilindices
URL: https://github.com/apache/incubator-mxnet/pull/17904#discussion_r400587830
 
 

 ##########
 File path: python/mxnet/symbol/numpy/_symbol.py
 ##########
 @@ -2197,6 +2197,87 @@ def tril(m, k=0):
     """
     return _npi.tril(m, k)
 
+@set_module('mxnet.symbol.numpy')
+def tril_indices(n, k=0, m=None):
+    """
+    Return the indices for the lower-triangle of an (n, m) array.
+
+    Parameters
+    ----------
+    n : int
+        The row dimension of the arrays for which the returned
+        indices will be valid.
+    k : int, optional
+        Diagonal offset (see `tril` for details).
+    m : int, optional
+        .. versionadded:: 1.9.0
+
+        The column dimension of the arrays for which the returned
+        arrays will be valid.
+        By default `m` is taken equal to `n`.
+
+
+    Returns
+    -------
+    inds : tuple of arrays
+        The indices for the triangle. The returned tuple contains two arrays,
+        each with the indices along one dimension of the array.
+
+    See also
+    --------
+    triu_indices : similar function, for upper-triangular.
+    mask_indices : generic function accepting an arbitrary mask function.
+    tril, triu
+
+    Notes
+    -----
+    .. versionadded:: 1.4.0
+
+    Examples
+    --------
+    Compute two different sets of indices to access 4x4 arrays, one for the
+    lower triangular part starting at the main diagonal, and one starting two
+    diagonals further right:
+
+    >>> il1 = np.tril_indices(4)
+    >>> il2 = np.tril_indices(4, 2)
+
+    Here is how they can be used with a sample array:
+
+    >>> a = np.arange(16).reshape(4, 4)
+    >>> a
+    array([[ 0,  1,  2,  3],
+           [ 4,  5,  6,  7],
+           [ 8,  9, 10, 11],
+           [12, 13, 14, 15]])
+
+    Both for indexing:
+
+    >>> a[il1]
+    array([ 0,  4,  5,  8,  9, 10, 12, 13, 14, 15])
+
+    And for assigning values:
+
+    >>> a[il1] = -1
+    >>> a
+    array([[-1,  1,  2,  3],
+           [-1, -1,  6,  7],
+           [-1, -1, -1, 11],
+           [-1, -1, -1, -1]])
+
+    These cover almost the whole array (two diagonals right of the main one):
+
+    >>> a[il2] = -10
+    >>> a
+    array([[-10, -10, -10,   3],
+           [-10, -10, -10, -10],
+           [-10, -10, -10, -10],
+           [-10, -10, -10, -10]])
+
+    """
+    if m is None:
+        m = n
+    return _npi.tril_indices(n, k, m)
 
 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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] haojin2 commented on a change in pull request #17904: [Numpy] add: numpy op trilindices

Posted by GitBox <gi...@apache.org>.
haojin2 commented on a change in pull request #17904: [Numpy] add: numpy op trilindices
URL: https://github.com/apache/incubator-mxnet/pull/17904#discussion_r400586071
 
 

 ##########
 File path: tests/python/unittest/test_numpy_op.py
 ##########
 @@ -6693,6 +6693,35 @@ def test_np_builtin_op_signature():
         assert op is not None
         assert str(op.__signature__) == str(inspect.signature(_op_from_doc))
 
+@with_seed()
+@use_np
+def test_np_tril_indices():
+    class TestTrilindices(HybridBlock):
+        def __init__(self, n, k=0, m=None):
+            super(TestTrilindices, self).__init__()
+            self._n = n;
+            self._k = k;
+            if m is None:
+                m = n
+            self._m = m
+        
+        def hybrid_forward(self, F, x, *args, **kwargs):
+            return x, F.np.tril_indices(n=self._n, k=self._k, m=self._m)
+    
+    for n in _np.random.random_integers(-10, 50, 10):
+        for k in _np.random.random_integers(-50, 50, 4):
+            for m in _np.random.random_integers(-10, 50, 4):
+                np_out = _np.tril_indices(n, k, m)
+                for hybridize in [True, False]:
+                    # dummy nparray for hybridize
+                    x = mx.nd.ones((1,1)).as_np_ndarray()
+                    test_trilindices = TestTrilindices(n, k, m)
+                    if hybridize:
+                        test_trilindices.hybridize()
+                    mx_out = test_trilindices(x)[1]
+                    assert len(mx_out) == 2
+                    assert same(mx_out[0], np_out[0])
+                    assert same(mx_out[1], np_out[1])
 
 Review comment:
   an extra 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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] haojin2 commented on a change in pull request #17904: [Numpy] add: numpy op trilindices

Posted by GitBox <gi...@apache.org>.
haojin2 commented on a change in pull request #17904: [Numpy] add: numpy op trilindices
URL: https://github.com/apache/incubator-mxnet/pull/17904#discussion_r400586225
 
 

 ##########
 File path: tests/python/unittest/test_numpy_op.py
 ##########
 @@ -6693,6 +6693,35 @@ def test_np_builtin_op_signature():
         assert op is not None
         assert str(op.__signature__) == str(inspect.signature(_op_from_doc))
 
+@with_seed()
+@use_np
+def test_np_tril_indices():
+    class TestTrilindices(HybridBlock):
+        def __init__(self, n, k=0, m=None):
+            super(TestTrilindices, self).__init__()
+            self._n = n;
+            self._k = k;
+            if m is None:
+                m = n
+            self._m = m
+        
+        def hybrid_forward(self, F, x, *args, **kwargs):
+            return x, F.np.tril_indices(n=self._n, k=self._k, m=self._m)
+    
+    for n in _np.random.random_integers(-10, 50, 10):
+        for k in _np.random.random_integers(-50, 50, 4):
+            for m in _np.random.random_integers(-10, 50, 4):
+                np_out = _np.tril_indices(n, k, m)
+                for hybridize in [True, False]:
+                    # dummy nparray for hybridize
+                    x = mx.nd.ones((1,1)).as_np_ndarray()
 
 Review comment:
   simply do `x = np.ones((1, 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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] mxnet-bot commented on issue #17904: [Numpy] add: numpy op trilindices

Posted by GitBox <gi...@apache.org>.
mxnet-bot commented on issue #17904: [Numpy] add: numpy op trilindices
URL: https://github.com/apache/incubator-mxnet/pull/17904#issuecomment-611355202
 
 
   None of the jobs entered are supported. 
   Jobs entered by user: [macosx]
   CI supported Jobs: [centos-gpu, miscellaneous, website, sanity, windows-cpu, windows-gpu, centos-cpu, unix-gpu, edge, clang, unix-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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] haojin2 commented on a change in pull request #17904: [Numpy] add: numpy op trilindices

Posted by GitBox <gi...@apache.org>.
haojin2 commented on a change in pull request #17904: [Numpy] add: numpy op trilindices
URL: https://github.com/apache/incubator-mxnet/pull/17904#discussion_r400589634
 
 

 ##########
 File path: python/mxnet/numpy/multiarray.py
 ##########
 @@ -5533,6 +5533,87 @@ def tril(m, k=0):
     """
     return _mx_nd_np.tril(m, k)
 
+@set_module('mxnet.numpy')
+def tril_indices(n, k=0, m=None):
+    """
+    Return the indices for the lower-triangle of an (n, m) array.
+
+    Parameters
+    ----------
+    n : int
+        The row dimension of the arrays for which the returned
+        indices will be valid.
+    k : int, optional
+        Diagonal offset (see `tril` for details).
+    m : int, optional
+        .. versionadded:: 1.9.0
+
+        The column dimension of the arrays for which the returned
+        arrays will be valid.
+        By default `m` is taken equal to `n`.
+
+
+    Returns
+    -------
+    inds : tuple of arrays
+        The indices for the triangle. The returned tuple contains two arrays,
+        each with the indices along one dimension of the array.
+
+    See also
+    --------
+    triu_indices : similar function, for upper-triangular.
+    mask_indices : generic function accepting an arbitrary mask function.
+    tril, triu
+
+    Notes
+    -----
+    .. versionadded:: 1.4.0
+
+    Examples
+    --------
+    Compute two different sets of indices to access 4x4 arrays, one for the
+    lower triangular part starting at the main diagonal, and one starting two
+    diagonals further right:
+
+    >>> il1 = np.tril_indices(4)
+    >>> il2 = np.tril_indices(4, 2)
+
+    Here is how they can be used with a sample array:
+
+    >>> a = np.arange(16).reshape(4, 4)
+    >>> a
+    array([[ 0,  1,  2,  3],
+           [ 4,  5,  6,  7],
+           [ 8,  9, 10, 11],
+           [12, 13, 14, 15]])
+
+    Both for indexing:
+
+    >>> a[il1]
+    array([ 0,  4,  5,  8,  9, 10, 12, 13, 14, 15])
+
+    And for assigning values:
+
+    >>> a[il1] = -1
+    >>> a
+    array([[-1,  1,  2,  3],
+           [-1, -1,  6,  7],
+           [-1, -1, -1, 11],
+           [-1, -1, -1, -1]])
+
+    These cover almost the whole array (two diagonals right of the main one):
+
+    >>> a[il2] = -10
+    >>> a
+    array([[-10, -10, -10,   3],
+           [-10, -10, -10, -10],
+           [-10, -10, -10, -10],
+           [-10, -10, -10, -10]])
+
+    """
+    if m is None:
+        m = n
+    return _mx_nd_np.tril_indices(n, k, m)
 
 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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] mxnet-bot commented on issue #17904: [Numpy] add: numpy op trilindices

Posted by GitBox <gi...@apache.org>.
mxnet-bot commented on issue #17904: [Numpy] add: numpy op trilindices
URL: https://github.com/apache/incubator-mxnet/pull/17904#issuecomment-603675581
 
 
   Hey @BenjaminCHEN2016 , Thanks for submitting the PR 
   Once your PR is ready for CI checks, invoke the following commands: 
   - To trigger all jobs: @mxnet-bot run ci [all] 
   - To trigger specific jobs: @mxnet-bot run ci [job1, job2] 
   *** 
   **CI supported jobs**: [windows-gpu, website, unix-gpu, edge, centos-cpu, windows-cpu, miscellaneous, sanity, unix-cpu, centos-gpu, clang]
   *** 
   _Note_: 
    Only following 3 categories can trigger CI :PR Author, MXNet Committer, Jenkins Admin. 
   All CI tests must pass before the PR can be 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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] mxnet-bot commented on issue #17904: [Numpy] add: numpy op trilindices

Posted by GitBox <gi...@apache.org>.
mxnet-bot commented on issue #17904: [Numpy] add: numpy op trilindices
URL: https://github.com/apache/incubator-mxnet/pull/17904#issuecomment-611345092
 
 
   Jenkins CI successfully triggered : [unix-gpu]

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


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] mxnet-bot commented on issue #17904: [Numpy] add: numpy op trilindices

Posted by GitBox <gi...@apache.org>.
mxnet-bot commented on issue #17904: [Numpy] add: numpy op trilindices
URL: https://github.com/apache/incubator-mxnet/pull/17904#issuecomment-611859909
 
 
   Jenkins CI successfully triggered : [unix-gpu]

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


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] haojin2 commented on a change in pull request #17904: [Numpy] add: numpy op trilindices

Posted by GitBox <gi...@apache.org>.
haojin2 commented on a change in pull request #17904: [Numpy] add: numpy op trilindices
URL: https://github.com/apache/incubator-mxnet/pull/17904#discussion_r400588805
 
 

 ##########
 File path: python/mxnet/numpy/multiarray.py
 ##########
 @@ -5533,6 +5533,87 @@ def tril(m, k=0):
     """
     return _mx_nd_np.tril(m, k)
 
+@set_module('mxnet.numpy')
 
 Review comment:
   one more blank line above.

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


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] haojin2 commented on a change in pull request #17904: [Numpy] add: numpy op trilindices

Posted by GitBox <gi...@apache.org>.
haojin2 commented on a change in pull request #17904: [Numpy] add: numpy op trilindices
URL: https://github.com/apache/incubator-mxnet/pull/17904#discussion_r400587466
 
 

 ##########
 File path: tests/python/unittest/test_numpy_op.py
 ##########
 @@ -6693,6 +6693,35 @@ def test_np_builtin_op_signature():
         assert op is not None
         assert str(op.__signature__) == str(inspect.signature(_op_from_doc))
 
+@with_seed()
+@use_np
+def test_np_tril_indices():
+    class TestTrilindices(HybridBlock):
+        def __init__(self, n, k=0, m=None):
+            super(TestTrilindices, self).__init__()
+            self._n = n;
+            self._k = k;
+            if m is None:
+                m = n
+            self._m = m
+        
+        def hybrid_forward(self, F, x, *args, **kwargs):
+            return x, F.np.tril_indices(n=self._n, k=self._k, m=self._m)
+    
+    for n in _np.random.random_integers(-10, 50, 10):
 
 Review comment:
   how long is this unit test currently taking? If it's taking more than 3 seconds for a single run, please consider reducing those test cases.

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


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] BenjaminCHEN2016 commented on issue #17904: [Numpy] add: numpy op trilindices

Posted by GitBox <gi...@apache.org>.
BenjaminCHEN2016 commented on issue #17904: [Numpy] add: numpy op trilindices
URL: https://github.com/apache/incubator-mxnet/pull/17904#issuecomment-611345037
 
 
   @mxnet-bot run ci [unix-gpu]

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


With regards,
Apache Git Services

[GitHub] [incubator-mxnet] haojin2 commented on a change in pull request #17904: [Numpy] add: numpy op trilindices

Posted by GitBox <gi...@apache.org>.
haojin2 commented on a change in pull request #17904: [Numpy] add: numpy op trilindices
URL: https://github.com/apache/incubator-mxnet/pull/17904#discussion_r405196183
 
 

 ##########
 File path: src/operator/numpy/np_matrix_op.cc
 ##########
 @@ -1115,6 +1115,66 @@ NNVM_REGISTER_OP(_backward_np_dstack)
 .set_attr<nnvm::TIsBackward>("TIsBackward", true)
 .set_attr<FCompute>("FCompute<cpu>", DStackGradCompute<cpu>);
 
+DMLC_REGISTER_PARAMETER(NumpyTrilindicesParam);
+
+inline bool TrilindicesOpType(const nnvm::NodeAttrs& attrs,
+                                std::vector<int> *in_attrs,
+                                std::vector<int> *out_attrs) {
+  CHECK_EQ(in_attrs->size(), 0U);
+  CHECK_EQ(out_attrs->size(), 2U);
+
+  TYPE_ASSIGN_CHECK(*out_attrs, 0, mshadow::kInt64);
+  TYPE_ASSIGN_CHECK(*out_attrs, 1, mshadow::kInt64);
+
+  return true;
+}
+
+inline bool TrilindicesOpShape(const nnvm::NodeAttrs& attrs,
+                            mxnet::ShapeVector* in_attrs,
+                            mxnet::ShapeVector* out_attrs) {
+  CHECK_EQ(in_attrs->size(), 0U);
+  CHECK_EQ(out_attrs->size(), 2U);
+
+  const NumpyTrilindicesParam& param =
+                              nnvm::get<NumpyTrilindicesParam>(attrs.parsed);
 
 Review comment:
   ```c++
     const NumpyTrilindicesParam& param =
       nnvm::get<NumpyTrilindicesParam>(attrs.parsed);
   ```

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


With regards,
Apache Git Services