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/04/14 03:36:48 UTC

[GitHub] [incubator-mxnet] BenjaminCHEN2016 opened a new pull request #18049: [numpy] add numpy op fill_diagonal

BenjaminCHEN2016 opened a new pull request #18049: [numpy] add numpy op fill_diagonal
URL: https://github.com/apache/incubator-mxnet/pull/18049
 
 
   ## Description ##
   add numpy op fill_diagonal
   
   ## 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] BenjaminCHEN2016 commented on issue #18049: [numpy] add numpy op fill_diagonal

Posted by GitBox <gi...@apache.org>.
BenjaminCHEN2016 commented on issue #18049: [numpy] add numpy op fill_diagonal
URL: https://github.com/apache/incubator-mxnet/pull/18049#issuecomment-615083884
 
 
   @mxnet-bot run ci [windows-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] BenjaminCHEN2016 commented on issue #18049: [numpy] add numpy op fill_diagonal

Posted by GitBox <gi...@apache.org>.
BenjaminCHEN2016 commented on issue #18049: [numpy] add numpy op fill_diagonal
URL: https://github.com/apache/incubator-mxnet/pull/18049#issuecomment-615180087
 
 
   @mxnet-bot run ci [windows-cpu, windows-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 #18049: [numpy] add numpy op fill_diagonal

Posted by GitBox <gi...@apache.org>.
mxnet-bot commented on issue #18049: [numpy] add numpy op fill_diagonal
URL: https://github.com/apache/incubator-mxnet/pull/18049#issuecomment-613208462
 
 
   Hey @BenjaminCHEN2016 , Thanks for submitting the PR 
   All tests are already queued to run once. If tests fail, you can trigger one or more tests again with 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**: [edge, unix-gpu, windows-cpu, website, centos-cpu, unix-cpu, centos-gpu, windows-gpu, sanity, miscellaneous, 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 #18049: [numpy] add numpy op fill_diagonal

Posted by GitBox <gi...@apache.org>.
mxnet-bot commented on issue #18049: [numpy] add numpy op fill_diagonal
URL: https://github.com/apache/incubator-mxnet/pull/18049#issuecomment-615180135
 
 
   Jenkins CI successfully triggered : [windows-gpu, windows-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 #18049: [numpy] add numpy op fill_diagonal

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

 ##########
 File path: python/mxnet/symbol/numpy/_symbol.py
 ##########
 @@ -6582,6 +6582,102 @@ def resize(a, new_shape):
     return _npi.resize_fallback(a, new_shape=new_shape)
 
 
+@set_module('mxnet.symbol.numpy')
+def fill_diagonal(a, val, wrap=False):
+    """
+    Fill the main diagonal of the given array of any dimensionality.
+    For an array `a` with ``a.ndim >= 2``, the diagonal is the list of
+    locations with indices ``a[i, ..., i]`` all identical. This function
+    modifies the input array in-place, it does not return a value.
+    Parameters
 
 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 #18049: [numpy] add numpy op fill_diagonal

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

 ##########
 File path: tests/python/unittest/test_numpy_op.py
 ##########
 @@ -6900,7 +6900,51 @@ def hybrid_forward(self, F, x, *args, **kwargs):
                         np_data[np_out] = -10
                         mx_data[mx_out] = -10
                         assert same(np_data, mx_data.asnumpy())
-                        
+
 
 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 #18049: [numpy] add numpy op fill_diagonal

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

 ##########
 File path: python/mxnet/symbol/numpy/_symbol.py
 ##########
 @@ -6582,6 +6582,102 @@ def resize(a, new_shape):
     return _npi.resize_fallback(a, new_shape=new_shape)
 
 
+@set_module('mxnet.symbol.numpy')
+def fill_diagonal(a, val, wrap=False):
+    """
+    Fill the main diagonal of the given array of any dimensionality.
+    For an array `a` with ``a.ndim >= 2``, the diagonal is the list of
+    locations with indices ``a[i, ..., i]`` all identical. This function
+    modifies the input array in-place, it does not return a value.
+    Parameters
+    ----------
+    a : array, at least 2-D.
+      Array whose diagonal is to be filled, it gets modified in-place.
+    val : scalar
+      Value to be written on the diagonal, its type must be compatible with
+      that of the array a.
+    wrap : bool
+      For tall matrices in NumPy version up to 1.6.2, the
+      diagonal "wrapped" after N columns. You can have this behavior
+      with this option. This affects only tall matrices.
+    See also
+    --------
+    diag_indices, diag_indices_from
+    Notes
 
 Review comment:
   no need for `notes` and `see also`

----------------------------------------------------------------
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] hzfan commented on a change in pull request #18049: [numpy] add numpy op fill_diagonal

Posted by GitBox <gi...@apache.org>.
hzfan commented on a change in pull request #18049: [numpy] add numpy op fill_diagonal
URL: https://github.com/apache/incubator-mxnet/pull/18049#discussion_r409985694
 
 

 ##########
 File path: src/api/operator/numpy/np_fill_diagonal_op.cc
 ##########
 @@ -0,0 +1,58 @@
+/*
+ * 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_fill_diagonal_op.cc
+ * \brief Implementation of the API of functions in src/operator/numpy/np_fill_diagonal.cc */
+#include <mxnet/api_registry.h>
+#include "../utils.h"
+#include "../../../operator/numpy/np_fill_diagonal_op-inl.h"
+
+namespace mxnet {
+
+MXNET_REGISTER_API("_npi.fill_diagonal")
+.set_body([](runtime::MXNetArgs args, runtime::MXNetRetValue* ret) {
+  using namespace runtime;
+  const nnvm::Op* op = Op::Get("_npi_fill_diagonal");
+  nnvm::NodeAttrs attrs;
+
+  op::NumpyFillDiagonalParam param;
+  int num_inputs = 1;
+  NDArray* inputs[] = {args[0].operator mxnet::NDArray*()};
+
+  param.val = Tuple<double>(1, args[1].operator double());
 
 Review comment:
   @BenjaminCHEN2016 #17866 has been merged. Let's use `Obj2Tuple` like https://github.com/apache/incubator-mxnet/pull/17866/files#diff-4c8cf94cd8bf4368b07f43c165402239R49.

----------------------------------------------------------------
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 #18049: [numpy] add numpy op fill_diagonal

Posted by GitBox <gi...@apache.org>.
BenjaminCHEN2016 commented on issue #18049: [numpy] add numpy op fill_diagonal
URL: https://github.com/apache/incubator-mxnet/pull/18049#issuecomment-615088708
 
 
   @mxnet-bot run ci [windows-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 #18049: [numpy] add numpy op fill_diagonal

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

 ##########
 File path: src/operator/numpy/np_fill_diagonal_op-inl.h
 ##########
 @@ -0,0 +1,174 @@
+/*
+ * 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) 2020 by Contributors
+ * \file np_tril_op-inl.h
+ * \brief Function definition of the tril (lower triangle of an array) op
+ */
+
+#ifndef MXNET_OPERATOR_NUMPY_NP_FILL_DIAGONAL_OP_INL_H_
+#define MXNET_OPERATOR_NUMPY_NP_FILL_DIAGONAL_OP_INL_H_
+
+#include <dmlc/parameter.h>
+#include <vector>
+#include <string>
+#include <algorithm>
+#include "../mxnet_op.h"
+#include "../operator_common.h"
+#include "../elemwise_op_common.h"
+
+namespace mxnet {
+namespace op {
+
+struct NumpyFillDiagonalParam : public dmlc::Parameter<NumpyFillDiagonalParam> {
+  Tuple<double> val;
+  bool wrap;
+  DMLC_DECLARE_PARAMETER(NumpyFillDiagonalParam) {
+    DMLC_DECLARE_FIELD(val)
+      .describe("Value to be written on the diagonal, "
+                "its type must be compatible with that of the array a.");
+    DMLC_DECLARE_FIELD(wrap)
+    .set_default(false)
+    .describe("The diagonal “wrapped” after N columns."
+              "You can have this behavior with this option. "
+              "This affects only tall matrices.");
+  }
+  void SetAttrDict(std::unordered_map<std::string, std::string>* dict) {
 
 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] hzfan commented on a change in pull request #18049: [numpy] add numpy op fill_diagonal

Posted by GitBox <gi...@apache.org>.
hzfan commented on a change in pull request #18049: [numpy] add numpy op fill_diagonal
URL: https://github.com/apache/incubator-mxnet/pull/18049#discussion_r409481301
 
 

 ##########
 File path: src/api/operator/numpy/np_fill_diagonal_op.cc
 ##########
 @@ -0,0 +1,58 @@
+/*
+ * 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_fill_diagonal_op.cc
+ * \brief Implementation of the API of functions in src/operator/numpy/np_fill_diagonal.cc */
+#include <mxnet/api_registry.h>
+#include "../utils.h"
+#include "../../../operator/numpy/np_fill_diagonal_op-inl.h"
+
+namespace mxnet {
+
+MXNET_REGISTER_API("_npi.fill_diagonal")
+.set_body([](runtime::MXNetArgs args, runtime::MXNetRetValue* ret) {
+  using namespace runtime;
+  const nnvm::Op* op = Op::Get("_npi_fill_diagonal");
+  nnvm::NodeAttrs attrs;
+
+  op::NumpyFillDiagonalParam param;
+  int num_inputs = 1;
+  NDArray* inputs[] = {args[0].operator mxnet::NDArray*()};
+
+  param.val = Tuple<double>(1, args[1].operator double());
 
 Review comment:
   tuple of float is not supported for now. We may wait for #17866 .

----------------------------------------------------------------
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 #18049: [numpy] add numpy op fill_diagonal

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

 ##########
 File path: python/mxnet/ndarray/numpy/_op.py
 ##########
 @@ -7477,6 +7477,94 @@ def resize(a, new_shape):
     return _npi.resize_fallback(a, new_shape=new_shape)
 
 
+@set_module('mxnet.ndarray.numpy')
+def fill_diagonal(a, val, wrap=False):
+    """
+    Fill the main diagonal of the given array of any dimensionality.
+    For an array `a` with ``a.ndim >= 2``, the diagonal is the list of
+    locations with indices ``a[i, ..., i]`` all identical. This function
+    modifies the input array in-place, it does not return a value.
+    Parameters
 
 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] mxnet-bot commented on issue #18049: [numpy] add numpy op fill_diagonal

Posted by GitBox <gi...@apache.org>.
mxnet-bot commented on issue #18049: [numpy] add numpy op fill_diagonal
URL: https://github.com/apache/incubator-mxnet/pull/18049#issuecomment-615088777
 
 
   Jenkins CI successfully triggered : [windows-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 #18049: [numpy] add numpy op fill_diagonal

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

 ##########
 File path: python/mxnet/symbol/numpy/_symbol.py
 ##########
 @@ -6582,6 +6582,102 @@ def resize(a, new_shape):
     return _npi.resize_fallback(a, new_shape=new_shape)
 
 
+@set_module('mxnet.symbol.numpy')
+def fill_diagonal(a, val, wrap=False):
+    """
+    Fill the main diagonal of the given array of any dimensionality.
+    For an array `a` with ``a.ndim >= 2``, the diagonal is the list of
+    locations with indices ``a[i, ..., i]`` all identical. This function
+    modifies the input array in-place, it does not return a value.
+    Parameters
+    ----------
+    a : array, at least 2-D.
+      Array whose diagonal is to be filled, it gets modified in-place.
+    val : scalar
+      Value to be written on the diagonal, its type must be compatible with
+      that of the array a.
+    wrap : bool
+      For tall matrices in NumPy version up to 1.6.2, the
+      diagonal "wrapped" after N columns. You can have this behavior
+      with this option. This affects only tall matrices.
+    See also
+    --------
+    diag_indices, diag_indices_from
+    Notes
+    -----
+    .. versionadded:: 1.4.0
+    This functionality can be obtained via `diag_indices`, but internally
+    this version uses a much faster implementation that never constructs the
+    indices and uses simple slicing.
+    Examples
 
 Review comment:
   actually no need for `examples` for symbol

----------------------------------------------------------------
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 #18049: [numpy] add numpy op fill_diagonal

Posted by GitBox <gi...@apache.org>.
haojin2 commented on issue #18049: [numpy] add numpy op fill_diagonal
URL: https://github.com/apache/incubator-mxnet/pull/18049#issuecomment-613610980
 
 
   @hzfan Could you double check on the ffi part?

----------------------------------------------------------------
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 #18049: [numpy] add numpy op fill_diagonal

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

 ##########
 File path: src/api/operator/numpy/np_fill_diagonal_op.cc
 ##########
 @@ -0,0 +1,58 @@
+/*
+ * 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_fill_diagonal_op.cc
+ * \brief Implementation of the API of functions in src/operator/numpy/np_fill_diagonal.cc */
+#include <mxnet/api_registry.h>
+#include "../utils.h"
+#include "../../../operator/numpy/np_fill_diagonal_op-inl.h"
+
+namespace mxnet {
+
+MXNET_REGISTER_API("_npi.fill_diagonal")
+.set_body([](runtime::MXNetArgs args, runtime::MXNetRetValue* ret) {
+  using namespace runtime;
+  const nnvm::Op* op = Op::Get("_npi_fill_diagonal");
+  nnvm::NodeAttrs attrs;
+
+  op::NumpyFillDiagonalParam param;
+  int num_inputs = 1;
+  NDArray* inputs[] = {args[0].operator mxnet::NDArray*()};
+
+  param.val = Tuple<double>(1, args[1].operator double());
 
 Review comment:
   #17866 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] haojin2 commented on a change in pull request #18049: [numpy] add numpy op fill_diagonal

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

 ##########
 File path: python/mxnet/symbol/numpy/_symbol.py
 ##########
 @@ -6582,6 +6582,102 @@ def resize(a, new_shape):
     return _npi.resize_fallback(a, new_shape=new_shape)
 
 
+@set_module('mxnet.symbol.numpy')
+def fill_diagonal(a, val, wrap=False):
+    """
+    Fill the main diagonal of the given array of any dimensionality.
+    For an array `a` with ``a.ndim >= 2``, the diagonal is the list of
+    locations with indices ``a[i, ..., i]`` all identical. This function
+    modifies the input array in-place, it does not return a value.
+    Parameters
+    ----------
+    a : array, at least 2-D.
+      Array whose diagonal is to be filled, it gets modified in-place.
+    val : scalar
+      Value to be written on the diagonal, its type must be compatible with
+      that of the array a.
+    wrap : bool
+      For tall matrices in NumPy version up to 1.6.2, the
+      diagonal "wrapped" after N columns. You can have this behavior
+      with this option. This affects only tall matrices.
+    See also
+    --------
+    diag_indices, diag_indices_from
+    Notes
+    -----
+    .. versionadded:: 1.4.0
+    This functionality can be obtained via `diag_indices`, but internally
+    this version uses a much faster implementation that never constructs the
+    indices and uses simple slicing.
+    Examples
 
 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] mxnet-bot commented on issue #18049: [numpy] add numpy op fill_diagonal

Posted by GitBox <gi...@apache.org>.
mxnet-bot commented on issue #18049: [numpy] add numpy op fill_diagonal
URL: https://github.com/apache/incubator-mxnet/pull/18049#issuecomment-615083951
 
 
   Jenkins CI successfully triggered : [windows-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] hzfan commented on a change in pull request #18049: [numpy] add numpy op fill_diagonal

Posted by GitBox <gi...@apache.org>.
hzfan commented on a change in pull request #18049: [numpy] add numpy op fill_diagonal
URL: https://github.com/apache/incubator-mxnet/pull/18049#discussion_r409986072
 
 

 ##########
 File path: python/mxnet/ndarray/numpy/_op.py
 ##########
 @@ -7477,6 +7477,94 @@ def resize(a, new_shape):
     return _npi.resize_fallback(a, new_shape=new_shape)
 
 
+@set_module('mxnet.ndarray.numpy')
+def fill_diagonal(a, val, wrap=False):
+    """
+    Fill the main diagonal of the given array of any dimensionality.
+    For an array `a` with ``a.ndim >= 2``, the diagonal is the list of
+    locations with indices ``a[i, ..., i]`` all identical. This function
+    modifies the input array in-place, it does not return a value.
+    Parameters
+    ----------
+    a : array, at least 2-D.
+      Array whose diagonal is to be filled, it gets modified in-place.
+    val : scalar
+      Value to be written on the diagonal, its type must be compatible with
+      that of the array a.
+    wrap : bool
+      For tall matrices in NumPy version up to 1.6.2, the
+      diagonal "wrapped" after N columns. You can have this behavior
+      with this option. This affects only tall matrices.
+
+    Examples
+    --------
+    >>> a = np.zeros((3, 3), int)
+    >>> np.fill_diagonal(a, 5)
+    >>> a
+    array([[5, 0, 0],
+           [0, 5, 0],
+           [0, 0, 5]])
+    The same function can operate on a 4-D array:
+    >>> a = np.zeros((3, 3, 3, 3), int)
+    >>> np.fill_diagonal(a, 4)
+    We only show a few blocks for clarity:
+    >>> a[0, 0]
+    array([[4, 0, 0],
+           [0, 0, 0],
+           [0, 0, 0]])
+    >>> a[1, 1]
+    array([[0, 0, 0],
+           [0, 4, 0],
+           [0, 0, 0]])
+    >>> a[2, 2]
+    array([[0, 0, 0],
+           [0, 0, 0],
+           [0, 0, 4]])
+    The wrap option affects only tall matrices:
+    >>> # tall matrices no wrap
+    >>> a = np.zeros((5, 3), int)
+    >>> np.fill_diagonal(a, 4)
+    >>> a
+    array([[4, 0, 0],
+           [0, 4, 0],
+           [0, 0, 4],
+           [0, 0, 0],
+           [0, 0, 0]])
+    >>> # tall matrices wrap
+    >>> a = np.zeros((5, 3), int)
+    >>> np.fill_diagonal(a, 4, wrap=True)
+    >>> a
+    array([[4, 0, 0],
+           [0, 4, 0],
+           [0, 0, 4],
+           [0, 0, 0],
+           [4, 0, 0]])
+    >>> # wide matrices
+    >>> a = np.zeros((3, 5), int)
+    >>> np.fill_diagonal(a, 4, wrap=True)
+    >>> a
+    array([[4, 0, 0, 0, 0],
+           [0, 4, 0, 0, 0],
+           [0, 0, 4, 0, 0]])
+    The anti-diagonal can be filled by reversing the order of elements
+    using either `numpy.flipud` or `numpy.fliplr`.
+    >>> a = np.zeros((3, 3), int);
+    >>> np.fill_diagonal(np.fliplr(a), [1,2,3])  # Horizontal flip
+    >>> a
+    array([[0, 0, 1],
+           [0, 2, 0],
+           [3, 0, 0]])
+    >>> np.fill_diagonal(np.flipud(a), [1,2,3])  # Vertical flip
+    >>> a
+    array([[0, 0, 3],
+           [0, 2, 0],
+           [1, 0, 0]])
+    Note that the order in which the diagonal is filled varies depending
+    on the flip function.
+    """
+    return _npi.fill_diagonal(a, val=val, wrap=wrap, out=a)
 
 Review comment:
   Use `_api_internal`

----------------------------------------------------------------
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 #18049: [numpy] add numpy op fill_diagonal

Posted by GitBox <gi...@apache.org>.
BenjaminCHEN2016 commented on issue #18049:
URL: https://github.com/apache/incubator-mxnet/pull/18049#issuecomment-617637323


   @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



[GitHub] [incubator-mxnet] BenjaminCHEN2016 commented on issue #18049: [numpy] add numpy op fill_diagonal

Posted by GitBox <gi...@apache.org>.
BenjaminCHEN2016 commented on issue #18049:
URL: https://github.com/apache/incubator-mxnet/pull/18049#issuecomment-618508666


   @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



[GitHub] [incubator-mxnet] BenjaminCHEN2016 commented on issue #18049: [numpy] add numpy op fill_diagonal

Posted by GitBox <gi...@apache.org>.
BenjaminCHEN2016 commented on issue #18049:
URL: https://github.com/apache/incubator-mxnet/pull/18049#issuecomment-618394639


   @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



[GitHub] [incubator-mxnet] mxnet-bot commented on issue #18049: [numpy] add numpy op fill_diagonal

Posted by GitBox <gi...@apache.org>.
mxnet-bot commented on issue #18049:
URL: https://github.com/apache/incubator-mxnet/pull/18049#issuecomment-618508753


   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



[GitHub] [incubator-mxnet] BenjaminCHEN2016 commented on issue #18049: [numpy] add numpy op fill_diagonal

Posted by GitBox <gi...@apache.org>.
BenjaminCHEN2016 commented on issue #18049:
URL: https://github.com/apache/incubator-mxnet/pull/18049#issuecomment-618402216


   @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



[GitHub] [incubator-mxnet] mxnet-bot commented on issue #18049: [numpy] add numpy op fill_diagonal

Posted by GitBox <gi...@apache.org>.
mxnet-bot commented on issue #18049:
URL: https://github.com/apache/incubator-mxnet/pull/18049#issuecomment-618394725


   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



[GitHub] [incubator-mxnet] mxnet-bot commented on issue #18049: [numpy] add numpy op fill_diagonal

Posted by GitBox <gi...@apache.org>.
mxnet-bot commented on issue #18049:
URL: https://github.com/apache/incubator-mxnet/pull/18049#issuecomment-618153454


   Jenkins CI successfully triggered : [unix-cpu, website, edge, centos-gpu, sanity, clang, windows-cpu, unix-gpu, centos-cpu, miscellaneous, windows-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



[GitHub] [incubator-mxnet] mxnet-bot commented on issue #18049: [numpy] add numpy op fill_diagonal

Posted by GitBox <gi...@apache.org>.
mxnet-bot commented on issue #18049:
URL: https://github.com/apache/incubator-mxnet/pull/18049#issuecomment-618408929


   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



[GitHub] [incubator-mxnet] BenjaminCHEN2016 commented on pull request #18049: [numpy] add numpy op fill_diagonal

Posted by GitBox <gi...@apache.org>.
BenjaminCHEN2016 commented on pull request #18049:
URL: https://github.com/apache/incubator-mxnet/pull/18049#issuecomment-618782876


   @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



[GitHub] [incubator-mxnet] mxnet-bot commented on issue #18049: [numpy] add numpy op fill_diagonal

Posted by GitBox <gi...@apache.org>.
mxnet-bot commented on issue #18049:
URL: https://github.com/apache/incubator-mxnet/pull/18049#issuecomment-618153605


   Jenkins CI successfully triggered : [windows-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



[GitHub] [incubator-mxnet] mxnet-bot commented on pull request #18049: [numpy] add numpy op fill_diagonal

Posted by GitBox <gi...@apache.org>.
mxnet-bot commented on pull request #18049:
URL: https://github.com/apache/incubator-mxnet/pull/18049#issuecomment-618782907


   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



[GitHub] [incubator-mxnet] haojin2 commented on a change in pull request #18049: [numpy] add numpy op fill_diagonal

Posted by GitBox <gi...@apache.org>.
haojin2 commented on a change in pull request #18049:
URL: https://github.com/apache/incubator-mxnet/pull/18049#discussion_r412388678



##########
File path: python/mxnet/numpy/multiarray.py
##########
@@ -9870,6 +9870,94 @@ def ones_like(a, dtype=None, order='C', ctx=None, out=None):
 # pylint: enable=redefined-outer-name
 
 
+@set_module('mxnet.numpy')
+def fill_diagonal(a, val, wrap=False):
+    """
+    Fill the main diagonal of the given array of any dimensionality.
+    For an array `a` with ``a.ndim >= 2``, the diagonal is the list of
+    locations with indices ``a[i, ..., i]`` all identical. This function
+    modifies the input array in-place, it does not return a value.
+    Parameters
+    ----------
+    a : array, at least 2-D.
+      Array whose diagonal is to be filled, it gets modified in-place.
+    val : scalar
+      Value to be written on the diagonal, its type must be compatible with
+      that of the array a.
+    wrap : bool
+      For tall matrices in NumPy version up to 1.6.2, the
+      diagonal "wrapped" after N columns. You can have this behavior
+      with this option. This affects only tall matrices.
+
+    Examples
+    --------
+    >>> a = np.zeros((3, 3), int)
+    >>> np.fill_diagonal(a, 5)
+    >>> a
+    array([[5, 0, 0],
+           [0, 5, 0],
+           [0, 0, 5]])
+    The same function can operate on a 4-D array:
+    >>> a = np.zeros((3, 3, 3, 3), int)
+    >>> np.fill_diagonal(a, 4)
+    We only show a few blocks for clarity:
+    >>> a[0, 0]
+    array([[4, 0, 0],
+           [0, 0, 0],
+           [0, 0, 0]])
+    >>> a[1, 1]
+    array([[0, 0, 0],
+           [0, 4, 0],
+           [0, 0, 0]])
+    >>> a[2, 2]
+    array([[0, 0, 0],
+           [0, 0, 0],
+           [0, 0, 4]])
+    The wrap option affects only tall matrices:
+    >>> # tall matrices no wrap
+    >>> a = np.zeros((5, 3), int)
+    >>> np.fill_diagonal(a, 4)
+    >>> a
+    array([[4, 0, 0],
+           [0, 4, 0],
+           [0, 0, 4],
+           [0, 0, 0],
+           [0, 0, 0]])
+    >>> # tall matrices wrap
+    >>> a = np.zeros((5, 3), int)
+    >>> np.fill_diagonal(a, 4, wrap=True)
+    >>> a
+    array([[4, 0, 0],
+           [0, 4, 0],
+           [0, 0, 4],
+           [0, 0, 0],
+           [4, 0, 0]])
+    >>> # wide matrices
+    >>> a = np.zeros((3, 5), int)
+    >>> np.fill_diagonal(a, 4, wrap=True)
+    >>> a
+    array([[4, 0, 0, 0, 0],
+           [0, 4, 0, 0, 0],
+           [0, 0, 4, 0, 0]])
+    The anti-diagonal can be filled by reversing the order of elements
+    using either `numpy.flipud` or `numpy.fliplr`.
+    >>> a = np.zeros((3, 3), int);
+    >>> np.fill_diagonal(np.fliplr(a), [1,2,3])  # Horizontal flip
+    >>> a
+    array([[0, 0, 1],
+           [0, 2, 0],
+           [3, 0, 0]])
+    >>> np.fill_diagonal(np.flipud(a), [1,2,3])  # Vertical flip
+    >>> a
+    array([[0, 0, 3],
+           [0, 2, 0],
+           [1, 0, 0]])
+    Note that the order in which the diagonal is filled varies depending
+    on the flip function.
+    """
+    return _mx_nd_np.fill_diagonal(a, val=val, wrap=wrap)

Review comment:
       Actually there shouldn't be a return value for this function...This operator is an in-place operator




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



[GitHub] [incubator-mxnet] BenjaminCHEN2016 commented on issue #18049: [numpy] add numpy op fill_diagonal

Posted by GitBox <gi...@apache.org>.
BenjaminCHEN2016 commented on issue #18049:
URL: https://github.com/apache/incubator-mxnet/pull/18049#issuecomment-618153399


   @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



[GitHub] [incubator-mxnet] BenjaminCHEN2016 removed a comment on issue #18049: [numpy] add numpy op fill_diagonal

Posted by GitBox <gi...@apache.org>.
BenjaminCHEN2016 removed a comment on issue #18049:
URL: https://github.com/apache/incubator-mxnet/pull/18049#issuecomment-618153583


   @mxnet-bot run ci [windows-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



[GitHub] [incubator-mxnet] BenjaminCHEN2016 removed a comment on issue #18049: [numpy] add numpy op fill_diagonal

Posted by GitBox <gi...@apache.org>.
BenjaminCHEN2016 removed a comment on issue #18049:
URL: https://github.com/apache/incubator-mxnet/pull/18049#issuecomment-617637323


   @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



[GitHub] [incubator-mxnet] BenjaminCHEN2016 commented on issue #18049: [numpy] add numpy op fill_diagonal

Posted by GitBox <gi...@apache.org>.
BenjaminCHEN2016 commented on issue #18049:
URL: https://github.com/apache/incubator-mxnet/pull/18049#issuecomment-618153583


   @mxnet-bot run ci [windows-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